AndroidSettingsWidget.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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.UISelectDropdown>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. this.ndkChooseButton = <Atomic.UIButton>this.getWidget("choose_ndk_auth");
  44. this.ndkPathEdit = <Atomic.UIEditField>this.getWidget("ndk_root");
  45. if (Atomic.platform == "Windows") {
  46. jdkRootText.text = "JDK Root: (Ex. C:\\Program Files\\Java\\jdk1.8.0_31)";
  47. antPathText.text = "Ant Path: (The folder that contains ant.bat)";
  48. }
  49. this.antPathEdit = <Atomic.UIEditField>this.getWidget("ant_path");
  50. this.refreshWidgets();
  51. this.subscribeToEvent(this, Atomic.UIWidgetEvent((ev) => this.handleWidgetEvent(ev)));
  52. }
  53. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  54. if (ev.type == Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK) {
  55. if (ev.target.id == "choose_sdk_path") {
  56. var fileUtils = new Editor.FileUtils();
  57. var currsdk = this.sdkPathEdit.text;
  58. var path = fileUtils.findPath("Please choose the root folder of your Android SDK" , currsdk );
  59. if ( path.length > 0 )
  60. this.sdkPathEdit.text = path;
  61. return true;
  62. } else if (ev.target.id == "choose_ant_path") {
  63. var fileUtils = new Editor.FileUtils();
  64. var currant = this.antPathEdit.text;
  65. var path = fileUtils.getAntPath(currant);
  66. if ( path.length > 0 )
  67. this.antPathEdit.text = path;
  68. return true;
  69. } else if (ev.target.id == "choose_jdk_root") {
  70. var fileUtils = new Editor.FileUtils();
  71. var currjdk = this.jdkRootEdit.text;
  72. var path = fileUtils.findPath("Please choose the root folder of your JDK" , currjdk );
  73. if ( path.length > 0 )
  74. this.jdkRootEdit.text = path;
  75. return true;
  76. } else if (ev.target.id == "refresh_sdk_targets") {
  77. this.refreshAndroidTargets();
  78. } else if (ev.target.id == "choose_and_auth") {
  79. var fileUtils = new Editor.FileUtils();
  80. var currauth = this.releaseNameEdit.text;
  81. var path = fileUtils.findPath( "Please choose the folder of your ant.properties", currauth );
  82. if ( path.length > 0 )
  83. this.releaseNameEdit.text = path;
  84. return true;
  85. } else if (ev.target.id == "choose_icon") {
  86. var fileUtils = new Editor.FileUtils();
  87. var curricon = this.iconNameEdit.text;
  88. var path = fileUtils.findPath("Please choose the folder with drawable folders" , curricon);
  89. if ( path.length > 0 ) {
  90. this.iconNameEdit.text = path;
  91. this.updateIconButton();
  92. }
  93. return true;
  94. } else if (ev.target.id == "choose_ndk_auth") {
  95. var fileUtils = new Editor.FileUtils();
  96. var currauth = this.ndkPathEdit.text;
  97. var path = fileUtils.findPath( "Please choose the folder of your NDK", currauth );
  98. if ( path.length > 0 )
  99. this.ndkPathEdit.text = path;
  100. return true;
  101. }
  102. }
  103. return false;
  104. }
  105. refreshAndroidTargets() {
  106. var platform = <ToolCore.PlatformAndroid>ToolCore.toolSystem.getPlatformByName("ANDROID");
  107. platform.refreshAndroidTargets();
  108. this.subscribeToEvent(platform, ToolCore.AndroidTargetsRefreshedEvent((ev) => {
  109. this.sdkTargetSource.clear();
  110. var targets: string[] = platform.androidTargets;
  111. for (var i in targets) {
  112. this.sdkTargetSource.addItem(new Atomic.UISelectItem(targets[i]));
  113. }
  114. this.sdkTargetSelect.source = this.sdkTargetSource;
  115. // force a refresh
  116. this.sdkTargetSelect.value = -1;
  117. this.sdkTargetSelect.value = 0;
  118. }));
  119. }
  120. updateIconButton() {
  121. var fileSystem = Atomic.getFileSystem();
  122. if ( this.iconNameEdit.text.length > 0 ) {
  123. let myicon = this.iconNameEdit.text + "/drawable-ldpi/icon.png";
  124. if ( fileSystem.fileExists(myicon) ) {
  125. this.iconImage.setImage( myicon );
  126. return;
  127. }
  128. }
  129. let defaulticon = fileSystem.getProgramDir() + "Resources/ToolData/Deployment/Android/res/drawable-ldpi/icon.png";
  130. this.iconImage.setImage( defaulticon );
  131. }
  132. refreshWidgets() {
  133. var toolPrefs = ToolCore.toolEnvironment.toolPrefs;
  134. this.sdkPathEdit.text = toolPrefs.androidSDKPath;
  135. this.antPathEdit.text = toolPrefs.antPath;
  136. this.jdkRootEdit.text = toolPrefs.jDKRootPath;
  137. this.releaseNameEdit.text = toolPrefs.releasePath;
  138. this.releaseCheck.value = toolPrefs.releaseCheck;
  139. this.ndkPathEdit.text = toolPrefs.ndkPath;
  140. this.appNameEdit.text = this.settings.appName;
  141. this.packageNameEdit.text = this.settings.packageName;
  142. this.companyNameEdit.text = this.settings.companyName;
  143. this.iconNameEdit.text = this.settings.iconPath;
  144. this.sdkTargetSelect.text = this.settings.sDKVersion;
  145. this.updateIconButton();
  146. }
  147. storeValues() {
  148. this.settings.appName = this.appNameEdit.text;
  149. this.settings.packageName = this.packageNameEdit.text;
  150. this.settings.companyName = this.companyNameEdit.text;
  151. this.settings.sDKVersion = this.sdkTargetSelect.text;
  152. this.settings.iconPath = this.iconNameEdit.text;
  153. ToolCore.toolEnvironment.toolPrefs.antPath = this.antPathEdit.text;
  154. ToolCore.toolEnvironment.toolPrefs.androidSDKPath = this.sdkPathEdit.text;
  155. ToolCore.toolEnvironment.toolPrefs.jDKRootPath = this.jdkRootEdit.text;
  156. ToolCore.toolEnvironment.toolPrefs.releasePath = this.releaseNameEdit.text;
  157. ToolCore.toolEnvironment.toolPrefs.releaseCheck = this.releaseCheck.value;
  158. ToolCore.toolEnvironment.toolPrefs.ndkPath = this.ndkPathEdit.text;
  159. ToolCore.toolEnvironment.saveToolPrefs();
  160. }
  161. settings: ToolCore.AndroidBuildSettings;
  162. sdkTargetSource: Atomic.UISelectItemSource = new Atomic.UISelectItemSource();
  163. sdkTargetSelect: Atomic.UISelectDropdown;
  164. sdkPathEdit: Atomic.UIEditField;
  165. jdkRootChooseButton: Atomic.UIButton;
  166. jdkRootEdit: Atomic.UIEditField;
  167. antPathEdit: Atomic.UIEditField;
  168. appNameEdit: Atomic.UIEditField;
  169. packageNameEdit: Atomic.UIEditField;
  170. companyNameEdit: Atomic.UIEditField;
  171. releaseNameEdit : Atomic.UIEditField;
  172. releaseChooseButton : Atomic.UIButton;
  173. releaseCheck : Atomic.UISelectDropdown;
  174. iconNameEdit : Atomic.UIEditField;
  175. iconChooseButton : Atomic.UIButton;
  176. iconImage : Atomic.UIImageWidget;
  177. ndkPathEdit : Atomic.UIEditField;
  178. ndkChooseButton : Atomic.UIButton;
  179. }
  180. export = AndroidSettingsWidget;