use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ResourcesCompletionProvider method getCompletions.
@NotNull
@Override
public List<String> getCompletions(@NotNull EditedStyleItem value) {
ConfiguredThemeEditorStyle selectedStyle = value.getSourceStyle();
AttributeDefinition attrDefinition = ResolutionUtils.getAttributeDefinition(selectedStyle.getConfiguration(), value.getSelectedValue());
if (attrDefinition == null) {
return Collections.emptyList();
}
Set<ResourceType> acceptedTypes = EnumSet.noneOf(ResourceType.class);
if (ThemeEditorUtils.acceptsFormat(attrDefinition, AttributeFormat.Color)) {
acceptedTypes.add(ResourceType.COLOR);
}
if (ThemeEditorUtils.acceptsFormat(attrDefinition, AttributeFormat.Dimension)) {
acceptedTypes.add(ResourceType.DIMEN);
}
if (ThemeEditorUtils.acceptsFormat(attrDefinition, AttributeFormat.String)) {
acceptedTypes.add(ResourceType.STRING);
}
if (ThemeEditorUtils.acceptsFormat(attrDefinition, AttributeFormat.Reference)) {
acceptedTypes.addAll(ImmutableList.of(ResourceType.LAYOUT, ResourceType.COLOR, ResourceType.DRAWABLE, ResourceType.MIPMAP, ResourceType.STYLE, ResourceType.ATTR, ResourceType.STRING, ResourceType.DIMEN, ResourceType.TRANSITION));
}
ArrayList<String> resourceNamesList = new ArrayList<String>(myAllResources.size());
for (ResourceValue resource : myAllResources) {
if (!acceptedTypes.contains(resource.getResourceType())) {
continue;
}
final String name = String.format("%1$s%2$s%3$s/%4$s", ResourceType.ATTR == resource.getResourceType() ? SdkConstants.PREFIX_THEME_REF : SdkConstants.PREFIX_RESOURCE_REF, resource.isFramework() ? SdkConstants.ANDROID_NS_NAME_PREFIX : "", resource.getResourceType().getName(), resource.getName());
resourceNamesList.add(name);
}
return resourceNamesList;
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ColorUtils method getContrastItems.
/**
* @param styleAttributeName the name of a style attribute we want to check for contrast issues
* Returns the set of {@link ItemResourceValue} that have to be checked in the current theme for contrast against a particular attribute.
*/
@NotNull
public static ImmutableSet<ItemResourceValue> getContrastItems(@NotNull ThemeEditorContext context, @NotNull String styleAttributeName) {
Set<String> contrastColorSet = CONTRAST_MAP.get(styleAttributeName);
if (contrastColorSet == null) {
return ImmutableSet.of();
}
ImmutableSet.Builder<ItemResourceValue> contrastItemsBuilder = ImmutableSet.builder();
ConfiguredThemeEditorStyle currentTheme = context.getCurrentTheme();
assert currentTheme != null;
for (String contrastColor : contrastColorSet) {
ItemResourceValue contrastItem = ThemeEditorUtils.resolveItemFromParents(currentTheme, contrastColor, false);
if (contrastItem == null) {
contrastItem = ThemeEditorUtils.resolveItemFromParents(currentTheme, contrastColor, true);
}
if (contrastItem != null) {
contrastItemsBuilder.add(contrastItem);
}
}
return contrastItemsBuilder.build();
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ThemeSelectionPanel method getFilteredPrefixesSortedNames.
/**
* Sorts the themes in themesRaw excluding those in excludedThemes and those starting with prefixes in excludedPrefixes
*
* @param themesRaw themes to process
* @param excludedThemes themes to filter out
* @param excludedPrefixes set of prefixes of the themes to filter
* @return the sorted themes excluding those in excludedThemes or starting with a prefix in excludedPrefixes
*/
private static List<String> getFilteredPrefixesSortedNames(Collection<ConfiguredThemeEditorStyle> themesRaw, Set<String> excludedThemes, Set<String> excludedPrefixes) {
List<String> themes = new ArrayList<String>(themesRaw.size());
for (ConfiguredThemeEditorStyle theme : themesRaw) {
String qualifiedName = theme.getQualifiedName();
if (!excludedThemes.contains(qualifiedName)) {
boolean startWithPrefix = false;
String themeName = theme.getName();
for (String prefix : excludedPrefixes) {
if (themeName.startsWith(prefix)) {
startWithPrefix = true;
break;
}
}
if (!startWithPrefix) {
themes.add(qualifiedName);
}
}
}
Collections.sort(themes);
return themes;
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle 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());
}
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ParentRendererEditor method getEditorComponent.
@Override
public Component getEditorComponent(JTable table, ConfiguredThemeEditorStyle value, boolean isSelected, int row, int column) {
Font font = table.getFont();
Font scaledFont = ThemeEditorUtils.scaleFontForAttribute(font);
myParentComboBox.setFont(scaledFont);
myLabel.setFont(scaledFont);
ConfiguredThemeEditorStyle parent = value.getParent();
ImmutableList<String> defaultThemeNames = ThemeEditorUtils.getDefaultThemeNames(myContext.getThemeResolver());
myParentComboBox.setModel(new ParentThemesListModel(defaultThemeNames, parent.getQualifiedName()));
myResultValue = parent.getQualifiedName();
myItem = value;
updateVariantsCombo();
return myPanel;
}
Aggregations