use of com.android.ide.common.rendering.api.ItemResourceValue in project android by JetBrains.
the class ConfiguredThemeEditorStyle method getConfiguredValues.
/**
* Returns all the style attributes and its values. For each attribute, multiple {@link ConfiguredElement} can be returned
* representing the multiple values in different configurations for each item.
* TODO: needs to be deleted, as we don't use this method except tests
*/
@NotNull
public ImmutableCollection<ConfiguredElement<ItemResourceValue>> getConfiguredValues() {
// Get a list of all the items indexed by the item name. Each item contains a list of the
// possible values in this theme in different configurations.
//
// If item1 has multiple values in different configurations, there will be an
// item1 = {folderConfiguration1 -> value1, folderConfiguration2 -> value2}
final ImmutableList.Builder<ConfiguredElement<ItemResourceValue>> itemResourceValues = ImmutableList.builder();
if (isFramework()) {
assert myConfiguration.getFrameworkResources() != null;
com.android.ide.common.resources.ResourceItem styleItem = myConfiguration.getFrameworkResources().getResourceItem(ResourceType.STYLE, myStyleResourceValue.getName());
// Go over all the files containing the resource.
for (ResourceFile file : styleItem.getSourceFileList()) {
ResourceValue styleResourceValue = file.getValue(ResourceType.STYLE, styleItem.getName());
FolderConfiguration folderConfiguration = file.getConfiguration();
if (styleResourceValue instanceof StyleResourceValue) {
for (final ItemResourceValue value : ((StyleResourceValue) styleResourceValue).getValues()) {
itemResourceValues.add(ConfiguredElement.create(folderConfiguration, value));
}
}
}
} else {
for (ResourceItem styleDefinition : getStyleResourceItems()) {
ResourceValue styleResourceValue = styleDefinition.getResourceValue(isFramework());
FolderConfiguration folderConfiguration = styleDefinition.getConfiguration();
if (styleResourceValue instanceof StyleResourceValue) {
for (final ItemResourceValue value : ((StyleResourceValue) styleResourceValue).getValues()) {
// We use the qualified name since apps and libraries can use the same attribute name twice with and without "android:"
itemResourceValues.add(ConfiguredElement.create(folderConfiguration, value));
}
}
}
}
return itemResourceValues.build();
}
use of com.android.ide.common.rendering.api.ItemResourceValue in project android by JetBrains.
the class ChooseResourceDialog method selectResourceValue.
private void selectResourceValue(@Nullable ResourceValue resValue) {
// initial selection
if (resValue != null) {
ResourcePanel panel = getSelectedPanel();
if (panel.select(resValue)) {
return;
}
// Selection not found in the current panel: switch tab to show it
ResourceType type;
if (resValue instanceof ItemResourceValue) {
// type is always null for ItemResourceValue
type = ResolutionUtils.getAttrType((ItemResourceValue) resValue, myConfiguration);
} else {
type = resValue.getResourceType();
}
// panel is null if the reference is incorrect, e.g. "@sdfgsdfgs" (user error).
if (type != null) {
panel = getPanel(myTabbedPane, type);
if (panel != null) {
if (myTabbedPane != null) {
myTabbedPane.setSelectedComponent(panel.myComponent.getParent());
}
if (!panel.select(resValue) && type == ResourceType.COLOR) {
// You might have selected a private framework color; we *can* edit these
panel.showPreview(null, true);
}
}
}
}
}
use of com.android.ide.common.rendering.api.ItemResourceValue in project android by JetBrains.
the class ThemeAttributeResolverTest method testResolveAllVersion.
/**
* Tests {@link ThemeAttributeResolver#resolveAll(ConfiguredThemeEditorStyle, ThemeResolver)}
*/
public void testResolveAllVersion() {
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-v13", "values-v16"));
createNewStyle(resourceDir, "ThemeB", "ThemeA", "blue", Lists.newArrayList("values-v12"));
createNewStyle(resourceDir, "ThemeB", "ThemeA", null, Lists.newArrayList("values-v15"));
// 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("-v16:red", "-v15:red", "-v14:blue");
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 EditedStyleItemTest method testValueSetters.
public void testValueSetters() {
// Do a simple instantiation and check that the setters update the right value
VirtualFile myLayout = myFixture.copyFileToProject("xmlpull/layout.xml", "res/layout/layout1.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myLayout);
// We just get a theme that we use as fake source to pass to the ConfiguredItemResourceValue constructor
ConfiguredThemeEditorStyle fakeTheme = ResolutionUtils.getStyle(configuration, "android:Theme", null);
assertNotNull(fakeTheme);
//noinspection ConstantConditions
List<ConfiguredElement<ItemResourceValue>> items = ImmutableList.of(ConfiguredElement.create(FolderConfiguration.getConfigForFolder("values-v21"), new ItemResourceValue("attribute", false, "otherValue", false, null)));
EditedStyleItem editedStyleItem = new EditedStyleItem(ConfiguredElement.create(new FolderConfiguration(), new ItemResourceValue("attribute", false, "selectedValue", false, null)), items, fakeTheme);
assertEquals("selectedValue", editedStyleItem.getValue());
assertEquals("selectedValue", editedStyleItem.getSelectedValue().getValue());
assertEquals(1, editedStyleItem.getNonSelectedItemResourceValues().size());
ConfiguredElement<ItemResourceValue> notSelectedItem = editedStyleItem.getNonSelectedItemResourceValues().iterator().next();
assertEquals("otherValue", notSelectedItem.myValue.getValue());
}
use of com.android.ide.common.rendering.api.ItemResourceValue in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method testSetValueMinSdk.
/**
* Tests setValue method for an attribute having api level below than Minimum Sdk
* Tests following cases:
* values, values-v17, values-v19, values-v22
* setValue("android:colorBackgroundCacheHint", "#000000");
*/
public void testSetValueMinSdk() {
VirtualFile file = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_3.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_3.xml", "res/values-v17/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_4.xml", "res/values-v19/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_3.xml", "res/values-v22/styles.xml");
ItemResourceValue item = new ItemResourceValue("colorBackgroundCacheHint", true, "#000000", false, null);
checkSetValue(file, item, "", "-v17", "-v19", "-v22");
}
Aggregations