AndroidSettingsWidget.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. this.iconNameEdit.text = path;
  85. this.updateIconButton();
  86. }
  87. return true;
  88. }
  89. }
  90. return false;
  91. }
  92. refreshAndroidTargets() {
  93. var platform = <ToolCore.PlatformAndroid>ToolCore.toolSystem.getPlatformByName("ANDROID");
  94. platform.refreshAndroidTargets();
  95. this.subscribeToEvent(platform, "AndroidTargetsRefreshed", (ev) => {
  96. this.sdkTargetSource.clear();
  97. var targets: string[] = platform.androidTargets;
  98. for (var i in targets) {
  99. this.sdkTargetSource.addItem(new Atomic.UISelectItem(targets[i]));
  100. }
  101. this.sdkTargetSelect.source = this.sdkTargetSource;
  102. // force a refresh
  103. this.sdkTargetSelect.value = -1;
  104. this.sdkTargetSelect.value = 0;
  105. });
  106. }
  107. updateIconButton() {
  108. var fileSystem = Atomic.getFileSystem();
  109. if ( this.iconNameEdit.text.length > 0 ) {
  110. let myicon = this.iconNameEdit.text + "/drawable-ldpi/icon.png";
  111. if ( fileSystem.fileExists(myicon) ) {
  112. this.iconImage.setImage( myicon );
  113. return;
  114. }
  115. }
  116. let defaulticon = fileSystem.getProgramDir() + "Resources/ToolData/Deployment/Android/res/drawable-ldpi/icon.png";
  117. this.iconImage.setImage( defaulticon );
  118. }
  119. refreshWidgets() {
  120. var toolPrefs = ToolCore.toolEnvironment.toolPrefs;
  121. this.sdkPathEdit.text = toolPrefs.androidSDKPath;
  122. this.antPathEdit.text = toolPrefs.antPath;
  123. this.jdkRootEdit.text = toolPrefs.jDKRootPath;
  124. this.releaseNameEdit.text = toolPrefs.releasePath;
  125. this.releaseCheck.value = toolPrefs.releaseCheck;
  126. this.appNameEdit.text = this.settings.appName;
  127. this.packageNameEdit.text = this.settings.packageName;
  128. this.productNameEdit.text = this.settings.productName;
  129. this.companyNameEdit.text = this.settings.companyName;
  130. this.iconNameEdit.text = this.settings.iconPath;
  131. this.sdkTargetSelect.text = this.settings.sDKVersion;
  132. this.updateIconButton();
  133. }
  134. storeValues() {
  135. this.settings.appName = this.appNameEdit.text;
  136. this.settings.packageName = this.packageNameEdit.text;
  137. this.settings.productName = this.productNameEdit.text;
  138. this.settings.companyName = this.companyNameEdit.text;
  139. this.settings.sDKVersion = this.sdkTargetSelect.text;
  140. this.settings.iconPath = this.iconNameEdit.text;
  141. ToolCore.toolEnvironment.toolPrefs.antPath = this.antPathEdit.text;
  142. ToolCore.toolEnvironment.toolPrefs.androidSDKPath = this.sdkPathEdit.text;
  143. ToolCore.toolEnvironment.toolPrefs.jDKRootPath = this.jdkRootEdit.text;
  144. ToolCore.toolEnvironment.toolPrefs.releasePath = this.releaseNameEdit.text;
  145. ToolCore.toolEnvironment.toolPrefs.releaseCheck = this.releaseCheck.value;
  146. ToolCore.toolEnvironment.saveToolPrefs();
  147. }
  148. settings: ToolCore.AndroidBuildSettings;
  149. sdkTargetSource: Atomic.UISelectItemSource = new Atomic.UISelectItemSource();
  150. sdkTargetSelect: Atomic.UISelectDropdown;
  151. sdkPathEdit: Atomic.UIEditField;
  152. jdkRootChooseButton: Atomic.UIButton;
  153. jdkRootEdit: Atomic.UIEditField;
  154. antPathEdit: Atomic.UIEditField;
  155. appNameEdit: Atomic.UIEditField;
  156. packageNameEdit: Atomic.UIEditField;
  157. productNameEdit: Atomic.UIEditField;
  158. companyNameEdit: Atomic.UIEditField;
  159. releaseNameEdit : Atomic.UIEditField;
  160. releaseChooseButton : Atomic.UIButton;
  161. releaseCheck : Atomic.UICheckBox;
  162. iconNameEdit : Atomic.UIEditField;
  163. iconChooseButton : Atomic.UIButton;
  164. iconImage : Atomic.UIImageWidget;
  165. }
  166. export = AndroidSettingsWidget;