Search in sources :

Example 6 with AndroidFacet

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

the class NlProperties method getProperties.

@NotNull
public Table<String, String, NlPropertyItem> getProperties(@NotNull List<NlComponent> components) {
    AndroidFacet facet = getFacet(components);
    if (facet == null) {
        return ImmutableTable.of();
    }
    GradleDependencyManager dependencyManager = GradleDependencyManager.getInstance(facet.getModule().getProject());
    return getProperties(facet, components, dependencyManager);
}
Also used : GradleDependencyManager(com.android.tools.idea.gradle.dependencies.GradleDependencyManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with AndroidFacet

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

the class NlPreviewImagePanel method setDesignSurface.

public void setDesignSurface(@Nullable DesignSurface designSurface) {
    Module oldModule = null;
    Configuration oldConfiguration = myDesignSurface != null ? myDesignSurface.getConfiguration() : null;
    if (oldConfiguration != null) {
        oldModule = oldConfiguration.getModule();
        oldConfiguration.removeListener(myConfigurationListener);
    }
    if (myDesignSurface != null) {
        myDesignSurface.removePanZoomListener(myZoomListener);
    }
    myDesignSurface = designSurface;
    Module newModule = null;
    Configuration newConfiguration = myDesignSurface != null ? myDesignSurface.getConfiguration() : null;
    if (newConfiguration != null) {
        newModule = newConfiguration.getModule();
        newConfiguration.addListener(myConfigurationListener);
    }
    if (myDesignSurface != null) {
        myDesignSurface.addPanZoomListener(myZoomListener);
    }
    if (newModule != oldModule) {
        ResourceNotificationManager manager = ResourceNotificationManager.getInstance(myDependencyManager.getProject());
        AndroidFacet oldFacet = oldModule != null ? AndroidFacet.getInstance(oldModule) : null;
        if (oldFacet != null) {
            manager.removeListener(myResourceChangeListener, oldFacet, null, null);
        }
        AndroidFacet newFacet = newModule != null ? AndroidFacet.getInstance(newModule) : null;
        if (newFacet != null) {
            manager.addListener(myResourceChangeListener, newFacet, null, null);
        }
    }
    myImage = null;
    myPreviewGenerationDone = false;
    setTransferHandler(designSurface != null ? new ItemTransferHandler(myDesignSurface, this::getItem, myIconPreviewFactory) : null);
    invalidateUI();
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) ResourceNotificationManager(com.android.tools.idea.res.ResourceNotificationManager) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 8 with AndroidFacet

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

the class NlOldPalettePanel method setToolContext.

@Override
public void setToolContext(@Nullable DesignSurface designSurface) {
    Module prevModule = null;
    if (myConfiguration != null) {
        prevModule = myConfiguration.getModule();
        myConfiguration.removeListener(this);
    }
    Module newModule = null;
    myDesignSurface = designSurface != null && designSurface.getLayoutType().isSupportedByDesigner() ? designSurface : null;
    if (myDesignSurface != null) {
        updateConfiguration();
        if (myConfiguration != null) {
            newModule = myConfiguration.getModule();
            myConfiguration.addListener(this);
        }
        initItems();
        checkForNewMissingDependencies();
        repaint();
    }
    if (prevModule != newModule) {
        if (prevModule != null) {
            AndroidFacet facet = AndroidFacet.getInstance(prevModule);
            if (facet != null) {
                ResourceNotificationManager manager = ResourceNotificationManager.getInstance(myProject);
                manager.removeListener(this, facet, null, null);
            }
        }
        if (newModule != null) {
            AndroidFacet facet = AndroidFacet.getInstance(newModule);
            if (facet != null) {
                ResourceNotificationManager manager = ResourceNotificationManager.getInstance(myProject);
                manager.addListener(this, facet, null, null);
            }
            myIconFactory.dropCache();
        }
    }
}
Also used : ResourceNotificationManager(com.android.tools.idea.res.ResourceNotificationManager) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 9 with AndroidFacet

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

the class IconPreviewFactory method getRenderTask.

@Nullable
private RenderTask getRenderTask(Configuration configuration) {
    if (myRenderTask == null || myRenderTask.getModule() != configuration.getModule()) {
        if (myRenderTask != null) {
            myRenderTask.dispose();
        }
        AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
        if (facet == null) {
            return null;
        }
        RenderService renderService = RenderService.get(facet);
        RenderLogger logger = renderService.createLogger();
        myRenderTask = renderService.createTask(null, configuration, logger, null);
    }
    return myRenderTask;
}
Also used : AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with AndroidFacet

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

the class SdkUpdaterConfigPanel method getSdkLocations.

@NotNull
private static Collection<File> getSdkLocations() {
    File androidHome = IdeSdks.getInstance().getAndroidSdkPath();
    if (androidHome != null) {
        return ImmutableList.of(androidHome);
    }
    Set<File> locations = new HashSet<>();
    // Gradle project.
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        try {
            LocalProperties localProperties = new LocalProperties(project);
            File androidSdkPath = localProperties.getAndroidSdkPath();
            if (androidSdkPath != null) {
                locations.add(androidSdkPath);
                continue;
            }
        } catch (IOException ignored) {
            Logger.getInstance(SdkUpdaterConfigPanel.class).info("Unable to read local.properties file from project: " + project.getName(), ignored);
        }
        List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
        for (AndroidFacet facet : facets) {
            AndroidSdkData sdkData = facet.getConfiguration().getAndroidSdk();
            if (sdkData != null) {
                locations.add(sdkData.getLocation());
            }
        }
    }
    return locations;
}
Also used : Project(com.intellij.openapi.project.Project) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) IOException(java.io.IOException) File(java.io.File) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

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