use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.
the class ThemeAttributeResolver method resolveAll.
@NotNull
private List<EditedStyleItem> resolveAll() {
ThemeEditorStyle theme = new ThemeEditorStyle(myManager, myStyle.getQualifiedName());
for (FolderConfiguration folder : theme.getFolders()) {
resolveFromInheritance(myStyle, folder, new RestrictedConfiguration(), new HashSet<String>());
}
List<EditedStyleItem> result = Lists.newArrayList();
FolderConfiguration configuration = myStyle.getConfiguration().getFullConfig();
for (String key : myItemValueMap.keySet()) {
Collection<ConfiguredElement<ItemResourceValue>> itemValues = myItemValueMap.get(key);
final ConfiguredElement<ItemResourceValue> selectedValue = (ConfiguredElement<ItemResourceValue>) configuration.findMatchingConfigurable(Lists.<Configurable>newArrayList(itemValues));
if (selectedValue == null) {
// TODO: there is NO value for this attribute in the current config,so instead we need to show "no value for current device"
result.add(new EditedStyleItem(itemValues.iterator().next(), itemValues, myStyle));
} else {
itemValues.remove(selectedValue);
assert !itemValues.contains(selectedValue);
result.add(new EditedStyleItem(selectedValue, itemValues, myStyle));
}
}
return result;
}
use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.
the class AttributesGrouper method generateLabelsForType.
@NotNull
private static List<TableLabel> generateLabelsForType(@NotNull final List<EditedStyleItem> source, @NotNull final List<EditedStyleItem> sink) {
// ArrayListMultimap is used to ensure the elements stay sorted
final Multimap<Group, EditedStyleItem> classes = ArrayListMultimap.create();
for (final EditedStyleItem item : source) {
final String name = item.getName();
classes.put(Group.getGroupFromName(name), item);
}
final List<TableLabel> labels = new ArrayList<TableLabel>();
int offset = 0;
for (Group group : Group.values()) {
Collection<EditedStyleItem> elements = classes.get(group);
boolean addHeader = !elements.isEmpty();
if (addHeader && group == Group.OTHER) {
// Adding "Everything else" label only in case when there are at least one other label,
// because having "Everything else" as the only label present looks quite silly
addHeader = offset != 0;
}
if (addHeader) {
labels.add(new TableLabel(group.name, offset));
}
sink.addAll(elements);
offset += elements.size();
}
return labels;
}
use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem 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.tools.idea.editors.theme.datamodels.EditedStyleItem 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.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.
the class ThemeEditorUtilsTest method testGetDisplayHtml.
public void testGetDisplayHtml() {
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);
Collection<EditedStyleItem> values = ThemeEditorTestUtils.getStyleLocalValues(theme);
assertEquals(7, values.size());
for (EditedStyleItem item : values) {
String displayHtml = ThemeEditorUtils.getDisplayHtml(item);
if ("myDeprecated".equals(item.getName())) {
assertEquals("<html><body><strike>myDeprecated</strike></body></html>", displayHtml);
} else {
assertEquals(item.getName(), displayHtml);
}
}
}
Aggregations