Example usage for com.intellij.openapi.ui Messages YES

List of usage examples for com.intellij.openapi.ui Messages YES

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages YES.

Prototype

int YES

To view the source code for com.intellij.openapi.ui Messages YES.

Click Source Link

Usage

From source file:bazaar4idea.action.BzrInit.java

License:Apache License

private static void doInit(final Project project, FileChooserDescriptor fcd, VirtualFile baseDir,
        final VirtualFile finalBaseDir) {
    FileChooser.chooseFile(fcd, project, baseDir, new Consumer<VirtualFile>() {
        @Override//from   w w  w  .j  a v  a2s  .  c  o  m
        public void consume(final VirtualFile root) {
            if (BzrUtil.isUnderBzr(root) && Messages.showYesNoDialog(project,
                    BzrBundle.message("init.warning.already.under.bzr",
                            StringUtil.escapeXml(root.getPresentableUrl())),
                    BzrBundle.getString("init.warning.title"), Messages.getWarningIcon()) != Messages.YES) {
                return;
            }

            BzrCommandResult result = ServiceManager.getService(Bzr.class).init(project, root);
            if (!result.success()) {
                BzrVcs vcs = BzrVcs.getInstance(project);
                if (vcs != null && vcs.getExecutableValidator().checkExecutableAndNotifyIfNeeded()) {
                    BzrUIUtil.notify(BzrVcs.IMPORTANT_ERROR_NOTIFICATION, project, "Bazaar init failed",
                            result.getErrorOutputAsHtmlString(), NotificationType.ERROR, null);
                }
                return;
            }

            if (project.isDefault()) {
                return;
            }
            final String path = root.equals(finalBaseDir) ? "" : root.getPath();
            BzrVcs.runInBackground(new Task.Backgroundable(project, BzrBundle.getString("common.refreshing")) {
                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    refreshAndConfigureVcsMappings(project, root, path);
                }
            });
        }
    });
}

From source file:com.android.tools.idea.avdmanager.AvdEditWizard.java

License:Apache License

