AndroidSettingsWidget.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import BuildSettingsWindow = require("../BuildSettingsWindow");
  23. class AndroidSettingsWidget extends Atomic.UIWidget implements BuildSettingsWindow.BuildSettingsWidget {
  24. constructor() {
  25. super();
  26. this.load("AtomicEditor/editor/ui/buildsettings_android.tb.txt");
  27. this.settings = ToolCore.toolSystem.project.buildSettings.androidBuildSettings;
  28. this.sdkPathEdit = <Atomic.UIEditField>this.getWidget("sdk_path");
  29. this.sdkTargetSelect = <Atomic.UISelectDropdown>this.getWidget("sdk_target_select");
  30. this.appNameEdit = <Atomic.UIEditField>this.getWidget("app_name");
  31. this.packageNameEdit = <Atomic.UIEditField>this.getWidget("app_package");
  32. this.companyNameEdit = <Atomic.UIEditField>this.getWidget("company_name");
  33. this.jdkRootChooseButton = <Atomic.UIButton>this.getWidget("choose_jdk_root");
  34. this.jdkRootEdit = <Atomic.UIEditField>this.getWidget("jdk_root");
  35. var jdkRootText = <Atomic.UITextField>this.getWidget("jdk_root_text");
  36. var antPathText = <Atomic.UITextField>this.getWidget("ant_path_text");
  37. this.releaseChooseButton = <Atomic.UIButton>this.getWidget("choose_and_auth");
  38. this.releaseNameEdit = <Atomic.UIEditField>this.getWidget("auth_root");
  39. this.releaseCheck = <Atomic.UICheckBox>this.getWidget("and_auth_check");
  40. this.iconNameEdit = <Atomic.UIEditField>this.getWidget("icon_root");
  41. this.iconChooseButton = <Atomic.UIButton>this.getWidget("choose_icon");
  42. this.iconImage = <Atomic.UIImageWidget>this.getWidget("and_icon");
  43. if (Atomic.platform == "Windows") {
  44. jdkRootText.text = "JDK Root: (Ex. C:\\Program Files\\Java\\jdk1.8.0_31)";
  45. antPathText.text = "Ant Path: (The folder that contains ant.bat)";
  46. }
  47. this.antPathEdit = <Atomic.UIEditField>this.getWidget("ant_path");
  48. this.refreshWidgets();
  49. this.subscribeToEvent(this, "WidgetEvent", (ev) => this.handleWidgetEvent(ev));
  50. }
  51. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  52. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  53. if (ev.target.id == "choose_sdk_path") {
  54. var fileUtils = new Editor.FileUtils();
  55. var currsdk = this.sdkPathEdit.text;
  56. var path = fileUtils.findPath("Please choose the root folder of your Android SDK" , currsdk );
  57. if ( path.length > 0 )
  58. this.sdkPathEdit.text = path;
  59. return true;
  60. } else if (ev.target.id == "choose_ant_path") {
  61. var fileUtils = new Editor.FileUtils();
  62. var currant = this.antPathEdit.text;
  63. var path = fileUtils.getAntPath(currant);
  64. if ( path.length > 0 )
  65. this.antPathEdit.text = path;
  66. return true;
  67. } else if (ev.target.id == "choose_jdk_root") {
  68. var fileUtils = new Editor.FileUtils();
  69. var currjdk = this.jdkRootEdit.text;
  70. var path = fileUtils.findPath("Please choose the root folder of your JDK" , currjdk );
  71. if ( path.length > 0 )
  72. this.jdkRootEdit.text = path;
  73. return true;
  74. } else if (ev.target.id == "refresh_sdk_targets") {
  75. this.refreshAndroidTargets();
  76. } else if (ev.target.id == "choose_and_auth") {
  77. var fileUtils = new Editor.FileUtils();
  78. var currauth = this.releaseNameEdit.text;
  79. var path = fileUtils.findPath( "Please choose the folder of your ant.properties", currauth );
  80. if ( path.length > 0 )
  81. this.releaseNameEdit.text = path;
  82. return true;
  83. } else if (ev.target.id == "choose_icon") {
  84. var fileUtils = new Editor.FileUtils();
  85. var curricon = this.iconNameEdit.text;
  86. var path = fileUtils.findPath("Please choose the folder with drawable folders" , curricon);
  87. if ( path.length > 0 ) {
  88. this.iconNameEdit.text = path;
  89. this.updateIconButton();
  90. }
  91. return true;
  92. }
  93. }
  94. return false;
  95. }
  96. refreshAndroidTargets() {
  97. var platform = <ToolCore.PlatformAndroid>ToolCore.toolSystem.getPlatformByName("ANDROID");
  98. platform.refreshAndroidTargets();
  99. this.subscribeToEvent(platform, "AndroidTargetsRefreshed", (ev) => {
  100. this.sdkTargetSource.clear();
  101. var targets: string[] = platform.androidTargets;
  102. for (var i in targets) {
  103. this.sdkTargetSource.addItem(new Atomic.UISelectItem(targets[i]));
  104. }
  105. this.sdkTargetSelect.source = this.sdkTargetSource;
  106. // force a refresh
  107. this.sdkTargetSelect.value = -1;
  108. this.sdkTargetSelect.value = 0;
  109. });
  110. }
  111. updateIconButton() {
  112. var fileSystem = Atomic.getFileSystem();
  113. if ( this.iconNameEdit.text.length > 0 ) {
  114. let myicon = this.iconNameEdit.text + "/drawable-ldpi/icon.png";
  115. if ( fileSystem.fileExists(myicon) ) {
  116. this.iconImage.setImage( myicon );
  117. return;
  118. }
  119. }
  120. let defaulticon = fileSystem.getProgramDir() + "Resources/ToolData/Deployment/Android/res/drawable-ldpi/icon.png";
  121. this.iconImage.setImage( defaulticon );
  122. }
  123. refreshWidgets() {
  124. var toolPrefs = ToolCore.toolEnvironment.toolPrefs;
  125. this.sdkPathEdit.text = toolPrefs.androidSDKPath;
  126. this.antPathEdit.text = toolPrefs.antPath;
  127. this.jdkRootEdit.text = toolPrefs.jDKRootPath;
  128. this.releaseNameEdit.text = toolPrefs.releasePath;
  129. this.releaseCheck.value = toolPrefs.releaseCheck;
  130. this.appNameEdit.text = this.settings.appName;
  131. this.packageNameEdit.text = this.settings.packageName;
  132. this.companyNameEdit.text = this.settings.companyName;
  133. this.iconNameEdit.text = this.settings.iconPath;
  134. this.sdkTargetSelect.text = this.settings.sDKVersion;
  135. this.updateIconButton();
  136. }
  137. storeValues() {
  138. this.settings.appName = this.appNameEdit.text;
  139. this.settings.packageName = this.packageNameEdit.text;
  140. this.settings.companyName = this.companyNameEdit.text;
  141. this.settings.sDKVersion = this.sdkTargetSelect.text;
  142. this.settings.iconPath = this.iconNameEdit.text;
  143. ToolCore.toolEnvironment.toolPrefs.antPath = this.antPathEdit.text;
  144. ToolCore.toolEnvironment.toolPrefs.androidSDKPath = this.sdkPathEdit.text;
  145. ToolCore.toolEnvironment.toolPrefs.jDKRootPath = this.jdkRootEdit.text;
  146. ToolCore.toolEnvironment.toolPrefs.releasePath = this.releaseNameEdit.text;
  147. ToolCore.toolEnvironment.toolPrefs.releaseCheck = this.releaseCheck.value;
  148. ToolCore.toolEnvironment.saveToolPrefs();
  149. }
  150. settings: ToolCore.AndroidBuildSettings;
  151. sdkTargetSource: Atomic.UISelectItemSource = new Atomic.UISelectItemSource();
  152. sdkTargetSelect: Atomic.UISelectDropdown;
  153. sdkPathEdit: Atomic.UIEditField;
  154. jdkRootChooseButton: Atomic.UIButton;
  155. jdkRootEdit: Atomic.UIEditField;
  156. antPathEdit: Atomic.UIEditField;
  157. appNameEdit: Atomic.UIEditField;
  158. packageNameEdit: Atomic.UIEditField;
  159. companyNameEdit: Atomic.UIEditField;
  160. releaseNameEdit : Atomic.UIEditField;
  161. releaseChooseButton : Atomic.UIButton;
  162. releaseCheck : Atomic.UICheckBox;
  163. iconNameEdit : Atomic.UIEditField;
  164. iconChooseButton : Atomic.UIButton;
  165. iconImage : Atomic.UIImageWidget;
  166. }
  167. export = AndroidSettingsWidget;