Search in sources :

Example 96 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class GenerateBackupDescriptorFix method isApplicable.

@Override
public boolean isApplicable(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.ContextType contextType) {
    AndroidFacet facet = AndroidFacet.getInstance(startElement);
    AppResourceRepository appResources = facet == null ? null : facet.getAppResources(true);
    return appResources == null || !appResources.getItemsOfType(ResourceType.XML).contains(myUrl.name);
}
Also used : AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 97 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class EmulatorTargetConfigurable method getAvdCompatibilityWarning.

@Nullable
private String getAvdCompatibilityWarning() {
    IdDisplay selectedItem = (IdDisplay) myAvdCombo.getComboBox().getSelectedItem();
    if (selectedItem != null) {
        final String selectedAvdName = selectedItem.getId();
        final Module module = myContext.getModule();
        if (module == null) {
            return null;
        }
        final AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet == null) {
            return null;
        }
        final AvdManager avdManager = facet.getAvdManagerSilently();
        if (avdManager == null) {
            return null;
        }
        final AvdInfo avd = avdManager.getAvd(selectedAvdName, false);
        if (avd == null || avd.getSystemImage() == null) {
            return null;
        }
        AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
        if (platform == null) {
            return null;
        }
        AndroidVersion minSdk = AndroidModuleInfo.get(facet).getRuntimeMinSdkVersion();
        LaunchCompatibility compatibility = LaunchCompatibility.canRunOnAvd(minSdk, platform.getTarget(), avd.getSystemImage());
        if (compatibility.isCompatible() == ThreeState.NO) {
            // todo: provide info about current module configuration
            return String.format("'%1$s' may be incompatible with your configuration (%2$s)", selectedAvdName, StringUtil.notNullize(compatibility.getReason()));
        }
    }
    return null;
}
Also used : IdDisplay(com.android.sdklib.repository.IdDisplay) LaunchCompatibility(com.android.tools.idea.run.LaunchCompatibility) AvdManager(com.android.sdklib.internal.avd.AvdManager) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Module(com.intellij.openapi.module.Module) AndroidVersion(com.android.sdklib.AndroidVersion) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Example 98 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class AvdComboBox method doUpdateAvds.

private void doUpdateAvds() {
    final Module module = getModule();
    if (module == null || module.isDisposed()) {
        return;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    final IdDisplay[] newAvds;
    if (facet != null) {
        final Set<String> filteringSet = new HashSet<String>();
        if (myShowNotLaunchedOnly) {
            final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(facet.getModule().getProject());
            if (debugBridge != null) {
                for (IDevice device : debugBridge.getDevices()) {
                    final String avdName = device.getAvdName();
                    if (avdName != null && avdName.length() > 0) {
                        filteringSet.add(avdName);
                    }
                }
            }
        }
        final List<IdDisplay> newAvdList = new ArrayList<IdDisplay>();
        if (myAddEmptyElement) {
            newAvdList.add(IdDisplay.create("", ""));
        }
        for (AvdInfo avd : facet.getAllAvds()) {
            String displayName = avd.getProperties().get(AvdManager.AVD_INI_DISPLAY_NAME);
            final String avdName = displayName == null || displayName.isEmpty() ? avd.getName() : displayName;
            if (!filteringSet.contains(avdName)) {
                newAvdList.add(IdDisplay.create(avd.getName(), avdName));
            }
        }
        newAvds = ArrayUtil.toObjectArray(newAvdList, IdDisplay.class);
    } else {
        newAvds = new IdDisplay[0];
    }
    if (!Arrays.equals(myOldAvds, newAvds)) {
        myOldAvds = newAvds;
        final Object selected = getComboBox().getSelectedItem();
        getComboBox().setModel(new DefaultComboBoxModel(newAvds));
        getComboBox().setSelectedItem(selected);
    }
}
Also used : ArrayList(java.util.ArrayList) IDevice(com.android.ddmlib.IDevice) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) IdDisplay(com.android.sdklib.repository.IdDisplay) Module(com.intellij.openapi.module.Module) HashSet(com.intellij.util.containers.HashSet) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 99 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class CreateResourceDialogUtils method getResourceDirectory.

