Search in sources :

Example 16 with ConfiguredThemeEditorStyle

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;
}
Also used : ResourceValue(com.android.ide.common.rendering.api.ResourceValue) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) ResourceType(com.android.resources.ResourceType) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with ConfiguredThemeEditorStyle

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

Example 18 with ConfiguredThemeEditorStyle

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

Example 19 with ConfiguredThemeEditorStyle

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

Example 20 with ConfiguredThemeEditorStyle

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

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