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());
}
}
Aggregations