Search in sources :

Example 11 with PropertiesComponent

use of com.intellij.ide.util.PropertiesComponent in project android by JetBrains.

the class ScreenshotViewer method doOKAction.

@Override
protected void doOKAction() {
    FileSaverDescriptor descriptor = new FileSaverDescriptor(AndroidBundle.message("android.ddms.screenshot.save.title"), "", SdkConstants.EXT_PNG);
    FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, myProject);
    VirtualFile baseDir = loadScreenshotPath();
    VirtualFileWrapper fileWrapper = saveFileDialog.save(baseDir, getDefaultFileName());
    if (fileWrapper == null) {
        return;
    }
    myScreenshotFile = fileWrapper.getFile();
    try {
        ImageIO.write(myDisplayedImageRef.get(), SdkConstants.EXT_PNG, myScreenshotFile);
    } catch (IOException e) {
        Messages.showErrorDialog(myProject, AndroidBundle.message("android.ddms.screenshot.save.error", e), AndroidBundle.message("android.ddms.actions.screenshot"));
        return;
    }
    VirtualFile virtualFile = fileWrapper.getVirtualFile();
    if (virtualFile != null) {
        PropertiesComponent properties = PropertiesComponent.getInstance(myProject);
        properties.setValue(SCREENSHOT_SAVE_PATH_KEY, virtualFile.getParent().getPath());
    }
    super.doOKAction();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) FileSaverDialog(com.intellij.openapi.fileChooser.FileSaverDialog) IOException(java.io.IOException) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Example 12 with PropertiesComponent

use of com.intellij.ide.util.PropertiesComponent in project android by JetBrains.

the class IdeSdks method getAndroidSdkPath.

/**
   * @return what the IDE is using as the home path for the Android SDK for new projects.
   */
@Nullable
public File getAndroidSdkPath() {
    // We assume that every time new android sdk path is applied, all existing ide android sdks are removed and replaced by newly
    // created ide android sdks for the platforms downloaded for the new android sdk. So, we bring the first ide android sdk configured
    // at the moment and deduce android sdk path from it.
    String sdkHome = null;
    Sdk sdk = getFirstAndroidSdk();
    if (sdk != null) {
        sdkHome = sdk.getHomePath();
    }
    if (sdkHome != null) {
        File candidate = new File(toSystemDependentName(sdkHome));
        // Check if the sdk home is still valid. See https://code.google.com/p/android/issues/detail?id=197401 for more details.
        if (isValidAndroidSdkPath(candidate)) {
            return candidate;
        }
    }
    // There is a possible case that android sdk which path was applied previously (setAndroidSdkPath()) didn't have any
    // platforms downloaded. Hence, no ide android sdk was created and we can't deduce android sdk location from it.
    // Hence, we fallback to the explicitly stored android sdk path here.
    PropertiesComponent component = PropertiesComponent.getInstance(ProjectManager.getInstance().getDefaultProject());
    String sdkPath = component.getValue(ANDROID_SDK_PATH_KEY);
    if (sdkPath != null) {
        File candidate = new File(sdkPath);
        if (isValidAndroidSdkPath(candidate)) {
            return candidate;
        }
    }
    return null;
}
Also used : SdkPaths.validateAndroidSdk(com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk) File(java.io.File) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with PropertiesComponent

use of com.intellij.ide.util.PropertiesComponent in project android by JetBrains.

the class AndroidSdkUtils method setupPlatform.

