use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ThemeEditorUtils method getDefaultThemeNames.
@NotNull
public static ImmutableList<String> getDefaultThemeNames(@NotNull ThemeResolver themeResolver) {
Collection<ConfiguredThemeEditorStyle> readOnlyLibThemes = themeResolver.getExternalLibraryThemes();
Collection<ConfiguredThemeEditorStyle> foundThemes = new HashSet<ConfiguredThemeEditorStyle>();
foundThemes.addAll(findThemes(readOnlyLibThemes, DEFAULT_THEMES));
if (foundThemes.isEmpty()) {
Collection<ConfiguredThemeEditorStyle> readOnlyFrameworkThemes = themeResolver.getFrameworkThemes();
foundThemes = new HashSet<ConfiguredThemeEditorStyle>();
foundThemes.addAll(findThemes(readOnlyFrameworkThemes, DEFAULT_THEMES_FALLBACK));
if (foundThemes.isEmpty()) {
foundThemes.addAll(readOnlyLibThemes);
foundThemes.addAll(readOnlyFrameworkThemes);
}
}
Set<String> temporarySet = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
for (ConfiguredThemeEditorStyle theme : foundThemes) {
temporarySet.add(theme.getQualifiedName());
}
return ImmutableList.copyOf(temporarySet);
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ThemeEditorUtils method simplifyThemeName.
/**
* Returns a more user-friendly name of a given theme.
* Aimed at framework themes with names of the form Theme.*.Light.*
* or Theme.*.*
*/
@NotNull
public static String simplifyThemeName(@NotNull ConfiguredThemeEditorStyle theme) {
String result;
String name = theme.getQualifiedName();
String[] pieces = name.split("\\.");
if (pieces.length > 1 && !"Light".equals(pieces[1])) {
result = pieces[1];
} else {
result = "Theme";
}
ConfiguredThemeEditorStyle parent = theme;
while (parent != null) {
if ("Theme.Light".equals(parent.getName())) {
return result + " Light";
} else {
parent = parent.getParent();
}
}
return result + " Dark";
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ThemeEditorUtils method resolveItemFromParents.
/**
* Finds an ItemResourceValue for a given name in a theme inheritance tree
*/
@Nullable
public static /*if there is not an item with that name*/
ItemResourceValue resolveItemFromParents(@NotNull final ConfiguredThemeEditorStyle theme, @NotNull String name, boolean isFrameworkAttr) {
ConfiguredThemeEditorStyle currentTheme = theme;
for (int i = 0; (i < ResourceResolver.MAX_RESOURCE_INDIRECTION) && currentTheme != null; i++) {
ItemResourceValue item = currentTheme.getItem(name, isFrameworkAttr);
if (item != null) {
return item;
}
currentTheme = currentTheme.getParent();
}
return null;
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ThemeResolver method constructThemeFromResourceValue.
/**
* Create a ThemeEditorStyle instance stored in ThemeResolver, which can be added to one of theme lists.
*/
@Nullable
private /*if theme with this name was already added or resolution has failed*/
ConfiguredThemeEditorStyle constructThemeFromResourceValue(@NotNull StyleResourceValue value, @Nullable Module sourceModule) {
final String name = ResolutionUtils.getQualifiedStyleName(value);
if (myThemeByName.containsKey(name)) {
return null;
}
final ConfiguredThemeEditorStyle theme = ResolutionUtils.getStyle(myConfiguration, name, sourceModule);
if (theme != null) {
myThemeByName.put(name, theme);
}
return theme;
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle 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);
}
Aggregations