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);
}
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;
}
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));
}
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));
}
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;
}
Aggregations