@Override
public void performFinishingActions() {
    Device device = myState.get(DEVICE_DEFINITION_KEY);
    assert device != null; // Validation should be done by individual steps
    SystemImageDescription systemImageDescription = myState.get(SYSTEM_IMAGE_KEY);
    assert systemImageDescription != null;
    ScreenOrientation orientation = myState.get(DEFAULT_ORIENTATION_KEY);
    if (orientation == null) {
        orientation = device.getDefaultState().getOrientation();
    }// www.  j av a2s .c o m

    Map<String, String> hardwareProperties = DeviceManager.getHardwareProperties(device);
    Map<String, Object> userEditedProperties = myState.flatten();

    // Remove the SD card setting that we're not using
    String sdCard = null;

    Boolean useExternalSdCard = myState.get(DISPLAY_USE_EXTERNAL_SD_KEY);
    boolean useExisting = useExternalSdCard != null && useExternalSdCard;
    if (!useExisting) {
        if (Objects.equal(myState.get(SD_CARD_STORAGE_KEY), myState.get(DISPLAY_SD_SIZE_KEY))) {
            // unchanged, use existing card
            useExisting = true;
        }
    }
    boolean hasSdCard;
    if (!useExisting) {
        userEditedProperties.remove(EXISTING_SD_LOCATION.name);
        Storage storage = myState.get(DISPLAY_SD_SIZE_KEY);
        myState.put(SD_CARD_STORAGE_KEY, storage);
        if (storage != null) {
            sdCard = toIniString(storage, false);
        }
        hasSdCard = storage != null && storage.getSize() > 0;
    } else {
        sdCard = myState.get(DISPLAY_SD_LOCATION_KEY);
        myState.put(EXISTING_SD_LOCATION, sdCard);
        userEditedProperties.remove(SD_CARD_STORAGE_KEY.name);
        assert sdCard != null;
        hasSdCard = true;
        hardwareProperties.put(HardwareProperties.HW_SDCARD, toIniString(true));
    }
    hardwareProperties.put(HardwareProperties.HW_SDCARD, toIniString(hasSdCard));
    // Remove any internal keys from the map
    userEditedProperties = Maps.filterEntries(userEditedProperties, new Predicate<Map.Entry<String, Object>>() {
        @Override
        public boolean apply(Map.Entry<String, Object> input) {
            return !input.getKey().startsWith(WIZARD_ONLY) && input.getValue() != null;
        }
    });
    // Call toString() on all remaining values
    hardwareProperties.putAll(
            Maps.transformEntries(userEditedProperties, new Maps.EntryTransformer<String, Object, String>() {
                @Override
                public String transformEntry(String key, Object value) {
                    if (value instanceof Storage) {
                        if (key.equals(AvdWizardConstants.RAM_STORAGE_KEY.name)
                                || key.equals(AvdWizardConstants.VM_HEAP_STORAGE_KEY.name)) {
                            return toIniString((Storage) value, true);
                        } else {
                            return toIniString((Storage) value, false);
                        }
                    } else if (value instanceof Boolean) {
                        return toIniString((Boolean) value);
                    } else if (value instanceof AvdScaleFactor) {
                        return toIniString((AvdScaleFactor) value);
                    } else if (value instanceof File) {
                        return toIniString((File) value);
                    } else if (value instanceof Double) {
                        return toIniString((Double) value);
                    } else {
                        return value.toString();
                    }
                }
            }));

    File skinFile = myState.get(CUSTOM_SKIN_FILE_KEY);
    if (skinFile == null) {
        skinFile = resolveSkinPath(device.getDefaultHardware().getSkinFile(), systemImageDescription);
    }
    File backupSkinFile = myState.get(BACKUP_SKIN_FILE_KEY);
    if (backupSkinFile != null) {
        hardwareProperties.put(AvdManager.AVD_INI_BACKUP_SKIN_PATH, backupSkinFile.getPath());
    }

    // Add defaults if they aren't already set differently
    if (!hardwareProperties.containsKey(AvdManager.AVD_INI_SKIN_DYNAMIC)) {
        hardwareProperties.put(AvdManager.AVD_INI_SKIN_DYNAMIC, toIniString(true));
    }
    if (!hardwareProperties.containsKey(HardwareProperties.HW_KEYBOARD)) {
        hardwareProperties.put(HardwareProperties.HW_KEYBOARD, toIniString(false));
    }

    boolean isCircular = device.isScreenRound();

    String tempAvdName = myState.get(AvdWizardConstants.AVD_ID_KEY);
    if (tempAvdName == null || tempAvdName.isEmpty()) {
        tempAvdName = calculateAvdName(myAvdInfo, hardwareProperties, device, myForceCreate);
    }
    final String avdName = tempAvdName;

    // If we're editing an AVD and we downgrade a system image, wipe the user data with confirmation
    if (myAvdInfo != null && !myForceCreate) {
        IAndroidTarget target = myAvdInfo.getTarget();
        if (target != null) {

            int oldApiLevel = target.getVersion().getFeatureLevel();
            int newApiLevel = systemImageDescription.getVersion().getFeatureLevel();
            final String oldApiName = target.getVersion().getApiString();
            final String newApiName = systemImageDescription.getVersion().getApiString();
            if (oldApiLevel > newApiLevel || (oldApiLevel == newApiLevel && target.getVersion().isPreview()
                    && !systemImageDescription.getVersion().isPreview())) {
                final AtomicReference<Boolean> shouldContinue = new AtomicReference<Boolean>();
                ApplicationManager.getApplication().invokeAndWait(new Runnable() {
                    @Override
                    public void run() {
                        String message = String.format(Locale.getDefault(),
                                "You are about to downgrade %1$s from API level %2$s to API level %3$s.\n"
                                        + "This requires a wipe of the userdata partition of the AVD.\nDo you wish to "
                                        + "continue with the data wipe?",
                                avdName, oldApiName, newApiName);
                        int result = Messages.showYesNoDialog((Project) null, message, "Confirm Data Wipe",
                                AllIcons.General.QuestionDialog);
                        shouldContinue.set(result == Messages.YES);
                    }
                }, ModalityState.any());
                if (shouldContinue.get()) {
                    AvdManagerConnection.getDefaultAvdManagerConnection().wipeUserData(myAvdInfo);
                } else {
                    return;
                }
            }
        }
    }

    AvdManagerConnection connection = AvdManagerConnection.getDefaultAvdManagerConnection();
    connection.createOrUpdateAvd(myForceCreate ? null : myAvdInfo, avdName, device, systemImageDescription,
            orientation, isCircular, sdCard, skinFile, hardwareProperties, false);
}

