Search in sources :

Example 61 with AndroidFacet

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

the class StyleItemConverter method getConverter.

@Override
public Converter getConverter(@NotNull GenericDomValue element) {
    StyleItem item = (StyleItem) element;
    String name = item.getName().getValue();
    if (name != null) {
        String[] strs = name.split(":");
        if (strs.length == 1 || strs.length == 2) {
            AndroidFacet facet = AndroidFacet.getInstance(element);
            if (facet != null) {
                String namespacePrefix = strs.length == 2 ? strs[0] : null;
                String localName = strs[strs.length - 1];
                return findConverterForAttribute(namespacePrefix, localName, facet, element);
            }
        }
    }
    return null;
}
Also used : StyleItem(org.jetbrains.android.dom.resources.StyleItem) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 62 with AndroidFacet

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

the class TargetApiConverter method getHighestKnownApi.

private static int getHighestKnownApi(@NotNull ConvertContext context) {
    Module module = context.getModule();
    if (module == null) {
        return HIGHEST_KNOWN_API;
    }
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        return HIGHEST_KNOWN_API;
    }
    IAndroidTarget apiTarget = facet.getConfigurationManager().getHighestApiTarget();
    if (apiTarget == null) {
        return HIGHEST_KNOWN_API;
    }
    return Math.max(apiTarget.getVersion().getApiLevel(), HIGHEST_KNOWN_API);
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 63 with AndroidFacet

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

the class AndroidUtils method getDepLibsPackages.

@NotNull
public static Set<String> getDepLibsPackages(Module module) {
    final Set<String> result = new HashSet<>();
    final HashSet<Module> visited = new HashSet<>();
    if (visited.add(module)) {
        for (AndroidFacet depFacet : getAllAndroidDependencies(module, true)) {
            final Manifest manifest = depFacet.getManifest();
            if (manifest != null) {
                String aPackage = manifest.getPackage().getValue();
                if (aPackage != null) {
                    result.add(aPackage);
                }
            }
        }
    }
    return result;
}
Also used : Module(com.intellij.openapi.module.Module) Manifest(org.jetbrains.android.dom.manifest.Manifest) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with AndroidFacet

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

the class AndroidUtils method addAndroidFacet.

@NotNull
public static AndroidFacet addAndroidFacet(final Module module, @NotNull VirtualFile contentRoot, boolean library) {
    final FacetManager facetManager = FacetManager.getInstance(module);
    ModifiableFacetModel model = facetManager.createModifiableModel();
    AndroidFacet facet = model.getFacetByType(AndroidFacet.ID);
    if (facet == null) {
        facet = facetManager.createFacet(AndroidFacet.getFacetType(), "Android", null);
        AndroidFacetConfiguration configuration = facet.getConfiguration();
        configuration.init(module, contentRoot);
        if (library) {
            facet.setProjectType(PROJECT_TYPE_LIBRARY);
        }
        model.addFacet(facet);
    }
    model.commit();
    return facet;
}
Also used : AndroidFacetConfiguration(org.jetbrains.android.facet.AndroidFacetConfiguration) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) ProjectFacetManager(com.intellij.facet.ProjectFacetManager) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with AndroidFacet

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

the class ThemeEditorStyle method setValue.

/**
   * Sets the value of given attribute in all possible folders where this style is defined. If attribute or value can be used from certain API level,
   * folders below that level won't be modified, instead new folder with certain API will be created.
   * Note: {@link LocalResourceRepository}'s won't get updated immediately
   *
   * @param attribute the style attribute name
   * @param value     the style attribute value
   */
public void setValue(@NotNull final String attribute, @NotNull final String value) {
    if (!isProjectStyle()) {
        throw new UnsupportedOperationException("Non project styles can not be modified");
    }
    final Project project = myManager.getProject();
    int maxApi = Math.max(ResolutionUtils.getOriginalApiLevel(value, myManager.getProject()), ResolutionUtils.getOriginalApiLevel(attribute, project));
    int minSdk = ThemeEditorUtils.getMinApiLevel(myManager.getModule());
    // When api level of both attribute and value is not greater that Minimum SDK,
    // we should modify every FolderConfiguration, thus we set desiredApi to -1
    final int desiredApi = (maxApi <= minSdk) ? -1 : maxApi;
    new WriteCommandAction.Simple(project, "Setting value of " + attribute) {

        @Override
        protected void run() {
            // Makes the command global even if only one xml file is modified
            // That way, the Undo is always available from the theme editor
            CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
            Collection<FolderConfiguration> toBeCopied = findToBeCopied(desiredApi);
            for (FolderConfiguration configuration : toBeCopied) {
                XmlTag styleTag = findXmlTagFromConfiguration(configuration);
                assert styleTag != null;
                ThemeEditorUtils.copyTheme(desiredApi, styleTag);
            }
            if (!toBeCopied.isEmpty()) {
                // We need to refreshResource, to get all copied styles
                // Otherwise, LocalResourceRepositories won't get updated, so we won't get copied styles
                AndroidFacet facet = AndroidFacet.getInstance(myManager.getModule());
                if (facet != null) {
                    facet.refreshResources();
                    // This is because the ResourceFolderRepository may initialize through the file instead of Psi.
                    GradleBuildInvoker.saveAllFilesSafely();
                }
            }
            Collection<ResourceItem> styleItems = getStyleResourceItems();
            for (ResourceItem style : styleItems) {
                FolderConfiguration configuration = style.getConfiguration();
                int version = ThemeEditorUtils.getVersionFromConfiguration(configuration);
                // it means than we can modify 'attribute' to value 'value'.
                if (version >= desiredApi) {
                    setValue(configuration, attribute, value);
                }
            }
        }
    }.execute();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) ImmutableCollection(com.google.common.collect.ImmutableCollection) Collection(java.util.Collection) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) ResourceItem(com.android.ide.common.res2.ResourceItem) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) XmlTag(com.intellij.psi.xml.XmlTag)

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