AndroidSettingsWidget.ts 8.9 KB

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