From source file:com.android.tools.idea.avdmanager.AvdOptionsModel.java

License:Apache License

@Override
protected void handleFinished() {
    // By this point we should have both a Device and a SystemImage
    Device device = myDevice.getValue();
    SystemImageDescription systemImage = mySystemImage.getValue();

    Map<String, String> hardwareProperties = DeviceManager.getHardwareProperties(device);
    Map<String, Object> userEditedProperties = generateUserEditedPropertiesMap();

    // Remove the SD card setting that we're not using
    String sdCard = null;//from  w  w  w  . j  a v a  2s  .  c  o  m

    boolean useExisting = myUseExternalSdCard.get();
    if (!useExisting) {
        if (sdCardStorage().get().isPresent() && myOriginalSdCard != null
                && sdCardStorage().getValue().equals(myOriginalSdCard.get())) {
            // unchanged, use existing card
            useExisting = true;
        }
    }

    boolean hasSdCard = false;
    if (!useExisting) {

        userEditedProperties.remove(AvdWizardUtils.EXISTING_SD_LOCATION);
        Storage storage = null;
        myOriginalSdCard = new ObjectValueProperty<>(mySdCardStorage.getValue());
        if (mySdCardStorage.get().isPresent()) {
            storage = mySdCardStorage.getValue();
            sdCard = toIniString(storage, false);
        }
        hasSdCard = storage != null && storage.getSize() > 0;
    } else if (!Strings.isNullOrEmpty(existingSdLocation.get())) {
        sdCard = existingSdLocation.get();
        userEditedProperties.remove(AvdWizardUtils.SD_CARD_STORAGE_KEY);
        hasSdCard = true;
    }
    hardwareProperties.put(HardwareProperties.HW_SDCARD, toIniString(hasSdCard));
    // Remove any internal keys from the map
    userEditedProperties = Maps.filterEntries(userEditedProperties,
            input -> !input.getKey().startsWith(AvdWizardUtils.WIZARD_ONLY) && input.getValue() != null);

    // Call toIniString() on all remaining values
    hardwareProperties.putAll(Maps.transformEntries(userEditedProperties, (key, value) -> {
        if (value instanceof Storage) {
            if (key.equals(AvdWizardUtils.RAM_STORAGE_KEY) || key.equals(AvdWizardUtils.VM_HEAP_STORAGE_KEY)) {
                return toIniString((Storage) value, true);
            } else {
                return toIniString((Storage) value, false);
            }
        } else if (value instanceof Boolean) {
            return toIniString((Boolean) value);
        } else if (value instanceof File) {
            return toIniString((File) value);
        } else if (value instanceof Double) {
            return toIniString((Double) value);
        } else if (value instanceof GpuMode) {
            return ((GpuMode) value).getGpuSetting();
        } else {
            return value.toString();
        }
    }));

    File skinFile = (myAvdDeviceData.customSkinFile().get().isPresent())
            ? myAvdDeviceData.customSkinFile().getValue()
            : AvdWizardUtils.resolveSkinPath(device.getDefaultHardware().getSkinFile(), systemImage,
                    FileOpUtils.create());

    if (myBackupSkinFile.get().isPresent()) {
        hardwareProperties.put(AvdManager.AVD_INI_BACKUP_SKIN_PATH, myBackupSkinFile.getValue().getPath());
    }

    // Add defaults if they aren't already set differently
    if (!hardwareProperties.containsKey(AvdManager.AVD_INI_SKIN_DYNAMIC)) {
        hardwareProperties.put(AvdManager.AVD_INI_SKIN_DYNAMIC, toIniString(true));
    }
    if (!hardwareProperties.containsKey(HardwareProperties.HW_KEYBOARD)) {
        hardwareProperties.put(HardwareProperties.HW_KEYBOARD, toIniString(false));
    }

    boolean isCircular = myAvdDeviceData.isScreenRound().get();

    String tempAvdName = myAvdId.get();
    final String avdName = tempAvdName.isEmpty() ? calculateAvdName(myAvdInfo, hardwareProperties, device)
            : tempAvdName;

    // If we're editing an AVD and we downgrade a system image, wipe the user data with confirmation
    if (myAvdInfo != null) {
        ISystemImage image = myAvdInfo.getSystemImage();
        if (image != null) {
            int oldApiLevel = image.getAndroidVersion().getFeatureLevel();
            int newApiLevel = systemImage.getVersion().getFeatureLevel();
            final String oldApiName = image.getAndroidVersion().getApiString();
            final String newApiName = systemImage.getVersion().getApiString();
            if (oldApiLevel > newApiLevel || (oldApiLevel == newApiLevel
                    && image.getAndroidVersion().isPreview() && !systemImage.getVersion().isPreview())) {
                final AtomicReference<Boolean> shouldContinue = new AtomicReference<>();
                ApplicationManager.getApplication().invokeAndWait(() -> {
                    String message = String.format(Locale.getDefault(),
                            "You are about to downgrade %1$s from API level %2$s to API level %3$s.\n"
                                    + "This requires a wipe of the userdata partition of the AVD.\nDo you wish to "
                                    + "continue with the data wipe?",
                            avdName, oldApiName, newApiName);
                    int result = Messages.showYesNoDialog((Project) null, message, "Confirm Data Wipe",
                            AllIcons.General.QuestionDialog);
                    shouldContinue.set(result == Messages.YES);
                }, ModalityState.any());
                if (shouldContinue.get()) {
                    AvdManagerConnection.getDefaultAvdManagerConnection().wipeUserData(myAvdInfo);
                } else {
                    return;
                }
            }
        }
    }

    AvdManagerConnection connection = AvdManagerConnection.getDefaultAvdManagerConnection();
    myCreatedAvd = connection.createOrUpdateAvd(myAvdInfo, avdName, device, systemImage,
            mySelectedAvdOrientation.get(), isCircular, sdCard, skinFile, hardwareProperties, false);
    if (myCreatedAvd == null) {
        ApplicationManager.getApplication().invokeAndWait(() -> Messages.showErrorDialog((Project) null,
                "An error occurred while creating the AVD. See idea.log for details.", "Error Creating AVD"),
                ModalityState.any());
    }
}

