// // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // import BuildSettingsWindow = require("../BuildSettingsWindow"); class AndroidSettingsWidget extends Atomic.UIWidget implements BuildSettingsWindow.BuildSettingsWidget { constructor() { super(); this.load("AtomicEditor/editor/ui/buildsettings_android.tb.txt"); this.settings = ToolCore.toolSystem.project.buildSettings.androidBuildSettings; this.sdkPathEdit = this.getWidget("sdk_path"); this.sdkTargetSelect = this.getWidget("sdk_target_select"); this.appNameEdit = this.getWidget("app_name"); this.packageNameEdit = this.getWidget("app_package"); this.companyNameEdit = this.getWidget("company_name"); this.jdkRootChooseButton = this.getWidget("choose_jdk_root"); this.jdkRootEdit = this.getWidget("jdk_root"); var jdkRootText = this.getWidget("jdk_root_text"); var antPathText = this.getWidget("ant_path_text"); this.releaseChooseButton = this.getWidget("choose_and_auth"); this.releaseNameEdit = this.getWidget("auth_root"); this.releaseCheck = this.getWidget("and_auth_check"); this.iconNameEdit = this.getWidget("icon_root"); this.iconChooseButton = this.getWidget("choose_icon"); this.iconImage = this.getWidget("and_icon"); this.ndkChooseButton = this.getWidget("choose_ndk_auth"); this.ndkPathEdit = this.getWidget("ndk_root"); if (Atomic.platform == "Windows") { jdkRootText.text = "JDK Root: (Ex. C:\\Program Files\\Java\\jdk1.8.0_31)"; antPathText.text = "Ant Path: (The folder that contains ant.bat)"; } this.antPathEdit = this.getWidget("ant_path"); this.refreshWidgets(); this.subscribeToEvent(this, Atomic.UIWidgetEvent((ev) => this.handleWidgetEvent(ev))); } handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean { if (ev.type == Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK) { if (ev.target.id == "choose_sdk_path") { var fileUtils = new Editor.FileUtils(); var currsdk = this.sdkPathEdit.text; var path = fileUtils.findPath("Please choose the root folder of your Android SDK" , currsdk ); if ( path.length > 0 ) this.sdkPathEdit.text = path; return true; } else if (ev.target.id == "choose_ant_path") { var fileUtils = new Editor.FileUtils(); var currant = this.antPathEdit.text; var path = fileUtils.getAntPath(currant); if ( path.length > 0 ) this.antPathEdit.text = path; return true; } else if (ev.target.id == "choose_jdk_root") { var fileUtils = new Editor.FileUtils(); var currjdk = this.jdkRootEdit.text; var path = fileUtils.findPath("Please choose the root folder of your JDK" , currjdk ); if ( path.length > 0 ) this.jdkRootEdit.text = path; return true; } else if (ev.target.id == "refresh_sdk_targets") { this.refreshAndroidTargets(); } else if (ev.target.id == "choose_and_auth") { var fileUtils = new Editor.FileUtils(); var currauth = this.releaseNameEdit.text; var path = fileUtils.findPath( "Please choose the folder of your ant.properties", currauth ); if ( path.length > 0 ) this.releaseNameEdit.text = path; return true; } else if (ev.target.id == "choose_icon") { var fileUtils = new Editor.FileUtils(); var curricon = this.iconNameEdit.text; var path = fileUtils.findPath("Please choose the folder with drawable folders" , curricon); if ( path.length > 0 ) { this.iconNameEdit.text = path; this.updateIconButton(); } return true; } else if (ev.target.id == "choose_ndk_auth") { var fileUtils = new Editor.FileUtils(); var currauth = this.ndkPathEdit.text; var path = fileUtils.findPath( "Please choose the folder of your NDK", currauth ); if ( path.length > 0 ) this.ndkPathEdit.text = path; return true; } } return false; } refreshAndroidTargets() { var platform = ToolCore.toolSystem.getPlatformByName("ANDROID"); platform.refreshAndroidTargets(); this.subscribeToEvent(platform, ToolCore.AndroidTargetsRefreshedEvent((ev) => { this.sdkTargetSource.clear(); var targets: string[] = platform.androidTargets; for (var i in targets) { this.sdkTargetSource.addItem(new Atomic.UISelectItem(targets[i])); } this.sdkTargetSelect.source = this.sdkTargetSource; // force a refresh this.sdkTargetSelect.value = -1; this.sdkTargetSelect.value = 0; })); } updateIconButton() { var fileSystem = Atomic.getFileSystem(); if ( this.iconNameEdit.text.length > 0 ) { let myicon = this.iconNameEdit.text + "/drawable-ldpi/icon.png"; if ( fileSystem.fileExists(myicon) ) { this.iconImage.setImage( myicon ); return; } } let defaulticon = fileSystem.getProgramDir() + "Resources/ToolData/Deployment/Android/res/drawable-ldpi/icon.png"; this.iconImage.setImage( defaulticon ); } refreshWidgets() { var toolPrefs = ToolCore.toolEnvironment.toolPrefs; this.sdkPathEdit.text = toolPrefs.androidSDKPath; this.antPathEdit.text = toolPrefs.antPath; this.jdkRootEdit.text = toolPrefs.jDKRootPath; this.releaseNameEdit.text = toolPrefs.releasePath; this.releaseCheck.value = toolPrefs.releaseCheck; this.ndkPathEdit.text = toolPrefs.ndkPath; this.appNameEdit.text = this.settings.appName; this.packageNameEdit.text = this.settings.packageName; this.companyNameEdit.text = this.settings.companyName; this.iconNameEdit.text = this.settings.iconPath; this.sdkTargetSelect.text = this.settings.sDKVersion; this.updateIconButton(); } storeValues() { this.settings.appName = this.appNameEdit.text; this.settings.packageName = this.packageNameEdit.text; this.settings.companyName = this.companyNameEdit.text; this.settings.sDKVersion = this.sdkTargetSelect.text; this.settings.iconPath = this.iconNameEdit.text; ToolCore.toolEnvironment.toolPrefs.antPath = this.antPathEdit.text; ToolCore.toolEnvironment.toolPrefs.androidSDKPath = this.sdkPathEdit.text; ToolCore.toolEnvironment.toolPrefs.jDKRootPath = this.jdkRootEdit.text; ToolCore.toolEnvironment.toolPrefs.releasePath = this.releaseNameEdit.text; ToolCore.toolEnvironment.toolPrefs.releaseCheck = this.releaseCheck.value; ToolCore.toolEnvironment.toolPrefs.ndkPath = this.ndkPathEdit.text; ToolCore.toolEnvironment.saveToolPrefs(); } settings: ToolCore.AndroidBuildSettings; sdkTargetSource: Atomic.UISelectItemSource = new Atomic.UISelectItemSource(); sdkTargetSelect: Atomic.UISelectDropdown; sdkPathEdit: Atomic.UIEditField; jdkRootChooseButton: Atomic.UIButton; jdkRootEdit: Atomic.UIEditField; antPathEdit: Atomic.UIEditField; appNameEdit: Atomic.UIEditField; packageNameEdit: Atomic.UIEditField; companyNameEdit: Atomic.UIEditField; releaseNameEdit : Atomic.UIEditField; releaseChooseButton : Atomic.UIButton; releaseCheck : Atomic.UISelectDropdown; iconNameEdit : Atomic.UIEditField; iconChooseButton : Atomic.UIButton; iconImage : Atomic.UIImageWidget; ndkPathEdit : Atomic.UIEditField; ndkChooseButton : Atomic.UIButton; } export = AndroidSettingsWidget;