@Nullable
public static PsiDirectory getResourceDirectory(@Nullable SourceProvider sourceProvider, @NotNull Module module, boolean create) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    if (sourceProvider != null) {
        final PsiManager manager = PsiManager.getInstance(module.getProject());
        for (final File file : sourceProvider.getResDirectories()) {
            if (create && !file.exists()) {
                PsiDirectory dir = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {

                    @Override
                    public PsiDirectory compute() {
                        return DirectoryUtil.mkdirs(manager, FileUtil.toSystemIndependentName(file.getPath()));
                    }
                });
                if (dir != null) {
                    return dir;
                }
            } else {
                VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
                if (virtualFile != null) {
                    PsiDirectory dir = manager.findDirectory(virtualFile);
                    if (dir != null) {
                        return dir;
                    }
                }
            }
        }
    }
    // Otherwise use the main source set:
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet != null) {
        VirtualFile res = facet.getPrimaryResourceDir();
        if (res != null) {
            return PsiManager.getInstance(module.getProject()).findDirectory(res);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Example 100 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class AndroidLintExternalAnnotator method collectInformation.

@Override
public State collectInformation(@NotNull PsiFile file) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module == null) {
        return null;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null && !LintIdeProject.hasAndroidModule(module.getProject())) {
        return null;
    }
    final VirtualFile vFile = file.getVirtualFile();
    if (vFile == null) {
        return null;
    }
    final FileType fileType = file.getFileType();
    if (fileType == StdFileTypes.XML) {
        if (facet == null || facet.getLocalResourceManager().getFileResourceFolderType(file) == null && !ANDROID_MANIFEST_XML.equals(vFile.getName())) {
            return null;
        }
    } else if (fileType == FileTypes.PLAIN_TEXT) {
        if (!AndroidCommonUtils.PROGUARD_CFG_FILE_NAME.equals(file.getName()) && !AndroidCompileUtil.OLD_PROGUARD_CFG_FILE_NAME.equals(file.getName())) {
            return null;
        }
    } else if (fileType == GroovyFileType.GROOVY_FILE_TYPE) {
        if (!SdkUtils.endsWithIgnoreCase(file.getName(), DOT_GRADLE)) {
            return null;
        }
        // Ensure that we're listening to the PSI structure for Gradle file edit notifications
        Project project = file.getProject();
        if (AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
            PsiProjectListener.getInstance(project);
        }
    } else if (fileType != StdFileTypes.JAVA && fileType != StdFileTypes.PROPERTIES) {
        return null;
    }
    final List<Issue> issues = getIssuesFromInspections(file.getProject(), file);
    if (issues.size() == 0) {
        return null;
    }
    return new State(module, vFile, file.getText(), issues);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Issue(com.android.tools.lint.detector.api.Issue) GroovyFileType(org.jetbrains.plugins.groovy.GroovyFileType) FileType(com.intellij.openapi.fileTypes.FileType) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

AndroidFacet (org.jetbrains.android.facet.AndroidFacet)299 Module (com.intellij.openapi.module.Module)122 VirtualFile (com.intellij.openapi.vfs.VirtualFile)73 NotNull (org.jetbrains.annotations.NotNull)61 Nullable (org.jetbrains.annotations.Nullable)51 Project (com.intellij.openapi.project.Project)39 File (java.io.File)29 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)28 PsiFile (com.intellij.psi.PsiFile)24 XmlFile (com.intellij.psi.xml.XmlFile)20 PsiElement (com.intellij.psi.PsiElement)17 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)16 XmlTag (com.intellij.psi.xml.XmlTag)16 ArrayList (java.util.ArrayList)16 Manifest (org.jetbrains.android.dom.manifest.Manifest)14 IAndroidTarget (com.android.sdklib.IAndroidTarget)13 ResourceFolderType (com.android.resources.ResourceFolderType)11 Configuration (com.android.tools.idea.configurations.Configuration)10 PsiClass (com.intellij.psi.PsiClass)10 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)10