From source file:com.android.tools.idea.avdmanager.ConfigureAvdOptionsStep.java

License:Apache License

private void addListeners() {
    myAvdId.addMouseListener(new MouseAdapter() {
        @Override//from   ww  w. j  a  v  a2  s  . c o  m
        public void mouseClicked(MouseEvent mouseEvent) {
            myAvdId.requestFocusInWindow();
        }
    });

    myShowAdvancedSettingsButton.addActionListener(myToggleAdvancedSettingsListener);
    myChangeDeviceButton.addActionListener(myChangeDeviceButtonListener);
    myChangeSystemImageButton.addActionListener(myChangeSystemImageButtonListener);

    myExternalRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            myExternalSdCard.setEnabled(true);
            myBuiltInSdCardStorage.setEnabled(false);
        }
    });
    myBuiltInRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            myExternalSdCard.setEnabled(false);
            myBuiltInSdCardStorage.setEnabled(true);
        }
    });

    myOrientationToggle.setOpaque(false);
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(FOCUS_OWNER,
            myPropertyChangeListener);

    myListeners.receive(getModel().device(), device -> {
        toggleOptionals(device, true);
        if (device.isPresent()) {
            myDeviceName.setIcon(DeviceDefinitionPreview.getIcon(getModel().getAvdDeviceData()));
            myDeviceName.setText(getModel().device().getValue().getDisplayName());
            updateDeviceDetails();
        }
    });

    List<AbstractProperty<?>> deviceProperties = AbstractProperty.getAll(getModel().getAvdDeviceData());
    deviceProperties.add(getModel().systemImage());
    myListeners.listenAll(deviceProperties).with(new Runnable() {
        @Override
        public void run() {
            if (getModel().systemImage().get().isPresent()
                    && getModel().getAvdDeviceData().customSkinFile().get().isPresent()) {
                File skin = AvdWizardUtils.resolveSkinPath(
                        getModel().getAvdDeviceData().customSkinFile().getValue(),
                        getModel().systemImage().getValue(), FileOpUtils.create());
                if (skin != null) {
                    getModel().getAvdDeviceData().customSkinFile().setValue(skin);
                    if (FileUtil.filesEqual(skin, AvdWizardUtils.NO_SKIN)) {
                        myDeviceFrameCheckbox.setSelected(false);
                    }
                } else {
                    getModel().getAvdDeviceData().customSkinFile().setValue(AvdWizardUtils.NO_SKIN);
                }
            }
        }
    });

    myListeners.listen(getModel().systemImage(), new InvalidationListener() {
        @Override
        public void onInvalidated(@NotNull ObservableValue<?> sender) {
            updateSystemImageData();
        }
    });

    myListeners.receive(getModel().sdCardStorage(), storage -> {
        if (myCheckSdForChanges && storage.isPresent() && !storage.get().equals(myOriginalSdCard)) {
            int result = Messages.showYesNoDialog((Project) null,
                    "Changing the size of the built-in SD card will erase "
                            + "the current contents of the card. Continue?",
                    "Confirm Data Wipe", AllIcons.General.QuestionDialog);
            if (result == Messages.YES) {
                myCheckSdForChanges = false;
            } else {
                getModel().sdCardStorage().setValue(myOriginalSdCard);
            }
        }
    });

    myListeners.listen(getModel().useQemu2(), new InvalidationListener() {
        @Override
        public void onInvalidated(@NotNull ObservableValue<?> sender) {
            toggleSystemOptionals(true);
        }
    });

    myListeners.receive(getModel().selectedAvdOrientation(),
            screenOrientation -> myOrientationToggle.setSelectedElement(screenOrientation));
}

