Search in sources :

Example 11 with ResourceResolver

use of com.android.ide.common.resources.ResourceResolver in project android by JetBrains.

the class ResourceDrawablePanel method select.

public void select(@NotNull ResourceChooserItem item) {
    myItem = item;
    List<String> qualifiers = item.getQualifiers();
    //noinspection unchecked
    myQualifierCombo.setModel(new DefaultComboBoxModel(ArrayUtil.toStringArray(qualifiers)));
    // Select the current item's qualifiers!
    //noinspection UnnecessaryLocalVariable
    String currentQualifier = DEFAULT_FOLDER_NAME;
    ResourceResolver resourceResolver = myDialog.getConfiguration().getResourceResolver();
    if (resourceResolver != null) {
        ResourceValue resourceValue = resourceResolver.resolveResValue(item.getResourceValue());
        if (resourceValue != null) {
            String value = resourceValue.getValue();
            if (value != null) {
                File rendered = new File(value);
                if (rendered.exists()) {
                    File folder = rendered.getParentFile();
                    if (folder != null) {
                        String folderName = folder.getName();
                        FolderConfiguration folderConfig = FolderConfiguration.getConfigForFolder(folderName);
                        if (folderConfig != null) {
                            int index = folderName.indexOf('-');
                            if (index != -1) {
                                currentQualifier = folderName.substring(index + 1);
                            }
                        }
                    }
                }
            }
        }
    }
    try {
        myIgnoreSelection = true;
        myQualifierCombo.setSelectedItem(currentQualifier);
    } finally {
        myIgnoreSelection = false;
    }
    show(item);
}
Also used : ResourceResolver(com.android.ide.common.resources.ResourceResolver) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) File(java.io.File)

Example 12 with ResourceResolver

use of com.android.ide.common.resources.ResourceResolver in project android by JetBrains.

the class ChooseResourceDialog method getResourceResolver.

@NotNull
private ResourceResolver getResourceResolver() {
    Configuration config = getConfiguration();
    ResourceResolver resolver = config.getResourceResolver();
    assert resolver != null;
    return resolver;
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) ResourceResolver(com.android.ide.common.resources.ResourceResolver) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ResourceResolver

use of com.android.ide.common.resources.ResourceResolver in project android by JetBrains.

the class ThemeEditorComponentTest method testGetGoodContrastPreviewBackground.

public void testGetGoodContrastPreviewBackground() {
    VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_background.xml", "res/values/styles.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
    ResourceResolver resourceResolver = configuration.getResourceResolver();
    assertNotNull(resourceResolver);
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle theme1 = themeResolver.getTheme("Theme.Theme1");
    assertNotNull(theme1);
    ConfiguredThemeEditorStyle theme2 = themeResolver.getTheme("Theme.Theme2");
    assertNotNull(theme2);
    ConfiguredThemeEditorStyle theme3 = themeResolver.getTheme("Theme.Theme3");
    assertNotNull(theme3);
    assertEquals(ThemeEditorComponent.ALT_PREVIEW_BACKGROUND, ThemeEditorUtils.getGoodContrastPreviewBackground(theme1, resourceResolver));
    assertEquals(ThemeEditorComponent.PREVIEW_BACKGROUND, ThemeEditorUtils.getGoodContrastPreviewBackground(theme2, resourceResolver));
    assertEquals(ThemeEditorComponent.PREVIEW_BACKGROUND, ThemeEditorUtils.getGoodContrastPreviewBackground(theme3, resourceResolver));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 14 with ResourceResolver

use of com.android.ide.common.resources.ResourceResolver in project android by JetBrains.

the class ResolutionUtilsTest method testGetParentQualifiedName.

/**
   * Tests {@link ResolutionUtils#getParentQualifiedName(StyleResourceValue)}
   */
public void testGetParentQualifiedName() {
    VirtualFile file = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles.xml", "res/values/styles.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(file);
    ResourceResolver resolver = configuration.getResourceResolver();
    assertNotNull(resolver);
    StyleResourceValue style;
    style = resolver.getStyle("Theme", true);
    assertNotNull(style);
    assertEquals(null, ResolutionUtils.getParentQualifiedName(style));
    style = resolver.getStyle("Theme.Holo.Light", true);
    assertNotNull(style);
    assertEquals("android:Theme.Light", ResolutionUtils.getParentQualifiedName(style));
    style = resolver.getStyle("ATheme", false);
    assertNotNull(style);
    assertEquals("android:Theme", ResolutionUtils.getParentQualifiedName(style));
    style = resolver.getStyle("AppTheme", false);
    assertNotNull(style);
    assertEquals("ATheme", ResolutionUtils.getParentQualifiedName(style));
    style = resolver.getStyle("ATheme.Red", false);
    assertNotNull(style);
    assertEquals("ATheme", ResolutionUtils.getParentQualifiedName(style));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) Configuration(com.android.tools.idea.configurations.Configuration) ResourceResolver(com.android.ide.common.resources.ResourceResolver)

Example 15 with ResourceResolver

use of com.android.ide.common.resources.ResourceResolver in project android by JetBrains.

the class ResolutionUtils method getAttrType.

@Nullable
public static /*if we can't work out the type, e.g a 'reference' with a '@null' value or enum*/
ResourceType getAttrType(@NotNull ItemResourceValue item, @NotNull Configuration configuration) {
    ResourceResolver resolver = configuration.getResourceResolver();
    assert resolver != null;
    ResourceValue resolvedValue = resolver.resolveResValue(item);
    ResourceType attrType = resolvedValue.getResourceType();
    if (attrType != null) {
        return attrType;
    } else {
        AttributeDefinition def = getAttributeDefinition(configuration, item);
        if (def != null) {
            for (AttributeFormat attrFormat : def.getFormats()) {
                attrType = AndroidDomUtil.getResourceType(attrFormat);
                if (attrType != null) {
                    return attrType;
                }
            }
        }
    }
    // sometimes we won't find the type of the attr, this means it's either a reference that points to @null, or a enum
    return null;
}
Also used : AttributeFormat(org.jetbrains.android.dom.attrs.AttributeFormat) ResourceResolver(com.android.ide.common.resources.ResourceResolver) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) ResourceType(com.android.resources.ResourceType) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ResourceResolver (com.android.ide.common.resources.ResourceResolver)43 Configuration (com.android.tools.idea.configurations.Configuration)16 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)13 NotNull (org.jetbrains.annotations.NotNull)11 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)8 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)6 Nullable (org.jetbrains.annotations.Nullable)6 SessionParams (com.android.ide.common.rendering.api.SessionParams)5 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)5 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)5 Module (com.intellij.openapi.module.Module)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 IAndroidTarget (com.android.sdklib.IAndroidTarget)4 Project (com.intellij.openapi.project.Project)4 ResourceType (com.android.resources.ResourceType)3 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)3 XmlFile (com.intellij.psi.xml.XmlFile)3 ResourceRepository (com.android.ide.common.resources.ResourceRepository)2 Device (com.android.sdklib.devices.Device)2 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)2