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.productNameEdit = <Atomic.UIEditField>this.getWidget("product_name");
  33. this.companyNameEdit = <Atomic.UIEditField>this.getWidget("company_name");
  34. this.jdkRootChooseButton = <Atomic.UIButton>this.getWidget("choose_jdk_root");
  35. this.jdkRootEdit = <Atomic.UIEditField>this.getWidget("jdk_root");
  36. var jdkRootText = <Atomic.UITextField>this.getWidget("jdk_root_text");
  37. var antPathText = <Atomic.UITextField>this.getWidget("ant_path_text");
  38. this.releaseChooseButton = <Atomic.UIButton>this.getWidget("choose_and_auth");
  39. this.releaseNameEdit = <Atomic.UIEditField>this.getWidget("auth_root");
  40. this.releaseCheck = <Atomic.UICheckBox>this.getWidget("and_auth_check");
  41. this.iconNameEdit = <Atomic.UIEditField>this.getWidget("icon_root");
  42. this.iconChooseButton = <Atomic.UIButton>this.getWidget("choose_icon");
  43. this.iconImage = <Atomic.UIImageWidget>this.getWidget("and_icon");
  44. if (Atomic.platform == "Windows") {
  45. jdkRootText.text = "JDK Root: (Ex. C:\\Program Files\\Java\\jdk1.8.0_31)";
  46. antPathText.text = "Ant Path: (The folder that contains ant.bat)";
  47. }
  48. this.antPathEdit = <Atomic.UIEditField>this.getWidget("ant_path");
  49. this.refreshWidgets();
  50. this.subscribeToEvent(this, "WidgetEvent", (ev) => this.handleWidgetEvent(ev));
  51. }
  52. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  53. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  54. if (ev.target.id == "choose_sdk_path") {
  55. var fileUtils = new Editor.FileUtils();
  56. var path = fileUtils.findPath("Please choose the root folder of your Android SDK","");
  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 path = fileUtils.getAntPath("");
  63. if ( path.length > 0 )
  64. this.antPathEdit.text = path;
  65. return true;
  66. } else if (ev.target.id == "choose_jdk_root") {
  67. var fileUtils = new Editor.FileUtils();
  68. var path = fileUtils.findPath("Please choose the root folder of your JDK","");
  69. if ( path.length > 0 )
  70. this.jdkRootEdit.text = path;
  71. return true;
  72. } else if (ev.target.id == "refresh_sdk_targets") {
  73. this.refreshAndroidTargets();
  74. } else if (ev.target.id == "choose_and_auth") {
  75. var fileUtils = new Editor.FileUtils();
  76. var path = fileUtils.findPath( "Please choose the folder of your ant.properties", "");
  77. if ( path.length > 0 )
  78. this.releaseNameEdit.text = path;
  79. return true;
  80. } else if (ev.target.id == "choose_icon") {
  81. var fileUtils = new Editor.FileUtils();
  82. var path = fileUtils.findPath("Please choose the folder with drawable folders","");
  83. if ( path.length > 0 )
  84. {
  85. this.iconNameEdit.text = path;
  86. this.updateIconButton();
  87. }
  88. return true;
  89. }
  90. }
  91. return false;
  92. }
  93. refreshAndroidTargets() {
  94. var platform = <ToolCore.PlatformAndroid>ToolCore.toolSystem.getPlatformByName("ANDROID");
  95. platform.refreshAndroidTargets();
  96. this.subscribeToEvent(platform, "AndroidTargetsRefreshed", (ev) => {
  97. this.sdkTargetSource.clear();
  98. var targets: string[] = platform.androidTargets;
  99. for (var i in targets) {
  100. this.sdkTargetSource.addItem(new Atomic.UISelectItem(targets[i]));
  101. }
  102. this.sdkTargetSelect.source = this.sdkTargetSource;
  103. // force a refresh
  104. this.sdkTargetSelect.value = -1;
  105. this.sdkTargetSelect.value = 0;
  106. });
  107. }
  108. updateIconButton() {
  109. var fileSystem = Atomic.getFileSystem();
  110. if ( this.iconNameEdit.text.length > 0 ) {
  111. let myicon = this.iconNameEdit.text + "/drawable-ldpi/icon.png";
  112. if ( fileSystem.fileExists(myicon) ) {
  113. this.iconImage.setImage( myicon );
  114. return;
  115. }
  116. }
  117. let defaulticon = fileSystem.getProgramDir() + "Resources/ToolData/Deployment/Android/res/drawable-ldpi/icon.png";
  118. this.iconImage.setImage( defaulticon );
  119. }
  120. refreshWidgets() {
  121. var toolPrefs = ToolCore.toolEnvironment.toolPrefs;
  122. this.sdkPathEdit.text = toolPrefs.androidSDKPath;
  123. this.antPathEdit.text = toolPrefs.antPath;
  124. this.jdkRootEdit.text = toolPrefs.jDKRootPath;
  125. this.releaseNameEdit.text = toolPrefs.releasePath;
  126. this.releaseCheck.value = toolPrefs.releaseCheck;
  127. this.appNameEdit.text = this.settings.appName;
  128. this.packageNameEdit.text = this.settings.packageName;
  129. this.productNameEdit.text = this.settings.productName;
  130. this.companyNameEdit.text = this.settings.companyName;
  131. this.iconNameEdit.text = this.settings.iconPath;
  132. this.sdkTargetSelect.text = this.settings.sDKVersion;
  133. this.updateIconButton();
  134. }
  135. storeValues() {
  136. this.settings.appName = this.appNameEdit.text;
  137. this.settings.packageName = this.packageNameEdit.text;
  138. this.settings.productName = this.productNameEdit.text;
  139. this.settings.companyName = this.companyNameEdit.text;
  140. this.settings.sDKVersion = this.sdkTargetSelect.text;
  141. this.settings.iconPath = this.iconNameEdit.text;
  142. ToolCore.toolEnvironment.toolPrefs.antPath = this.antPathEdit.text;
  143. ToolCore.toolEnvironment.toolPrefs.androidSDKPath = this.sdkPathEdit.text;
  144. ToolCore.toolEnvironment.toolPrefs.jDKRootPath = this.jdkRootEdit.text;
  145. ToolCore.toolEnvironment.toolPrefs.releasePath = this.releaseNameEdit.text;
  146. ToolCore.toolEnvironment.toolPrefs.releaseCheck = this.releaseCheck.value;
  147. ToolCore.toolEnvironment.saveToolPrefs();
  148. }
  149. settings: ToolCore.AndroidBuildSettings;
  150. sdkTargetSource: Atomic.UISelectItemSource = new Atomic.UISelectItemSource();
  151. sdkTargetSelect: Atomic.UISelectDropdown;
  152. sdkPathEdit: Atomic.UIEditField;
  153. jdkRootChooseButton: Atomic.UIButton;
  154. jdkRootEdit: Atomic.UIEditField;
  155. antPathEdit: Atomic.UIEditField;
  156. appNameEdit: Atomic.UIEditField;
  157. packageNameEdit: Atomic.UIEditField;
  158. productNameEdit: 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;