From source file:com.android.tools.idea.avdmanager.DeleteAvdAction.java

License:Apache License

@Override
public void actionPerformed(ActionEvent e) {
    AvdManagerConnection connection = AvdManagerConnection.getDefaultAvdManagerConnection();
    AvdInfo info = getAvdInfo();/*from  w ww .  j a v a 2s.  c o  m*/
    if (info == null) {
        return;
    }
    if (connection.isAvdRunning(info)) {
        Messages.showErrorDialog(myAvdInfoProvider.getComponent(),
                "The selected AVD is currently running in the Emulator. Please exit the emulator instance and try deleting again.",
                "Cannot Delete A Running AVD");
        return;
    }
    int result = Messages.showYesNoDialog(myAvdInfoProvider.getComponent(),
            "Do you really want to delete AVD " + info.getName() + "?", "Confirm Deletion",
            AllIcons.General.QuestionDialog);
    if (result == Messages.YES) {
        if (!connection.deleteAvd(info)) {
            Messages.showErrorDialog(myAvdInfoProvider.getComponent(),
                    "An error occurred while deleting the AVD. See idea.log for details.",
                    "Error Deleting AVD");
        }
        refreshAvds();
    }
}

From source file:com.android.tools.idea.avdmanager.DeleteDeviceAction.java

License:Apache License