private static void setupPlatform(@NotNull Module module) {
    String targetHashString = getTargetHashStringFromPropertyFile(module);
    if (targetHashString != null && findAndSetSdkWithHashString(module, targetHashString)) {
        return;
    }
    PropertiesComponent component = PropertiesComponent.getInstance();
    if (component.isValueSet(DEFAULT_PLATFORM_NAME_PROPERTY)) {
        String defaultPlatformName = component.getValue(DEFAULT_PLATFORM_NAME_PROPERTY);
        Sdk defaultLib = ProjectJdkTable.getInstance().findJdk(defaultPlatformName, AndroidSdkType.getInstance().getName());
        if (defaultLib != null && tryToSetAndroidPlatform(module, defaultLib)) {
            return;
        }
    }
    for (Sdk sdk : AndroidSdks.getInstance().getAllAndroidSdks()) {
        AndroidPlatform platform = AndroidPlatform.getInstance(sdk);
        if (platform != null && checkSdkRoots(sdk, platform.getTarget(), false) && tryToSetAndroidPlatform(module, sdk)) {
            component.setValue(DEFAULT_PLATFORM_NAME_PROPERTY, sdk.getName());
            return;
        }
    }
}
Also used : ModuleRootModificationUtil.setModuleSdk(com.intellij.openapi.roots.ModuleRootModificationUtil.setModuleSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 14 with PropertiesComponent

use of com.intellij.ide.util.PropertiesComponent in project android by JetBrains.

the class GradleSignStep method commitForNext.

@Override
protected void commitForNext() throws CommitStepException {
    if (myAndroidModel == null) {
        throw new CommitStepException(AndroidBundle.message("android.apk.sign.gradle.no.model"));
    }
    final String apkFolder = myApkPathField.getText().trim();
    if (apkFolder.isEmpty()) {
        throw new CommitStepException(AndroidBundle.message("android.apk.sign.gradle.missing.destination"));
    }
    File f = new File(apkFolder);
    if (!f.isDirectory() || !f.canWrite()) {
        throw new CommitStepException(AndroidBundle.message("android.apk.sign.gradle.invalid.destination"));
    }
    int[] selectedFlavorIndices = myFlavorsList.getSelectedIndices();
    if (!myFlavorsListModel.isEmpty() && selectedFlavorIndices.length == 0) {
        throw new CommitStepException(AndroidBundle.message("android.apk.sign.gradle.missing.flavors"));
    }
    Object[] selectedFlavors = myFlavorsList.getSelectedValues();
    List<String> flavors = new ArrayList<String>(selectedFlavors.length);
    for (int i = 0; i < selectedFlavors.length; i++) {
        flavors.add((String) selectedFlavors[i]);
    }
    boolean isV1 = myV1JarSignatureCheckBox.isSelected();
    boolean isV2 = myV2FullAPKSignatureCheckBox.isSelected();
    if (myV1JarSignatureCheckBox.isEnabled() && !isV1 && !isV2) {
        throw new CommitStepException(AndroidBundle.message("android.apk.sign.gradle.missing.signature-version"));
    }
    myWizard.setApkPath(apkFolder);
    myWizard.setGradleOptions((String) myBuildTypeCombo.getSelectedItem(), flavors);
    myWizard.setV1Signature(isV1);
    myWizard.setV2Signature(isV2);
    PropertiesComponent properties = PropertiesComponent.getInstance(myWizard.getProject());
    properties.setValue(PROPERTY_APK_PATH, apkFolder);
    properties.setValues(PROPERTY_FLAVORS, ArrayUtil.toStringArray(flavors));
    properties.setValue(PROPERTY_BUILD_TYPE, (String) myBuildTypeCombo.getSelectedItem());
    properties.setValue(PROPERTY_V1_SIGN, myV1JarSignatureCheckBox.isSelected());
    properties.setValue(PROPERTY_V2_SIGN, myV2FullAPKSignatureCheckBox.isSelected());
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.TIntArrayList) File(java.io.File) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 15 with PropertiesComponent

use of com.intellij.ide.util.PropertiesComponent in project android by JetBrains.

the class GradleSignStep method _init.

@Override
public void _init() {
    myAndroidModel = AndroidModuleModel.get(myWizard.getFacet());
    PropertiesComponent properties = PropertiesComponent.getInstance(myWizard.getProject());
    String lastSelectedBuildType = properties.getValue(PROPERTY_BUILD_TYPE);
    myBuildTypeComboModel.removeAllElements();
    Set<String> buildTypes = myAndroidModel == null ? Collections.<String>emptySet() : myAndroidModel.getBuildTypes();
    for (String buildType : buildTypes) {
        myBuildTypeComboModel.addElement(buildType);
        if ((lastSelectedBuildType == null && buildType.equals("release")) || buildType.equals(lastSelectedBuildType)) {
            myBuildTypeComboModel.setSelectedItem(buildType);
        }
    }
    myFlavorsListModel.clear();
    List<String> productFlavors;
    if (myAndroidModel == null || myAndroidModel.getProductFlavors().isEmpty()) {
        productFlavors = Collections.emptyList();
    } else {
        // if there are multiple flavors, we want the merged flavor list
        Set<String> mergedFlavors = Sets.newHashSet();
        for (Variant v : myAndroidModel.getAndroidProject().getVariants()) {
            mergedFlavors.add(ExportSignedPackageWizard.getMergedFlavorName(v));
        }
        productFlavors = Lists.newArrayList(mergedFlavors);
        Collections.sort(productFlavors);
    }
    TIntArrayList lastSelectedIndices = new TIntArrayList(productFlavors.size());
    String[] flavors = properties.getValues(PROPERTY_FLAVORS);
    Set<String> lastSelectedFlavors = flavors == null ? Collections.<String>emptySet() : Sets.newHashSet(flavors);
    for (int i = 0; i < productFlavors.size(); i++) {
        String flavor = productFlavors.get(i);
        myFlavorsListModel.addElement(flavor);
        if (lastSelectedFlavors.contains(flavor)) {
            lastSelectedIndices.add(i);
        }
    }
    myFlavorsList.setSelectedIndices(lastSelectedIndices.toNativeArray());
    String lastApkFolderPath = properties.getValue(PROPERTY_APK_PATH);
    File lastApkFolder;
    if (lastApkFolderPath != null) {
        lastApkFolder = new File(lastApkFolderPath);
    } else {
        if (myAndroidModel == null) {
            lastApkFolder = VfsUtilCore.virtualToIoFile(myWizard.getProject().getBaseDir());
        } else {
            lastApkFolder = myAndroidModel.getRootDirPath();
        }
    }
    myApkPathField.setText(lastApkFolder.getAbsolutePath());
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    myApkPathField.addBrowseFolderListener("Select APK Destination Folder", null, myWizard.getProject(), descriptor);
    GradleVersion modelVersion = null;
    if (myAndroidModel != null) {
        modelVersion = myAndroidModel.getModelVersion();
    }
    boolean enabled = modelVersion != null && modelVersion.compareIgnoringQualifiers(MIN_SIGNATURE_SELECTION_VERSION) >= 0;
    myV1JarSignatureCheckBox.setEnabled(enabled);
    myV1JarSignatureCheckBox.setSelected(properties.getBoolean(PROPERTY_V1_SIGN));
    myV2FullAPKSignatureCheckBox.setEnabled(enabled);
    myV2FullAPKSignatureCheckBox.setSelected(properties.getBoolean(PROPERTY_V2_SIGN));
    // Set HTML label here; the visual editor does not like the "&nbsp;" part so set the text here.
    mySignatureHelpLabel.setText("<html><a href=\"\">Signature&nbsp;Help</a></html>");
    mySignatureHelpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    mySignatureHelpLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                if (desktop.isSupported(Desktop.Action.BROWSE)) {
                    URI uri;
                    try {
                        uri = new URI("http://developer.android.com/about/versions/nougat/android-7.0.html#apk_signature_v2");
                    } catch (URISyntaxException ex) {
                        throw new AssertionError(ex);
                    }
                    try {
                        desktop.browse(uri);
                    } catch (IOException ex) {
                        LOG.error("Failed to open URI '" + uri + "'", ex);
                    }
                }
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) MouseAdapter(java.awt.event.MouseAdapter) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) TIntArrayList(gnu.trove.TIntArrayList) Variant(com.android.builder.model.Variant) GradleVersion(com.android.ide.common.repository.GradleVersion) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) File(java.io.File)

Aggregations

PropertiesComponent (com.intellij.ide.util.PropertiesComponent)53 File (java.io.File)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Project (com.intellij.openapi.project.Project)5 IOException (java.io.IOException)5 NotNull (org.jetbrains.annotations.NotNull)5 ArrayList (java.util.ArrayList)4 SdkPaths.validateAndroidSdk (com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk)2 CommitStepException (com.intellij.ide.wizard.CommitStepException)2 Notification (com.intellij.notification.Notification)2 NotificationListener (com.intellij.notification.NotificationListener)2 TIntArrayList (gnu.trove.TIntArrayList)2 List (java.util.List)2 JDOMException (org.jdom.JDOMException)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 Nullable (org.jetbrains.annotations.Nullable)2 Variant (com.android.builder.model.Variant)1 IDevice (com.android.ddmlib.IDevice)1 GradleVersion (com.android.ide.common.repository.GradleVersion)1 IdDisplay (com.android.sdklib.repository.IdDisplay)1