Search in sources :

Example 1 with LocalResourceRepository

use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.

the class ResourceFoldingBuilder method createdInlinedResource.

private static InlinedResource createdInlinedResource(@NotNull ResourceType type, @NotNull String name, @NotNull PsiElement foldElement) {
    // Not part of a call: just fold the R.string reference itself
    LocalResourceRepository appResources = getAppResources(foldElement);
    if (appResources != null && appResources.hasResourceItem(type, name)) {
        ASTNode node = foldElement.getNode();
        if (node != null) {
            TextRange textRange = foldElement.getTextRange();
            HashSet<Object> dependencies = new HashSet<Object>();
            dependencies.add(foldElement);
            FoldingDescriptor descriptor = new FoldingDescriptor(node, textRange, null, dependencies);
            InlinedResource inlinedResource = new InlinedResource(type, name, appResources, descriptor, foldElement);
            dependencies.add(inlinedResource);
            return inlinedResource;
        }
    }
    return NONE;
}
Also used : FoldingDescriptor(com.intellij.lang.folding.FoldingDescriptor) LocalResourceRepository(com.android.tools.idea.res.LocalResourceRepository) ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) HashSet(java.util.HashSet)

Example 2 with LocalResourceRepository

use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.

the class LintIdeViewTypeDetector method getViewTags.

@Nullable
@Override
protected Collection<String> getViewTags(@NonNull Context context, @NonNull ResourceItem item) {
    AbstractResourceRepository projectResources = context.getClient().getProjectResources(context.getMainProject(), true);
    assert projectResources instanceof LocalResourceRepository : projectResources;
    LocalResourceRepository repository = (LocalResourceRepository) projectResources;
    String viewTag = repository.getViewTag(item);
    if (viewTag != null) {
        return Collections.singleton(viewTag);
    }
    return super.getViewTags(context, item);
}
Also used : AbstractResourceRepository(com.android.ide.common.res2.AbstractResourceRepository) LocalResourceRepository(com.android.tools.idea.res.LocalResourceRepository) Nullable(com.android.annotations.Nullable)

Example 3 with LocalResourceRepository

use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.

the class Configuration method create.

/**
   * Creates a configuration suitable for the given file
   *
   * @param base the base configuration to base the file configuration off of
   * @param file the file to look up a configuration for
   * @return a suitable configuration
   */
@NotNull
public static Configuration create(@NotNull Configuration base, @NotNull VirtualFile file) {
    // TODO: Figure out whether we need this, or if it should be replaced by
    // a call to ConfigurationManager#createSimilar()
    Configuration configuration = base.clone();
    LocalResourceRepository resources = AppResourceRepository.getAppResources(base.getModule(), true);
    ConfigurationMatcher matcher = new ConfigurationMatcher(configuration, resources, file);
    configuration.getEditedConfig().set(FolderConfiguration.getConfigForFolder(file.getParent().getName()));
    matcher.adaptConfigSelection(true);
    return configuration;
}
Also used : LocalResourceRepository(com.android.tools.idea.res.LocalResourceRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with LocalResourceRepository

use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.

the class Configuration method copyCompatible.

/**
   * Copies attributes from the given source configuration into the given destination configuration,
   * as long as the attributes are compatible with the folder of the destination file.
   *
   * @param source the original to copy from
   * @return a new configuration copied from the original
   */
@NotNull
public static Configuration copyCompatible(@NotNull Configuration source, @NotNull Configuration destination) {
    // This method is intended to sync configurations for resource variations
    assert !Comparing.equal(source.myFile, destination.myFile);
    FolderConfiguration editedConfig = destination.getEditedConfig();
    if (editedConfig.getVersionQualifier() == null) {
        // avoid getTarget() since it fetches project state
        destination.myTarget = source.myTarget;
    }
    if (editedConfig.getScreenSizeQualifier() == null) {
        // avoid getDevice() since it fetches project state
        destination.mySpecificDevice = source.mySpecificDevice;
    }
    if (editedConfig.getScreenOrientationQualifier() == null && editedConfig.getSmallestScreenWidthQualifier() == null) {
        destination.myStateName = source.myStateName;
        destination.myState = source.myState;
    }
    if (editedConfig.getLocaleQualifier() == null) {
        // avoid getLocale() since it fetches project state
        destination.myLocale = source.myLocale;
    }
    if (editedConfig.getUiModeQualifier() == null) {
        destination.myUiMode = source.getUiMode();
    }
    if (editedConfig.getNightModeQualifier() == null) {
        destination.myNightMode = source.getNightMode();
    }
    destination.myActivity = source.getActivity();
    destination.myTheme = source.getTheme();
    //destination.myDisplayName = source.getDisplayName();
    LocalResourceRepository resources = AppResourceRepository.getAppResources(source.myManager.getModule(), true);
    ConfigurationMatcher matcher = new ConfigurationMatcher(destination, resources, destination.myFile);
    //if (!matcher.isCurrentFileBestMatchFor(editedConfig)) {
    matcher.adaptConfigSelection(true);
    return destination;
}
Also used : LocalResourceRepository(com.android.tools.idea.res.LocalResourceRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with LocalResourceRepository

use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.

the class ConfigurationManager method getLocales.

@NotNull
public List<Locale> getLocales() {
    // Get locales from modules, but not libraries!
    LocalResourceRepository projectResources = ProjectResourceRepository.getProjectResources(myModule, true);
    assert projectResources != null;
    if (projectResources.getModificationCount() != myLocaleCacheStamp) {
        myLocales = null;
    }
    if (myLocales == null) {
        List<Locale> locales = new ArrayList<Locale>();
        for (LocaleQualifier locale : projectResources.getLocales()) {
            locales.add(Locale.create(locale));
        }
        myLocales = locales;
        myLocaleCacheStamp = projectResources.getModificationCount();
    }
    return myLocales;
}
Also used : Locale(com.android.tools.idea.rendering.Locale) LocalResourceRepository(com.android.tools.idea.res.LocalResourceRepository) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LocalResourceRepository (com.android.tools.idea.res.LocalResourceRepository)25 NotNull (org.jetbrains.annotations.NotNull)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 Nullable (org.jetbrains.annotations.Nullable)6 ResourceItem (com.android.ide.common.res2.ResourceItem)5 Module (com.intellij.openapi.module.Module)5 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)5 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)4 DataBindingInfo (com.android.tools.idea.res.DataBindingInfo)4 ResourceRepository (com.android.ide.common.resources.ResourceRepository)3 LocaleQualifier (com.android.ide.common.resources.configuration.LocaleQualifier)3 Locale (com.android.tools.idea.rendering.Locale)3 XmlTag (com.intellij.psi.xml.XmlTag)3 ResourceResolver (com.android.ide.common.resources.ResourceResolver)2 ResourceType (com.android.resources.ResourceType)2 State (com.android.sdklib.devices.State)2 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 PsiFile (com.intellij.psi.PsiFile)2 ArrayList (java.util.ArrayList)2