@Override
public void actionPerformed(ActionEvent e) {
    Device device = myProvider.getDevice();
    int result = Messages.showYesNoDialog((Project) null,
            "Do you really want to delete Device " + device.getDisplayName() + "?", "Confirm Deletion",
            AllIcons.General.QuestionDialog);
    if (result == Messages.YES) {
        DeviceManagerConnection.getDefaultDeviceManagerConnection().deleteDevice(device);
        myProvider.refreshDevices();// w w  w  .j av a 2s .  c  o m
        myProvider.selectDefaultDevice();
    }
}

From source file:com.android.tools.idea.avdmanager.WipeAvdDataAction.java

License:Apache License

@Override
public void actionPerformed(ActionEvent e) {
    AvdManagerConnection connection = AvdManagerConnection.getDefaultAvdManagerConnection();
    AvdInfo avdInfo = getAvdInfo();//from ww  w .j  ava  2s .c  o m
    if (avdInfo == null) {
        return;
    }
    if (connection.isAvdRunning(avdInfo)) {
        Messages.showErrorDialog(myAvdInfoProvider.getComponent(),
                "The selected AVD is currently running in the Emulator. "
                        + "Please exit the emulator instance and try wiping again.",
                "Cannot Wipe A Running AVD");
        return;
    }
    int result = Messages.showYesNoDialog(myAvdInfoProvider.getComponent(),
            "Do you really want to wipe user files from AVD " + avdInfo.getName() + "?", "Confirm Data Wipe",
            AllIcons.General.QuestionDialog);
    if (result == Messages.YES) {
        connection.wipeUserData(avdInfo);
        refreshAvds();
    }
}

From source file:com.android.tools.idea.gradle.actions.CleanImportProjectAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();/*from w ww .  j a va  2  s. c  om*/
    if (project != null && isGradleProjectIfNotNull(project)) {
        String projectName = project.getName();
        int answer = Messages.showYesNoDialog(project, String.format(MESSAGE_FORMAT, projectName), TITLE, null);
        if (answer == Messages.YES) {
            LOG.info(String.format("Closing, cleaning and re-importing project '%1$s'...", projectName));
            List<File> filesToDelete = collectFilesToDelete(project);
            File projectDirPath = getBaseDirPath(project);
            close(project);
            deleteFiles(filesToDelete, projectName);
            try {
                LOG.info(String.format("About to import project '%1$s'.", projectName));
                GradleProjectImporter.getInstance().importProject(projectName, projectDirPath, null);
                LOG.info(String.format("Done importing project '%1$s'.", projectName));
            } catch (Exception error) {
                String title = getErrorMessageTitle(error);
                Messages.showErrorDialog(error.getMessage(), title);
                LOG.info(String.format("Failed to import project '%1$s'.", projectName));
            }
        }
    }
}

From source file:com.android.tools.idea.gradle.project.SdkSync.java

License:Apache License

