use of com.android.ide.common.rendering.api.ItemResourceValue in project android by JetBrains.
the class ChooseResourceDialog method initializeThemeAttributes.
private static MultiMap<ResourceType, String> initializeThemeAttributes(@NotNull Configuration configuration, @NotNull ResourceResolver resolver) {
MultiMap<ResourceType, String> attrs = new MultiMap<>();
String themeName = configuration.getTheme();
assert themeName != null;
for (ItemResourceValue item : ResolutionUtils.getThemeAttributes(resolver, themeName)) {
ResourceType type = ResolutionUtils.getAttrType(item, configuration);
if (type != null) {
attrs.putValue(type, ResolutionUtils.getQualifiedItemName(item));
}
}
return attrs;
}
use of com.android.ide.common.rendering.api.ItemResourceValue in project android by JetBrains.
the class ThemeAttributeResolverTest method testResolveAllEnum.
/**
* Tests {@link ThemeAttributeResolver#resolveAll(ConfiguredThemeEditorStyle, ThemeResolver)}
*/
public void testResolveAllEnum() {
VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles.xml", "res/values/styles.xml");
VirtualFile resourceDir = myFile.getParent().getParent();
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
createNewStyle(resourceDir, "ThemeA", "android:Theme", "red", Lists.newArrayList("values-port", "values-square", "values-land"));
createNewStyle(resourceDir, "ThemeB", "ThemeA", null, Lists.newArrayList("values", "values-port"));
// ResourceFolderRepository needs to rescan the files to pick up the changes.
UIUtil.dispatchAllInvocationEvents();
ThemeResolver themeResolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle style = themeResolver.getTheme("ThemeB");
assertNotNull(style);
Set<String> answer = Sets.newHashSet("-port:red", "-land:red", "-square:red");
List<EditedStyleItem> items = ThemeAttributeResolver.resolveAll(style, configuration.getConfigurationManager());
boolean foundColorPrimary = false;
for (EditedStyleItem item : items) {
if (item.getName().equals("colorPrimary") && item.getAttrGroup().equals("Other non-theme attributes.")) {
foundColorPrimary = true;
assertEquals(answer.size(), item.getAllConfiguredItems().size());
for (ConfiguredElement<ItemResourceValue> value : item.getAllConfiguredItems()) {
assertTrue(answer.contains(value.getConfiguration().getUniqueKey() + ":" + value.getElement().getValue()));
}
}
}
assertTrue(foundColorPrimary);
}
use of com.android.ide.common.rendering.api.ItemResourceValue in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method testSetValueAndroidAttributeValue.
/**
* Tests setValue method for following cases:
* values, values-v21, values-night, value-port, values-port-v21
* setValue("android:colorFocusedHighlight", "?android:attr/colorAccent"), colorAccent - v21, colorFocusedHighlight - v14
*/
public void testSetValueAndroidAttributeValue() {
VirtualFile file = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_3.xml", "res/values-v21/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-night/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-port/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-port-v21/styles.xml");
ItemResourceValue item = new ItemResourceValue("colorAccent", true, "?android:attr/colorAccent", false, null);
checkSetValue(file, item, "-night-v21", "-v21", "-port-v21");
}
use of com.android.ide.common.rendering.api.ItemResourceValue in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method testHasItem.
public void testHasItem() {
VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_1.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/attrs.xml", "res/values/attrs.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
ThemeResolver themeResolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle theme = themeResolver.getTheme("AppTheme");
assertNotNull(theme);
ConfiguredThemeEditorStyle parent = theme.getParent();
assertNotNull(parent);
FolderConfiguration defaultConfig = new FolderConfiguration();
ConfiguredElement<ItemResourceValue> hasItem = ConfiguredElement.create(defaultConfig, new ItemResourceValue("myColor", false, "?android:attr/colorBackground", false, null));
ConfiguredElement<ItemResourceValue> hasNotItem = ConfiguredElement.create(defaultConfig, new ItemResourceValue("myHasNot", false, "?android:attr/colorBackground", false, null));
ConfiguredElement<ItemResourceValue> hasInParent = ConfiguredElement.create(defaultConfig, new ItemResourceValue("editTextStyle", true, "?android:attr/colorBackground", true, null));
assertTrue(theme.hasItem(new EditedStyleItem(hasItem, theme)));
assertFalse(theme.hasItem(new EditedStyleItem(hasNotItem, theme)));
assertTrue(theme.getParent().hasItem(new EditedStyleItem(hasInParent, parent)));
assertFalse(theme.hasItem(new EditedStyleItem(hasInParent, parent)));
}
use of com.android.ide.common.rendering.api.ItemResourceValue in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method testSetValue.
/**
* Tests setValue method for following cases:
* values, values-v21, values-night, value-port, values-port-v21
* setValue("colorAccent", "#000000")
*/
public void testSetValue() {
VirtualFile file = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-v21/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-night/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-port/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-port-v21/styles.xml");
ItemResourceValue item = new ItemResourceValue("colorAccent", false, "#000000", false, null);
checkSetValue(file, item, "", "-v21", "-night", "-port", "-port-v21");
}
Aggregations