Search in sources :

Example 1 with AvdManagerLog

use of org.jetbrains.android.sdk.AvdManagerLog in project android by JetBrains.

the class EmulatorTargetChooser method chooseAvd.

@Nullable
private String chooseAvd() {
    IAndroidTarget buildTarget = myFacet.getConfiguration().getAndroidTarget();
    assert buildTarget != null;
    AvdInfo[] avds = myFacet.getValidCompatibleAvds();
    if (avds.length > 0) {
        return avds[0].getName();
    }
    final Project project = myFacet.getModule().getProject();
    AvdManager manager;
    try {
        manager = myFacet.getAvdManager(new AvdManagerLog() {

            @Override
            public void error(Throwable t, String errorFormat, Object... args) {
                super.error(t, errorFormat, args);
                if (errorFormat != null) {
                    final String msg = String.format(errorFormat, args);
                    LOG.error(msg);
                }
            }
        });
    } catch (final AndroidLocation.AndroidLocationException e) {
        LOG.info(e);
        UIUtil.invokeLaterIfNeeded(new Runnable() {

            @Override
            public void run() {
                Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle());
            }
        });
        return null;
    }
    final AvdManager finalManager = manager;
    assert finalManager != null;
    return UIUtil.invokeAndWaitIfNeeded(new Computable<String>() {

        @Override
        public String compute() {
            int result = Messages.showDialog(project, "To run using the emulator, you must have an AVD defined.", "Define AVD", new String[] { "Cancel", "Create AVD" }, 1, null);
            AvdInfo createdAvd = null;
            if (result == 1) {
                AvdOptionsModel avdOptionsModel = new AvdOptionsModel(null);
                ModelWizardDialog dialog = AvdWizardUtils.createAvdWizard(null, project, avdOptionsModel);
                if (dialog.showAndGet()) {
                    createdAvd = avdOptionsModel.getCreatedAvd();
                }
            }
            return createdAvd == null ? null : createdAvd.getName();
        }
    });
}
Also used : AvdManagerLog(org.jetbrains.android.sdk.AvdManagerLog) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) IAndroidTarget(com.android.sdklib.IAndroidTarget) AvdOptionsModel(com.android.tools.idea.avdmanager.AvdOptionsModel) Project(com.intellij.openapi.project.Project) AvdManager(com.android.sdklib.internal.avd.AvdManager) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) AndroidLocation(com.android.prefs.AndroidLocation) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AndroidLocation (com.android.prefs.AndroidLocation)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)1 AvdManager (com.android.sdklib.internal.avd.AvdManager)1 AvdOptionsModel (com.android.tools.idea.avdmanager.AvdOptionsModel)1 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)1 Project (com.intellij.openapi.project.Project)1 AvdManagerLog (org.jetbrains.android.sdk.AvdManagerLog)1 Nullable (org.jetbrains.annotations.Nullable)1