use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method checkSetParent.
private void checkSetParent(VirtualFile file, String newParent, String... answerFolders) {
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(file);
ThemeResolver themeResolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle theme = themeResolver.getTheme("AppTheme");
assertNotNull(theme);
theme.setParent(newParent);
// 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<String> value : theme.getParentNames()) {
if (newParent.equals(value.getElement())) {
valuesFound++;
assertTrue(modifiedFolders.contains(value.getConfiguration().getUniqueKey()));
}
}
assertEquals(modifiedFolders.size(), valuesFound);
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method testGetParentNames.
public void testGetParentNames() {
myFixture.copyFileToProject("themeEditor/attributeResolution/styles_base.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v17.xml", "res/values-v17/styles.xml");
myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v19.xml", "res/values-v19/styles.xml");
VirtualFile file = myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v20.xml", "res/values-v20/styles.xml");
ConfigurationManager configurationManager = myFacet.getConfigurationManager();
Configuration configuration = configurationManager.getConfiguration(file);
ThemeResolver resolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle theme = resolver.getTheme("AppTheme");
assertNotNull(theme);
Collection<ConfiguredElement<String>> parents = theme.getParentNames();
assertSize(2, parents);
ImmutableList<String> parentNames = ImmutableList.of(Iterables.get(parents, 0).getElement(), Iterables.get(parents, 1).getElement());
assertContainsElements(parentNames, "Base.V20", "Base.V17");
// Set API 17 and try the same resolution
//noinspection ConstantConditions
configuration.setTarget(new CompatibilityRenderTarget(configurationManager.getHighestApiTarget(), 17, configurationManager.getHighestApiTarget()));
parents = theme.getParentNames();
assertSize(2, parents);
parentNames = ImmutableList.of(Iterables.get(parents, 0).getElement(), Iterables.get(parents, 1).getElement());
assertContainsElements(parentNames, "Base.V20", "Base.V17");
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method testGetStyleResourceUrl.
public void testGetStyleResourceUrl() {
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);
assertEquals("@style/AppTheme", theme.getStyleResourceUrl());
theme = themeResolver.getTheme("android:Theme");
assertNotNull(theme);
assertEquals("@android:style/Theme", theme.getStyleResourceUrl());
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ThemeResolverTest method testLocalThemes.
public void testLocalThemes() throws IOException {
VirtualFile myLayout = myFixture.copyFileToProject("themeEditor/layout.xml", "res/layout/layout.xml");
VirtualFile myStyleFile = myFixture.copyFileToProject("themeEditor/styles.xml", "res/values/styles.xml");
ConfigurationManager configurationManager = myFacet.getConfigurationManager();
Configuration configuration = configurationManager.getConfiguration(myLayout);
ThemeResolver themeResolver = new ThemeResolver(configuration);
// We don't have any libraries so this will only include the project theme
assertEquals(1, themeResolver.getLocalThemes().size());
// No library themes
assertEquals(0, themeResolver.getExternalLibraryThemes().size());
assertNull("The theme is an app theme and shouldn't be returned for the android namespace", themeResolver.getTheme("android:Theme.MyTheme"));
ConfiguredThemeEditorStyle theme = themeResolver.getTheme("Theme.MyTheme");
assertEquals("Theme.MyTheme", theme.getName());
assertEquals("Theme", theme.getParent().getName());
assertEquals(1, theme.getConfiguredValues().size());
ConfiguredElement<ItemResourceValue> value = Iterables.get(theme.getConfiguredValues(), 0);
assertEquals("windowBackground", value.getElement().getName());
assertEquals("@drawable/pic", value.getElement().getValue());
// Modify a value.
theme.setValue("android:windowBackground", "@drawable/other");
FileDocumentManager.getInstance().saveAllDocuments();
assertFalse(new String(myStyleFile.contentsToByteArray(), "UTF-8").contains("@drawable/pic"));
assertTrue(new String(myStyleFile.contentsToByteArray(), "UTF-8").contains("@drawable/other"));
// Add a value.
theme.setValue("android:windowBackground2", "@drawable/second_background");
FileDocumentManager.getInstance().saveAllDocuments();
assertTrue(new String(myStyleFile.contentsToByteArray(), "UTF-8").contains("@drawable/other"));
assertTrue(new String(myStyleFile.contentsToByteArray(), "UTF-8").contains("@drawable/second_background"));
}
use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method testGetConfiguredValues.
/**
* Tests {@link ConfiguredThemeEditorStyle#getConfiguredValues()}
* Tests values coming from different modules.
* Dependency used in the test: mainModule -> moduleA, mainModule -> moduleB
*/
public void testGetConfiguredValues() {
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_4.xml", "additionalModules/moduleB/res/values-v19/styles.xml");
VirtualFile virtualFile = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_3.xml", "additionalModules/moduleA/res/values/styles.xml");
ConfigurationManager configurationManager = myFacet.getConfigurationManager();
Configuration configuration = configurationManager.getConfiguration(virtualFile);
ThemeResolver resolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle theme = resolver.getTheme("AppTheme");
assertNotNull(theme);
assertEquals(3, theme.getConfiguredValues().size());
}
Aggregations