Search in sources :

Example 6 with ConfiguredThemeEditorStyle

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

the class ParentRendererEditor method getRendererComponent.

@Override
public Component getRendererComponent(JTable table, ConfiguredThemeEditorStyle value, boolean isSelected, boolean hasFocus, int row, int column) {
    final TableModel model = table.getModel();
    final ConfiguredThemeEditorStyle parent = value.getParent();
    Font font = table.getFont();
    Font scaledFont = ThemeEditorUtils.scaleFontForAttribute(font);
    myParentComboBox.setFont(scaledFont);
    myLabel.setFont(scaledFont);
    myParentComboBox.setEnabled(model.isCellEditable(row, column));
    if (parent == null) {
        myParentComboBox.setModel(NO_PARENT_MODEL);
        myItem = null;
    } else {
        ImmutableList<String> defaultThemeNames = ThemeEditorUtils.getDefaultThemeNames(myContext.getThemeResolver());
        myParentComboBox.setModel(new ParentThemesListModel(defaultThemeNames, parent.getQualifiedName()));
        myItem = value;
    }
    updateVariantsCombo();
    return myPanel;
}
Also used : ParentThemesListModel(com.android.tools.idea.editors.theme.ParentThemesListModel) TableModel(javax.swing.table.TableModel) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 7 with ConfiguredThemeEditorStyle

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

the class StyleListCellRenderer method customizeCellRenderer.

@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
    if (!(value instanceof String)) {
        return;
    }
    String stringValue = (String) value;
    if (ThemesListModel.isSpecialOption(stringValue) || ParentRendererEditor.NO_PARENT.equals(stringValue)) {
        append(stringValue, SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
        return;
    }
    ConfiguredThemeEditorStyle style = myContext.getThemeResolver().getTheme(stringValue);
    if (style == null) {
        append(stringValue, SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
        return;
    }
    ConfiguredThemeEditorStyle parent = style.getParent();
    String styleName = style.getName();
    String parentName = parent != null ? parent.getName() : null;
    String defaultAppThemeResourceUrl = null;
    final AndroidFacet facet = AndroidFacet.getInstance(myContext.getCurrentContextModule());
    if (facet != null) {
        MergedManifest info = MergedManifest.get(facet);
        defaultAppThemeResourceUrl = info.getManifestTheme();
    }
    if (!style.isProjectStyle()) {
        String simplifiedName = ThemeEditorUtils.simplifyThemeName(style);
        String qualifiedStyleName = (style.isFramework() ? SdkConstants.PREFIX_ANDROID : "") + styleName;
        if (StringUtil.isEmpty(simplifiedName)) {
            append(qualifiedStyleName, SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
        } else {
            append(simplifiedName, SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
            append(" [" + qualifiedStyleName + "]", SimpleTextAttributes.GRAY_ATTRIBUTES, false);
        }
    } else if (!selected && parentName != null && styleName.startsWith(parentName + ".")) {
        append(parentName + ".", SimpleTextAttributes.GRAY_ATTRIBUTES, false);
        append(styleName.substring(parentName.length() + 1), SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
    } else {
        append(styleName, SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
    }
    if (style.getStyleResourceUrl().equals(defaultAppThemeResourceUrl)) {
        append("  -  Default", new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, new JBColor(0xFF4CAF50, 0xFFA5D6A7)), true);
    }
}
Also used : MergedManifest(com.android.tools.idea.model.MergedManifest) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) JBColor(com.intellij.ui.JBColor) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 8 with ConfiguredThemeEditorStyle

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

the class ResolutionUtilsTest method testFrameworkStyleRead.

public void testFrameworkStyleRead() {
    VirtualFile myLayout = myFixture.copyFileToProject("themeEditor/layout.xml", "res/layout/layout1.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myLayout);
    assertNotNull(ResolutionUtils.getStyle(configuration, "android:TextAppearance", null));
    ConfiguredThemeEditorStyle style = ResolutionUtils.getStyle(configuration, "android:Theme.Holo.Light", null);
    assertEquals("Theme.Holo.Light", style.getName());
    try {
        style.setValue("newAttribute", "test");
        fail("Project styles shouldn't be modifiable");
    } catch (UnsupportedOperationException ignored) {
    }
    try {
        // We try to set a parent, this should fail because the style is read-only.
        // We use Theme as it's the only parent available on the test SDK.
        style.setParent("Theme");
        fail("Project styles shouldn't be modifiable");
    } catch (UnsupportedOperationException ignored) {
    }
    style = style.getParent();
    assertEquals("Theme.Light", style.getName());
    assertNotEmpty(style.getConfiguredValues());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 9 with ConfiguredThemeEditorStyle

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

the class ThemeAttributeResolverTest method testResolveAllVersion.

/**
   * Tests {@link ThemeAttributeResolver#resolveAll(ConfiguredThemeEditorStyle, ThemeResolver)}
   */
public void testResolveAllVersion() {
    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-v13", "values-v16"));
    createNewStyle(resourceDir, "ThemeB", "ThemeA", "blue", Lists.newArrayList("values-v12"));
    createNewStyle(resourceDir, "ThemeB", "ThemeA", null, Lists.newArrayList("values-v15"));
    // 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("-v16:red", "-v15:red", "-v14:blue");
    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)

Example 10 with ConfiguredThemeEditorStyle

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

the class ThemeEditorComponentTest method testGetGoodContrastPreviewBackground.

public void testGetGoodContrastPreviewBackground() {
    VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_background.xml", "res/values/styles.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
    ResourceResolver resourceResolver = configuration.getResourceResolver();
    assertNotNull(resourceResolver);
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle theme1 = themeResolver.getTheme("Theme.Theme1");
    assertNotNull(theme1);
    ConfiguredThemeEditorStyle theme2 = themeResolver.getTheme("Theme.Theme2");
    assertNotNull(theme2);
    ConfiguredThemeEditorStyle theme3 = themeResolver.getTheme("Theme.Theme3");
    assertNotNull(theme3);
    assertEquals(ThemeEditorComponent.ALT_PREVIEW_BACKGROUND, ThemeEditorUtils.getGoodContrastPreviewBackground(theme1, resourceResolver));
    assertEquals(ThemeEditorComponent.PREVIEW_BACKGROUND, ThemeEditorUtils.getGoodContrastPreviewBackground(theme2, resourceResolver));
    assertEquals(ThemeEditorComponent.PREVIEW_BACKGROUND, ThemeEditorUtils.getGoodContrastPreviewBackground(theme3, resourceResolver));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) ResourceResolver(com.android.ide.common.resources.ResourceResolver) 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