Search in sources :

Example 1 with ThemeResolver

use of com.android.tools.idea.editors.theme.ThemeResolver in project android by JetBrains.

the class StyleListPaletteCellRenderer method customizeCellRenderer.

@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
    super.customizeCellRenderer(list, value, index, selected, hasFocus);
    if (!(value instanceof String) || ThemesListModel.isSpecialOption((String) value)) {
        myColorPaletteComponent.reset();
        return;
    }
    ThemeResolver themeResolver = myContext.getThemeResolver();
    final ConfiguredThemeEditorStyle theme = themeResolver.getTheme((String) value);
    if (theme == null) {
        myColorPaletteComponent.reset();
        setIcon(null);
        return;
    }
    final boolean isFrameworkAttr = !ThemeEditorUtils.isAppCompatTheme(theme);
    ItemResourceValue primaryResourceValue = ThemeEditorUtils.resolveItemFromParents(theme, PRIMARY_MATERIAL, isFrameworkAttr);
    ItemResourceValue primaryDarkResourceValue = ThemeEditorUtils.resolveItemFromParents(theme, PRIMARY_DARK_MATERIAL, isFrameworkAttr);
    ItemResourceValue accentResourceValue = ThemeEditorUtils.resolveItemFromParents(theme, ACCENT_MATERIAL, isFrameworkAttr);
    //Check needed in case the xml files are inconsistent and have an item, but not a value
    if (primaryResourceValue != null && primaryDarkResourceValue != null && accentResourceValue != null) {
        Configuration configuration = theme.getConfiguration();
        ResourceResolver resourceResolver = configuration.getConfigurationManager().getResolverCache().getResourceResolver(configuration.getRealTarget(), theme.getStyleResourceUrl(), configuration.getFullConfig());
        Color primaryColor = ResourceHelper.resolveColor(resourceResolver, primaryResourceValue, myContext.getProject());
        Color primaryDarkColor = ResourceHelper.resolveColor(resourceResolver, primaryDarkResourceValue, myContext.getProject());
        Color accentColor = ResourceHelper.resolveColor(resourceResolver, accentResourceValue, myContext.getProject());
        if (primaryColor != null && primaryDarkColor != null && accentColor != null) {
            myColorPaletteComponent.setValues(primaryColor, primaryDarkColor, accentColor);
        }
        setIcon(myColorPaletteComponent);
    } else {
        myColorPaletteComponent.reset();
        setIcon(null);
    }
    if (selected) {
        myThemeChangedListener.themeChanged(theme.getQualifiedName());
    }
}
Also used : ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) Configuration(com.android.tools.idea.configurations.Configuration) ThemeResolver(com.android.tools.idea.editors.theme.ThemeResolver) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Aggregations

ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)1 ResourceResolver (com.android.ide.common.resources.ResourceResolver)1 Configuration (com.android.tools.idea.configurations.Configuration)1 ThemeResolver (com.android.tools.idea.editors.theme.ThemeResolver)1 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)1