mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactoring, tune Android run configuration in "new module" wizard
This commit is contained in:
@@ -168,13 +168,14 @@ android.dest.directory.title=De&stination directory
|
||||
android.generate.r.java.by.res.dir=Use res&ource directory specified at "Structure" section
|
||||
android.use.custom.r.java.source.dir=Use custo&m resource directory
|
||||
android.regenerate.idl.when.changed.checkbox=Regenerate &Java files when AIDL files are changed
|
||||
android.wizard.application.project.button=A&pplication
|
||||
android.wizard.application.project.button=&Application
|
||||
android.wizard.lib.project.button=&Library
|
||||
android.wizard.test.project.button=&Test
|
||||
android.wizard.tested.project.label=Tested &module:
|
||||
android.wizard.specify.tested.module.error=Please specify tested module
|
||||
android.wizard.tested.module.without.facet.error=Tested module must contain Android facet
|
||||
android.wizard.cannot.find.module.parent.dir.error=Cannot find module parent directory: {0}
|
||||
android.wizard.invalid.sdk.error=Android SDK is invalid
|
||||
android.facet.editor.is.library.checkbox=&Is Library project
|
||||
android.run.sdk.manager.action.text=Android SDK and AVD Manager
|
||||
android.choose.sdk.label=Please choose Android SDK location
|
||||
@@ -284,4 +285,14 @@ android.renderscript.file.type.description=Android renderscript files
|
||||
android.renderscript.compiler.description=Android Renderscript Compiler
|
||||
android.extended.device.chooser.running.device.radio=&Choose a running device
|
||||
android.extended.device.chooser.launch.emulator.radio=&Launch emulator
|
||||
android.extended.device.chooser.avd.label=&Android virtual device:
|
||||
android.extended.device.chooser.avd.label=&Android virtual device:
|
||||
deployment.target.settings.show.dialog=Show &chooser dialog
|
||||
deployment.target.settings.usb.device=&USB device
|
||||
deployment.target.settings.emulator=Emulato&r
|
||||
deployment.target.settings.prefer.avd.label=&Prefer Android Virtual Device:
|
||||
deployment.target.settings.prefer.avd.label.wizard=Prefer &Android Virtual Device:
|
||||
deployment.target.settings.title=Target Device
|
||||
deployment.target.settings.wizard.configure.later=&Do not create run configuration
|
||||
deployment.target.settings.wizard.show.dialog=&Show device chooser dialog
|
||||
deployment.target.settings.wizard.usb.device=&USB device
|
||||
deployment.target.settings.wizard.emulator=Emulat&or
|
||||
@@ -78,12 +78,12 @@ public class RunAndroidSdkManagerAction extends AnAction {
|
||||
}
|
||||
sdkPath = sdks[index];
|
||||
}
|
||||
runTool(project, sdkPath);
|
||||
runTool(sdkPath);
|
||||
}
|
||||
|
||||
public static void runTool(@NotNull Project project, @NotNull String sdkPath) {
|
||||
public static void runTool(@NotNull String sdkPath) {
|
||||
GeneralCommandLine commandLine = new GeneralCommandLine();
|
||||
commandLine.setExePath(sdkPath + File.separator + AndroidUtils.toolPath(SdkConstants.androidCmdName()));
|
||||
AndroidUtils.runExternalToolInSeparateThread(project, commandLine);
|
||||
AndroidUtils.runExternalToolInSeparateThread(null, commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class AndroidFrameworkDetector extends FacetBasedFrameworkDetector<Androi
|
||||
Manifest manifest = facet.getManifest();
|
||||
if (manifest != null) {
|
||||
if (AndroidUtils.getDefaultActivityName(manifest) != null) {
|
||||
AndroidUtils.addRunConfiguration(project, facet, null, true);
|
||||
AndroidUtils.addRunConfiguration(project, facet, null, true, null, null);
|
||||
}
|
||||
}
|
||||
ApplicationManager.getApplication().saveAll();
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -47,7 +46,6 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.ExternalChangeAction;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.android.AndroidFileTemplateProvider;
|
||||
import org.jetbrains.android.dom.manifest.Manifest;
|
||||
import org.jetbrains.android.dom.resources.ResourceElement;
|
||||
@@ -56,6 +54,7 @@ import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.android.facet.AndroidRootUtil;
|
||||
import org.jetbrains.android.importDependencies.ImportDependenciesUtil;
|
||||
import org.jetbrains.android.resourceManagers.LocalResourceManager;
|
||||
import org.jetbrains.android.run.TargetSelectionMode;
|
||||
import org.jetbrains.android.run.testing.AndroidTestRunConfiguration;
|
||||
import org.jetbrains.android.run.testing.AndroidTestRunConfigurationType;
|
||||
import org.jetbrains.android.sdk.AndroidPlatform;
|
||||
@@ -85,6 +84,8 @@ public class AndroidModuleBuilder extends JavaModuleBuilder {
|
||||
private ProjectType myProjectType;
|
||||
private Module myTestedModule;
|
||||
private Sdk mySdk;
|
||||
private TargetSelectionMode myTargetSelectionMode;
|
||||
private String myPreferredAvd;
|
||||
|
||||
public void setupRootModel(final ModifiableRootModel rootModel) throws ConfigurationException {
|
||||
super.setupRootModel(rootModel);
|
||||
@@ -146,7 +147,9 @@ public class AndroidModuleBuilder extends JavaModuleBuilder {
|
||||
createResourcesAndLibs(project, contentRoot);
|
||||
PsiDirectory sourceDir = sourceRoot != null ? PsiManager.getInstance(project).findDirectory(sourceRoot) : null;
|
||||
createActivityAndSetupManifest(facet, sourceDir);
|
||||
addRunConfiguration(facet);
|
||||
if (myTargetSelectionMode != null) {
|
||||
addRunConfiguration(facet, myTargetSelectionMode, myPreferredAvd);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -276,12 +279,14 @@ public class AndroidModuleBuilder extends JavaModuleBuilder {
|
||||
if (project.isDisposed() || facet.getModule().isDisposed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (myProjectType == ProjectType.APPLICATION) {
|
||||
addRunConfiguration(facet);
|
||||
}
|
||||
else if (myProjectType == ProjectType.TEST) {
|
||||
addTestRunConfiguration(facet);
|
||||
|
||||
if (myTargetSelectionMode != null) {
|
||||
if (myProjectType == ProjectType.APPLICATION) {
|
||||
addRunConfiguration(facet, myTargetSelectionMode, myPreferredAvd);
|
||||
}
|
||||
else if (myProjectType == ProjectType.TEST) {
|
||||
addTestRunConfiguration(facet, myTargetSelectionMode, myPreferredAvd);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -354,35 +359,36 @@ public class AndroidModuleBuilder extends JavaModuleBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFirstModule(@NotNull Module module) {
|
||||
Project project = module.getProject();
|
||||
Module[] modules = ModuleManager.getInstance(project).getModules();
|
||||
return modules.length == 0 || (modules.length == 1 && ArrayUtil.find(modules, module) >= 0);
|
||||
}
|
||||
|
||||
private void addRunConfiguration(AndroidFacet facet) {
|
||||
private void addRunConfiguration(@NotNull AndroidFacet facet,
|
||||
@NotNull TargetSelectionMode targetSelectionMode,
|
||||
@Nullable String targetAvd) {
|
||||
String activityClass;
|
||||
if (isHelloAndroid()) {
|
||||
String activityClass = myPackageName + '.' + myActivityName;
|
||||
Module module = facet.getModule();
|
||||
AndroidUtils.addRunConfiguration(module.getProject(), facet, activityClass, !isFirstModule(module));
|
||||
activityClass = myPackageName + '.' + myActivityName;
|
||||
}
|
||||
else {
|
||||
activityClass = null;
|
||||
}
|
||||
Module module = facet.getModule();
|
||||
AndroidUtils.addRunConfiguration(module.getProject(), facet, activityClass, false, targetSelectionMode, targetAvd);
|
||||
}
|
||||
|
||||
private static void addTestRunConfiguration(final AndroidFacet facet) {
|
||||
String moduleName = facet.getModule().getName();
|
||||
private static void addTestRunConfiguration(final AndroidFacet facet, @NotNull TargetSelectionMode mode, @Nullable String preferredAvd) {
|
||||
Project project = facet.getModule().getProject();
|
||||
int result = Messages.showYesNoDialog(project, AndroidBundle.message("create.run.configuration.question", moduleName),
|
||||
AndroidBundle.message("create.run.configuration.title"), Messages.getQuestionIcon());
|
||||
if (result == 0) {
|
||||
RunManagerEx runManager = RunManagerEx.getInstanceEx(project);
|
||||
Module module = facet.getModule();
|
||||
RunnerAndConfigurationSettings settings = runManager
|
||||
.createRunConfiguration(module.getName(), AndroidTestRunConfigurationType.getInstance().getFactory());
|
||||
AndroidTestRunConfiguration configuration = (AndroidTestRunConfiguration)settings.getConfiguration();
|
||||
configuration.setModule(module);
|
||||
runManager.addConfiguration(settings, false);
|
||||
runManager.setActiveConfiguration(settings);
|
||||
RunManagerEx runManager = RunManagerEx.getInstanceEx(project);
|
||||
Module module = facet.getModule();
|
||||
RunnerAndConfigurationSettings settings = runManager
|
||||
.createRunConfiguration(module.getName(), AndroidTestRunConfigurationType.getInstance().getFactory());
|
||||
|
||||
AndroidTestRunConfiguration configuration = (AndroidTestRunConfiguration)settings.getConfiguration();
|
||||
configuration.setModule(module);
|
||||
configuration.setTargetSelectionMode(mode);
|
||||
if (preferredAvd != null) {
|
||||
configuration.PREFERRED_AVD = preferredAvd;
|
||||
}
|
||||
|
||||
runManager.addConfiguration(settings, false);
|
||||
runManager.setActiveConfiguration(settings);
|
||||
}
|
||||
|
||||
private boolean isHelloAndroid() {
|
||||
@@ -512,4 +518,12 @@ public class AndroidModuleBuilder extends JavaModuleBuilder {
|
||||
public void setTestedModule(Module module) {
|
||||
myTestedModule = module;
|
||||
}
|
||||
|
||||
public void setTargetSelectionMode(TargetSelectionMode targetSelectionMode) {
|
||||
myTargetSelectionMode = targetSelectionMode;
|
||||
}
|
||||
|
||||
public void setPreferredAvd(String preferredAvd) {
|
||||
myPreferredAvd = preferredAvd;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.android.newProject.AndroidModuleWizardStep">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="388" height="346"/>
|
||||
<xy x="20" y="20" width="533" height="368"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="etched"/>
|
||||
<children>
|
||||
<vspacer id="c6c48">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="1b82d" class="javax.swing.JLabel">
|
||||
@@ -87,6 +87,73 @@
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="3b31d" binding="myDeploymentTargetPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<clientProperties>
|
||||
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
|
||||
</clientProperties>
|
||||
<border type="etched" title-resource-bundle="messages/AndroidBundle" title-key="deployment.target.settings.title"/>
|
||||
<children>
|
||||
<component id="7ca46" class="javax.swing.JRadioButton" binding="myDoNotCreateConfigurationRadioButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/AndroidBundle" key="deployment.target.settings.wizard.configure.later"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="a020d">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="6cad7" class="javax.swing.JRadioButton" binding="myShowDeviceChooserRadioButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<selected value="false"/>
|
||||
<text resource-bundle="messages/AndroidBundle" key="deployment.target.settings.wizard.show.dialog"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="8687c" class="javax.swing.JRadioButton" binding="myUSBDeviceRadioButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/AndroidBundle" key="deployment.target.settings.wizard.usb.device"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="79e2e" class="com.intellij.openapi.ui.LabeledComponent" binding="myAvdComboComponent">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="3" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<componentClass value="com.intellij.ui.ComboboxWithBrowseButton"/>
|
||||
<labelLocation value="West"/>
|
||||
<text resource-bundle="messages/AndroidBundle" key="deployment.target.settings.prefer.avd.label.wizard"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="3bfa6">
|
||||
<constraints>
|
||||
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="8a0f9" class="javax.swing.JRadioButton" binding="myEmulatorRadioButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<selected value="true"/>
|
||||
<text resource-bundle="messages/AndroidBundle" key="deployment.target.settings.wizard.emulator"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<buttonGroups>
|
||||
@@ -95,5 +162,11 @@
|
||||
<member id="f868f"/>
|
||||
<member id="1d479"/>
|
||||
</group>
|
||||
<group name="myButtonGroup1">
|
||||
<member id="7ca46"/>
|
||||
<member id="6cad7"/>
|
||||
<member id="8687c"/>
|
||||
<member id="8a0f9"/>
|
||||
</group>
|
||||
</buttonGroups>
|
||||
</form>
|
||||
|
||||
@@ -16,23 +16,37 @@
|
||||
|
||||
package org.jetbrains.android.newProject;
|
||||
|
||||
import com.android.prefs.AndroidLocation;
|
||||
import com.android.sdklib.SdkManager;
|
||||
import com.android.sdklib.internal.avd.AvdManager;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
||||
import com.intellij.ide.util.projectWizard.WizardContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.ui.LabeledComponent;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.ui.ComboboxWithBrowseButton;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.android.sdk.AndroidSdkType;
|
||||
import org.jetbrains.android.sdk.AndroidSdkUtils;
|
||||
import org.jetbrains.android.actions.RunAndroidSdkManagerAction;
|
||||
import org.jetbrains.android.run.TargetSelectionMode;
|
||||
import org.jetbrains.android.sdk.*;
|
||||
import org.jetbrains.android.util.AndroidBundle;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -42,6 +56,7 @@ import java.awt.event.ActionListener;
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class AndroidModuleWizardStep extends ModuleWizardStep {
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.android.newProject.AndroidModuleWizardStep");
|
||||
|
||||
private final AndroidAppPropertiesEditor myAppPropertiesEditor;
|
||||
|
||||
@@ -59,13 +74,23 @@ public class AndroidModuleWizardStep extends ModuleWizardStep {
|
||||
private AndroidSdkComboBoxWithBrowseButton mySdkComboBoxWithBrowseButton;
|
||||
private JCheckBox myCreateDefaultStructure;
|
||||
private JPanel myApplicationPanel;
|
||||
private JRadioButton myDoNotCreateConfigurationRadioButton;
|
||||
private JRadioButton myShowDeviceChooserRadioButton;
|
||||
private JRadioButton myUSBDeviceRadioButton;
|
||||
private JRadioButton myEmulatorRadioButton;
|
||||
private LabeledComponent<ComboboxWithBrowseButton> myAvdComboComponent;
|
||||
private JPanel myDeploymentTargetPanel;
|
||||
|
||||
private final WizardContext myWizardContext;
|
||||
private final ComboboxWithBrowseButton myAvdCombo;
|
||||
private final Alarm myAvdsUpdatingAlarm = new Alarm();
|
||||
|
||||
private String[] myOldAvds = ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
|
||||
@NonNls private static final String TARGET_SELECTION_MODE_FOR_NEW_MODULE_PROPERTY = "ANDROID_TARGET_SELECTION_MODE_FOR_NEW_MODULE2";
|
||||
@NonNls private static final String TARGET_AVD_FOR_NEW_MODULE_PROPERTY = "ANDROID_TARGET_AVD_FOR_NEW_MODULE2";
|
||||
|
||||
public AndroidModuleWizardStep(@NotNull AndroidModuleBuilder moduleBuilder, WizardContext context) {
|
||||
super();
|
||||
|
||||
myWizardContext = context;
|
||||
myApplicationProjectButton.setSelected(true);
|
||||
|
||||
myAppPropertiesEditor = new AndroidAppPropertiesEditor(moduleBuilder.getName());
|
||||
@@ -87,6 +112,7 @@ public class AndroidModuleWizardStep extends ModuleWizardStep {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
updatePropertiesEditor();
|
||||
updateDeploymentTargetPanel();
|
||||
}
|
||||
};
|
||||
myApplicationProjectButton.addActionListener(listener);
|
||||
@@ -102,8 +128,92 @@ public class AndroidModuleWizardStep extends ModuleWizardStep {
|
||||
if (enabled) {
|
||||
updatePropertiesEditor();
|
||||
}
|
||||
updateDeploymentTargetPanel();
|
||||
}
|
||||
});
|
||||
|
||||
final ActionListener l = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myAvdComboComponent.setEnabled(myEmulatorRadioButton.isSelected());
|
||||
}
|
||||
};
|
||||
|
||||
myEmulatorRadioButton.addActionListener(l);
|
||||
myDoNotCreateConfigurationRadioButton.addActionListener(l);
|
||||
myShowDeviceChooserRadioButton.addActionListener(l);
|
||||
myUSBDeviceRadioButton.addActionListener(l);
|
||||
|
||||
myAvdCombo = myAvdComboComponent.getComponent();
|
||||
|
||||
myAvdCombo.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final Sdk selectedSdk = mySdkComboBoxWithBrowseButton.getSelectedSdk();
|
||||
if (selectedSdk == null || !(selectedSdk.getSdkType() instanceof AndroidSdkType)) {
|
||||
Messages.showErrorDialog(myPanel, AndroidBundle.message("specify.platform.error"));
|
||||
return;
|
||||
}
|
||||
|
||||
final AndroidSdkAdditionalData sdkAdditionalData = (AndroidSdkAdditionalData)selectedSdk.getSdkAdditionalData();
|
||||
if (sdkAdditionalData == null) {
|
||||
Messages.showErrorDialog(myPanel, AndroidBundle.message("android.wizard.invalid.sdk.error"));
|
||||
return;
|
||||
}
|
||||
|
||||
final AndroidPlatform platform = sdkAdditionalData.getAndroidPlatform();
|
||||
if (platform == null) {
|
||||
Messages.showErrorDialog(myPanel, AndroidBundle.message("cannot.parse.sdk.error"));
|
||||
return;
|
||||
}
|
||||
|
||||
RunAndroidSdkManagerAction.runTool(platform.getSdk().getLocation());
|
||||
}
|
||||
});
|
||||
|
||||
myAvdCombo.setMinimumSize(new Dimension(100, myAvdCombo.getMinimumSize().height));
|
||||
|
||||
final PropertiesComponent properties = PropertiesComponent.getInstance();
|
||||
final String targetSelectionModeStr = properties.getValue(TARGET_SELECTION_MODE_FOR_NEW_MODULE_PROPERTY);
|
||||
|
||||
if (targetSelectionModeStr != null) {
|
||||
if (targetSelectionModeStr.length() > 0) {
|
||||
try {
|
||||
final TargetSelectionMode targetSelectionMode = TargetSelectionMode.valueOf(targetSelectionModeStr);
|
||||
switch (targetSelectionMode) {
|
||||
case SHOW_DIALOG:
|
||||
myShowDeviceChooserRadioButton.setSelected(true);
|
||||
break;
|
||||
case EMULATOR:
|
||||
myEmulatorRadioButton.setSelected(true);
|
||||
break;
|
||||
case USB_DEVICE:
|
||||
myUSBDeviceRadioButton.setSelected(true);
|
||||
break;
|
||||
default:
|
||||
assert false : "Unknown target selection mode " + targetSelectionMode;
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
myDoNotCreateConfigurationRadioButton.setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
Disposer.dispose(myAvdsUpdatingAlarm);
|
||||
}
|
||||
|
||||
private void updateDeploymentTargetPanel() {
|
||||
final boolean enabled = myCreateDefaultStructure.isSelected() &&
|
||||
(myApplicationProjectButton.isSelected() || myTestProjectButton.isSelected());
|
||||
UIUtil.setEnabled(myDeploymentTargetPanel, enabled, true);
|
||||
if (enabled) {
|
||||
myAvdComboComponent.setEnabled(myEmulatorRadioButton.isSelected());
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePropertiesEditor() {
|
||||
@@ -133,8 +243,10 @@ public class AndroidModuleWizardStep extends ModuleWizardStep {
|
||||
myAppPropertiesEditor.getApplicationNameField().setText(myModuleBuilder.getName());
|
||||
|
||||
Sdk selectedSdk = mySdkComboBoxWithBrowseButton.getSelectedSdk();
|
||||
final PropertiesComponent properties = PropertiesComponent.getInstance();
|
||||
|
||||
if (selectedSdk == null) {
|
||||
String defaultPlatformName = PropertiesComponent.getInstance().getValue(AndroidSdkUtils.DEFAULT_PLATFORM_NAME_PROPERTY);
|
||||
String defaultPlatformName = properties.getValue(AndroidSdkUtils.DEFAULT_PLATFORM_NAME_PROPERTY);
|
||||
if (defaultPlatformName != null) {
|
||||
Sdk sdk = ProjectJdkTable.getInstance().findJdk(defaultPlatformName);
|
||||
if (sdk != null && sdk.getSdkType().equals(AndroidSdkType.getInstance())) {
|
||||
@@ -144,6 +256,16 @@ public class AndroidModuleWizardStep extends ModuleWizardStep {
|
||||
}
|
||||
mySdkComboBoxWithBrowseButton.rebuildSdksListAndSelectSdk(selectedSdk);
|
||||
|
||||
boolean shouldReset = myAvdCombo.getComboBox().getSelectedItem() == null;
|
||||
startUpdatingAvds();
|
||||
if (shouldReset) {
|
||||
final String targetAvd = properties.getValue(TARGET_AVD_FOR_NEW_MODULE_PROPERTY);
|
||||
if (targetAvd != null && targetAvd.length() > 0) {
|
||||
myAvdCombo.getComboBox().setSelectedItem(targetAvd);
|
||||
}
|
||||
}
|
||||
|
||||
updateDeploymentTargetPanel();
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
@@ -172,7 +294,9 @@ public class AndroidModuleWizardStep extends ModuleWizardStep {
|
||||
Sdk selectedSdk = mySdkComboBoxWithBrowseButton.getSelectedSdk();
|
||||
assert selectedSdk != null;
|
||||
|
||||
PropertiesComponent.getInstance().setValue(AndroidSdkUtils.DEFAULT_PLATFORM_NAME_PROPERTY, selectedSdk.getName());
|
||||
final PropertiesComponent properties = PropertiesComponent.getInstance();
|
||||
|
||||
properties.setValue(AndroidSdkUtils.DEFAULT_PLATFORM_NAME_PROPERTY, selectedSdk.getName());
|
||||
myModuleBuilder.setSdk(selectedSdk);
|
||||
|
||||
if (!myCreateDefaultStructure.isSelected()) {
|
||||
@@ -190,10 +314,98 @@ public class AndroidModuleWizardStep extends ModuleWizardStep {
|
||||
assert myTestPropertiesEditor != null;
|
||||
myModuleBuilder.setTestedModule(myTestPropertiesEditor.getModule());
|
||||
}
|
||||
|
||||
if (myApplicationProjectButton.isSelected() || myTestProjectButton.isSelected()) {
|
||||
String preferredAvdName = null;
|
||||
TargetSelectionMode targetSelectionMode = null;
|
||||
|
||||
if (myEmulatorRadioButton.isSelected()) {
|
||||
preferredAvdName = (String)myAvdCombo.getComboBox().getSelectedItem();
|
||||
targetSelectionMode = TargetSelectionMode.EMULATOR;
|
||||
}
|
||||
else if (myShowDeviceChooserRadioButton.isSelected()) {
|
||||
targetSelectionMode = TargetSelectionMode.SHOW_DIALOG;
|
||||
}
|
||||
else if (myUSBDeviceRadioButton.isSelected()) {
|
||||
targetSelectionMode = TargetSelectionMode.USB_DEVICE;
|
||||
}
|
||||
|
||||
myModuleBuilder.setTargetSelectionMode(targetSelectionMode);
|
||||
myModuleBuilder.setPreferredAvd(preferredAvdName);
|
||||
|
||||
properties.setValue(TARGET_SELECTION_MODE_FOR_NEW_MODULE_PROPERTY, targetSelectionMode != null ? targetSelectionMode.name() : "");
|
||||
properties.setValue(TARGET_AVD_FOR_NEW_MODULE_PROPERTY, preferredAvdName != null ? preferredAvdName : "");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpId() {
|
||||
return "reference.dialogs.new.project.fromScratch.android";
|
||||
}
|
||||
|
||||
private void startUpdatingAvds() {
|
||||
if (!myAvdCombo.getComboBox().isPopupVisible()) {
|
||||
doUpdateAvds();
|
||||
}
|
||||
addUpdatingRequest();
|
||||
}
|
||||
|
||||
private void addUpdatingRequest() {
|
||||
if (myAvdsUpdatingAlarm.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
myAvdsUpdatingAlarm.cancelAllRequests();
|
||||
myAvdsUpdatingAlarm.addRequest(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startUpdatingAvds();
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
private void doUpdateAvds() {
|
||||
final Sdk selectedSdk = mySdkComboBoxWithBrowseButton.getSelectedSdk();
|
||||
|
||||
String[] newAvds = ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
|
||||
if (selectedSdk != null && selectedSdk.getSdkType() instanceof AndroidSdkType) {
|
||||
final AndroidSdkAdditionalData sdkAdditionalData = (AndroidSdkAdditionalData)selectedSdk.getSdkAdditionalData();
|
||||
if (sdkAdditionalData != null) {
|
||||
final AndroidPlatform androidPlatform = sdkAdditionalData.getAndroidPlatform();
|
||||
if (androidPlatform != null) {
|
||||
newAvds = getAvds(androidPlatform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Arrays.equals(myOldAvds, newAvds)) {
|
||||
myOldAvds = newAvds;
|
||||
final JComboBox combo = myAvdCombo.getComboBox();
|
||||
final Object selected = combo.getSelectedItem();
|
||||
combo.setModel(new DefaultComboBoxModel(newAvds));
|
||||
combo.setSelectedItem(selected);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String[] getAvds(@NotNull AndroidPlatform androidPlatform) {
|
||||
final AndroidSdk sdkObject = androidPlatform.getSdk();
|
||||
if (sdkObject instanceof AndroidSdkImpl) {
|
||||
final SdkManager sdkManager = ((AndroidSdkImpl)sdkObject).getSdkManager();
|
||||
try {
|
||||
final AvdManager avdManager = new AvdManager(sdkManager, new MessageBuildingSdkLog());
|
||||
final AvdManager.AvdInfo[] validAvds = avdManager.getValidAvds();
|
||||
|
||||
final String[] avdNames = new String[validAvds.length];
|
||||
for (int i = 0; i < validAvds.length; i++) {
|
||||
avdNames[i] = validAvds[i].getName();
|
||||
}
|
||||
return avdNames;
|
||||
}
|
||||
catch (AndroidLocation.AndroidLocationException e) {
|
||||
LOG.info(e);
|
||||
}
|
||||
}
|
||||
return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,14 +71,14 @@
|
||||
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="etched" title="Deployment Target"/>
|
||||
<border type="etched" title-resource-bundle="messages/AndroidBundle" title-key="deployment.target.settings.title"/>
|
||||
<children>
|
||||
<component id="69acb" class="javax.swing.JRadioButton" binding="myEmulatorRadioButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Emulato&r"/>
|
||||
<text resource-bundle="messages/AndroidBundle" key="deployment.target.settings.emulator"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="486f3" class="javax.swing.JRadioButton" binding="myUsbDeviceRadioButton">
|
||||
@@ -86,7 +86,7 @@
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&USB device"/>
|
||||
<text resource-bundle="messages/AndroidBundle" key="deployment.target.settings.usb.device"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c7aa9" class="javax.swing.JRadioButton" binding="myShowChooserRadioButton">
|
||||
@@ -94,7 +94,7 @@
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Show &chooser dialog"/>
|
||||
<text resource-bundle="messages/AndroidBundle" key="deployment.target.settings.show.dialog"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="96ed1" class="com.intellij.openapi.ui.LabeledComponent" binding="myAvdComboComponent">
|
||||
@@ -105,7 +105,7 @@
|
||||
<componentClass value="com.intellij.ui.ComboboxWithBrowseButton"/>
|
||||
<enabled value="true"/>
|
||||
<labelLocation value="West"/>
|
||||
<text value="&Prefer Android Virtual Device for deployment"/>
|
||||
<text resource-bundle="messages/AndroidBundle" key="deployment.target.settings.prefer.avd.label"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="2833">
|
||||
|
||||
@@ -58,7 +58,7 @@ public abstract class AvdComboBox extends ComboboxWithBrowseButton {
|
||||
return;
|
||||
}
|
||||
|
||||
RunAndroidSdkManagerAction.runTool(module.getProject(), platform.getSdk().getLocation());
|
||||
RunAndroidSdkManagerAction.runTool(platform.getSdk().getLocation());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -77,8 +77,7 @@ import org.jetbrains.android.dom.manifest.IntentFilter;
|
||||
import org.jetbrains.android.dom.manifest.Manifest;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.android.facet.AndroidFacetConfiguration;
|
||||
import org.jetbrains.android.run.AndroidRunConfiguration;
|
||||
import org.jetbrains.android.run.AndroidRunConfigurationType;
|
||||
import org.jetbrains.android.run.*;
|
||||
import org.jetbrains.android.sdk.AndroidSdk;
|
||||
import org.jetbrains.android.sdk.AndroidSdkAdditionalData;
|
||||
import org.jetbrains.android.sdk.AndroidSdkType;
|
||||
@@ -305,7 +304,9 @@ public class AndroidUtils {
|
||||
public static void addRunConfiguration(final Project project,
|
||||
final AndroidFacet facet,
|
||||
@Nullable final String activityClass,
|
||||
boolean ask) {
|
||||
final boolean ask,
|
||||
@Nullable final TargetSelectionMode targetSelectionMode,
|
||||
@Nullable final String preferredAvdName) {
|
||||
final Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
RunManagerEx runManager = RunManagerEx.getInstanceEx(project);
|
||||
@@ -321,6 +322,14 @@ public class AndroidUtils {
|
||||
else {
|
||||
configuration.MODE = AndroidRunConfiguration.LAUNCH_DEFAULT_ACTIVITY;
|
||||
}
|
||||
|
||||
if (targetSelectionMode != null) {
|
||||
configuration.setTargetSelectionMode(targetSelectionMode);
|
||||
}
|
||||
if (preferredAvdName != null) {
|
||||
configuration.PREFERRED_AVD = preferredAvdName;
|
||||
}
|
||||
|
||||
runManager.addConfiguration(settings, false);
|
||||
runManager.setActiveConfiguration(settings);
|
||||
}
|
||||
@@ -452,12 +461,12 @@ public class AndroidUtils {
|
||||
return exitCode == 0;
|
||||
}
|
||||
|
||||
public static void runExternalToolInSeparateThread(@NotNull final Project project,
|
||||
public static void runExternalToolInSeparateThread(@Nullable final Project project,
|
||||
@NotNull final GeneralCommandLine commandLine) {
|
||||
runExternalToolInSeparateThread(project, commandLine, null);
|
||||
}
|
||||
|
||||
public static void runExternalToolInSeparateThread(@NotNull final Project project,
|
||||
public static void runExternalToolInSeparateThread(@Nullable final Project project,
|
||||
@NotNull final GeneralCommandLine commandLine,
|
||||
@Nullable final ProcessHandler processHandler) {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
|
||||
Reference in New Issue
Block a user