@VisibleForTesting
static void syncIdeAndProjectAndroidSdks(@NotNull final LocalProperties localProperties,
        @NotNull FindValidSdkPathTask findSdkPathTask) {
    if (localProperties.hasAndroidDirProperty()) {
        // if android.dir is specified, we don't sync SDKs. User is working with SDK sources.
        return;/*from   w ww. j  a v a 2  s  .co m*/
    }

    final File ideAndroidSdkPath = IdeSdks.getAndroidSdkPath();
    final File projectAndroidSdkPath = localProperties.getAndroidSdkPath();

    if (ideAndroidSdkPath != null) {
        if (projectAndroidSdkPath == null) {
            // If we have the IDE default SDK and we don't have a project SDK, update local.properties with default SDK path and exit.
            setProjectSdk(localProperties, ideAndroidSdkPath);
            return;
        }
        final ValidationResult validationResult = validateAndroidSdk(projectAndroidSdkPath, true);
        if (!validationResult.success) {
            // If we have the IDE default SDK and we don't have a valid project SDK, update local.properties with default SDK path and exit.
            invokeAndWaitIfNeeded(new Runnable() {
                @Override
                public void run() {
                    if (!ApplicationManager.getApplication().isUnitTestMode()) {
                        String error = validationResult.message;
                        if (isEmpty(error)) {
                            error = String.format(
                                    "The path \n'%1$s'\n" + "does not refer to a valid Android SDK.",
                                    projectAndroidSdkPath.getPath());
                        }
                        String format = "%1$s\n\nAndroid Studio will use this Android SDK instead:\n'%2$s'\nand will modify the project's local.properties file.";
                        Messages.showErrorDialog(String.format(format, error, ideAndroidSdkPath.getPath()),
                                ERROR_DIALOG_TITLE);
                    }
                    setProjectSdk(localProperties, ideAndroidSdkPath);
                }
            });
            return;
        }
    } else {
        if (projectAndroidSdkPath == null || !isValidAndroidSdkPath(projectAndroidSdkPath)) {
            // We don't have any SDK (IDE or project.)
            File selectedPath = findSdkPathTask.selectValidSdkPath();
            if (selectedPath == null) {
                throw new ExternalSystemException("Unable to continue until an Android SDK is specified");
            }
            setIdeSdk(localProperties, selectedPath);
            return;
        }

        // If we have a valid project SDK but we don't have IDE default SDK, update IDE with project SDK path and exit.
        setIdeSdk(localProperties, projectAndroidSdkPath);
        return;
    }

    if (!filesEqual(ideAndroidSdkPath, projectAndroidSdkPath)) {
        final String msg = String.format("The project and Android Studio point to different Android SDKs.\n\n"
                + "Android Studio's default SDK is in:\n" + "%1$s\n\n"
                + "The project's SDK (specified in local.properties) is in:\n" + "%2$s\n\n"
                + "To keep results consistent between IDE and command line builds, only one path can be used. "
                + "Do you want to:\n\n"
                + "[1] Use Android Studio's default SDK (modifies the project's local.properties file.)\n\n"
                + "[2] Use the project's SDK (modifies Android Studio's default.)\n\n"
                + "Note that switching SDKs could cause compile errors if the selected SDK doesn't have the "
                + "necessary Android platforms or build tools.", ideAndroidSdkPath.getPath(),
                projectAndroidSdkPath.getPath());
        invokeAndWaitIfNeeded(new Runnable() {
            @Override
            public void run() {
                int result = MessageDialogBuilder.yesNo("Android SDK Manager", msg)
                        .yesText("Use Android Studio's SDK").noText("Use Project's SDK").show();
                if (result == Messages.YES) {
                    // Use Android Studio's SDK
                    setProjectSdk(localProperties, ideAndroidSdkPath);
                } else {
                    // Use project's SDK
                    setIdeSdk(localProperties, projectAndroidSdkPath);
                }
                if (isGuiTestingMode() && !getGuiTestSuiteState().isSkipSdkMerge()) {
                    mergeIfNeeded(projectAndroidSdkPath, ideAndroidSdkPath);
                }
            }
        });
    }
}

From source file:com.android.tools.idea.gradle.project.SdkSync.java

License:Apache License

private static void mergeIfNeeded(@NotNull final File sourceSdk, @NotNull final File destSdk) {
    if (SdkMerger.hasMergeableContent(sourceSdk, destSdk)) {
        String msg = String.format(
                "The Android SDK at\n\n%1$s\n\nhas packages not in your project's SDK at\n\n%2$s\n\n"
                        + "Would you like to copy into the project SDK?",
                sourceSdk.getPath(), destSdk.getPath());
        int result = MessageDialogBuilder.yesNo("Merge SDKs", msg).yesText("Copy").noText("Do not copy").show();
        if (result == Messages.YES) {
            new Task.Backgroundable(null, "Merging Android SDKs", false) {
                @Override//www .j  a  v a 2  s  . co m
                public void run(@NotNull ProgressIndicator indicator) {
                    SdkMerger.mergeSdks(sourceSdk, destSdk, indicator);
                }
            }.queue();
        }
    }
}