use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method testSettingInHighApiTheme.
/**
* Test setting a low-api attributes and parent in a theme defined only in higher api files
*/
public void testSettingInHighApiTheme() {
VirtualFile virtualFile = myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v14.xml", "res/values-v14/styles.xml");
myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v19.xml", "res/values-v19/styles.xml");
myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v21.xml", "res/values-v21/styles.xml");
ConfigurationManager configurationManager = myFacet.getConfigurationManager();
Configuration configuration = configurationManager.getConfiguration(virtualFile);
ThemeResolver themeResolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle theme = themeResolver.getTheme("Theme.MyOtherTheme");
assertNotNull(theme);
theme.setValue("android:windowIsFloating", "holo_purple");
theme.setValue("android:actionBarDivider", "myValue");
theme.setParent("android:Theme.Holo.Light.DarkActionBar");
myFixture.checkResultByFile("res/values/styles.xml", "themeEditor/apiTestAfter8/stylesApi.xml", true);
myFixture.checkResultByFile("res/values-v14/styles.xml", "themeEditor/apiTestAfter8/stylesApi-v14.xml", true);
myFixture.checkResultByFile("res/values-v19/styles.xml", "themeEditor/apiTestAfter8/stylesApi-v19.xml", true);
myFixture.checkResultByFile("res/values-v21/styles.xml", "themeEditor/apiTestAfter8/stylesApi-v21.xml", true);
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ThemeEditorUtilsTest method testGetDisplayHtml.
public void testGetDisplayHtml() {
VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_1.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/attrs.xml", "res/values/attrs.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
ThemeResolver themeResolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle theme = themeResolver.getTheme("AppTheme");
assertNotNull(theme);
Collection<EditedStyleItem> values = ThemeEditorTestUtils.getStyleLocalValues(theme);
assertEquals(7, values.size());
for (EditedStyleItem item : values) {
String displayHtml = ThemeEditorUtils.getDisplayHtml(item);
if ("myDeprecated".equals(item.getName())) {
assertEquals("<html><body><strike>myDeprecated</strike></body></html>", displayHtml);
} else {
assertEquals(item.getName(), displayHtml);
}
}
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ThemeEditorUtilsTest method testGenerateToolTipText.
public void testGenerateToolTipText() throws IOException {
if (SystemInfo.isWindows) {
// Do not run tests on Windows (see http://b.android.com/222904)
return;
}
VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_1.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/attrs.xml", "res/values/attrs.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
IAndroidTarget androidTarget = configuration.getTarget();
assertNotNull(androidTarget);
sdkPlatformPath = androidTarget.getLocation();
if (LayoutLibraryLoader.USE_SDK_LAYOUTLIB) {
if (!sdkPlatformPath.endsWith("/"))
sdkPlatformPath += "/";
sdkPlatformPath += "platforms/android-" + androidTarget.getVersion().getApiString();
}
sdkPlatformPath = Files.simplifyPath(sdkPlatformPath);
ThemeResolver themeResolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle theme = themeResolver.getTheme("AppTheme");
assertNotNull(theme);
Collection<EditedStyleItem> values = ThemeEditorTestUtils.getStyleLocalValues(theme);
assertEquals(7, values.size());
configuration.setTheme("AppTheme");
for (EditedStyleItem item : values) {
String doc = ThemeEditorUtils.generateToolTipText(item.getSelectedValue(), myModule, configuration);
compareWithGoldenFile(doc, myFixture.getTestDataPath() + "/themeEditor/tooltipDocAns/" + item.getName() + ".ans");
}
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ThemeResolverTest method testFrameworkThemeRead.
/*
* The test SDK only includes some resources. It only includes a few incomplete styles.
*/
public void testFrameworkThemeRead() {
VirtualFile myLayout = myFixture.copyFileToProject("xmlpull/layout.xml", "res/layout/layout1.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myLayout);
ThemeResolver themeResolver = new ThemeResolver(configuration);
// It's system theme and we're not specifying namespace so it will fail.
assertNull(themeResolver.getTheme("Theme.Holo.Light"));
ConfiguredThemeEditorStyle theme = themeResolver.getTheme("android:Theme.Holo.Light");
assertEquals("Theme.Holo.Light", theme.getName());
// Only framework themes.
assertEquals(themeResolver.getThemesCount(), themeResolver.getFrameworkThemes().size());
assertEmpty(themeResolver.getLocalThemes());
assertNull("Theme resolver shouldn't resolve styles", themeResolver.getTheme("android:TextAppearance"));
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method checkSetValue.
private void checkSetValue(VirtualFile file, ItemResourceValue item, String... answerFolders) {
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(file);
ThemeResolver themeResolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle style = themeResolver.getTheme("AppTheme");
assertNotNull(style);
style.setValue(ResolutionUtils.getQualifiedItemName(item), item.getValue());
// ResourceFolderRepository needs to rescan the files to pick up the changes.
UIUtil.dispatchAllInvocationEvents();
HashSet<String> modifiedFolders = new HashSet<>(Arrays.asList(answerFolders));
int valuesFound = 0;
for (ConfiguredElement<ItemResourceValue> value : style.getConfiguredValues()) {
if (item.equals(value.getElement())) {
valuesFound++;
assertTrue(modifiedFolders.contains(value.getConfiguration().getUniqueKey()));
}
}
assertEquals(modifiedFolders.size(), valuesFound);
}
Aggregations