Search in sources :

Example 26 with ConfiguredThemeEditorStyle

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);
}
Also used : ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with ConfiguredThemeEditorStyle

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";
}
Also used : ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with ConfiguredThemeEditorStyle

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;
}
Also used : ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with ConfiguredThemeEditorStyle

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;
}
Also used : ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with ConfiguredThemeEditorStyle

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)

Aggregations

ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)41 Configuration (com.android.tools.idea.configurations.Configuration)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)13 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)9 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)9 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)8 NotNull (org.jetbrains.annotations.NotNull)6 ResourceResolver (com.android.ide.common.resources.ResourceResolver)5 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)4 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)2 ParentThemesListModel (com.android.tools.idea.editors.theme.ParentThemesListModel)2 ConfiguredElement (com.android.tools.idea.editors.theme.datamodels.ConfiguredElement)2 PsiElement (com.intellij.psi.PsiElement)2 TableModel (javax.swing.table.TableModel)2 Nullable (org.jetbrains.annotations.Nullable)2 ResourceType (com.android.resources.ResourceType)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 ThemeResolver (com.android.tools.idea.editors.theme.ThemeResolver)1 AttributesModelColorPaletteModel (com.android.tools.idea.editors.theme.attributes.AttributesModelColorPaletteModel)1