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