use of com.android.tools.idea.configurations.Configuration 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.configurations.Configuration in project android by JetBrains.
the class MultipleModulesTest method testThemeResolver.
public void testThemeResolver() {
final VirtualFile appThemes = myFixture.copyFileToProject("themeEditor/multimodulesProject/app_themes.xml", "res/values/themes.xml");
myFixture.copyFileToProject("themeEditor/multimodulesProject/unusedlibrary_themes.xml", getAdditionalModulePath(UNUSEDLIBRARY) + "/res/values/themes.xml");
myFixture.copyFileToProject("themeEditor/multimodulesProject/usedlibrary_themes.xml", getAdditionalModulePath(USEDLIBRARY) + "/res/values/themes.xml");
// Main theme module
final Configuration configuration1 = myFacet.getConfigurationManager().getConfiguration(appThemes);
final ThemeResolver resolver1 = new ThemeResolver(configuration1);
// Available themes should contain from used library, but, more importantly, shouldn't contain themes from unused library (not a dependency)
assertContainsElements(themeNames(resolver1.getLocalThemes()), "AppTheme", "LibraryDependentTheme", "UsedLibraryTheme");
// Used library module
final Configuration configuration2 = AndroidFacet.getInstance(myAdditionalModules.get(0)).getConfigurationManager().getConfiguration(appThemes);
final ThemeResolver resolver2 = new ThemeResolver(configuration2);
assertContainsElements(themeNames(resolver2.getLocalThemes()), "UsedLibraryTheme");
// Unused library module
final Configuration configuration3 = AndroidFacet.getInstance(myAdditionalModules.get(1)).getConfigurationManager().getConfiguration(appThemes);
final ThemeResolver resolver3 = new ThemeResolver(configuration3);
assertContainsElements(themeNames(resolver3.getLocalThemes()), "UnusedLibraryTheme");
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class ResolutionUtilsTest method testGetParentQualifiedName.
/**
* Tests {@link ResolutionUtils#getParentQualifiedName(StyleResourceValue)}
*/
public void testGetParentQualifiedName() {
VirtualFile file = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles.xml", "res/values/styles.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(file);
ResourceResolver resolver = configuration.getResourceResolver();
assertNotNull(resolver);
StyleResourceValue style;
style = resolver.getStyle("Theme", true);
assertNotNull(style);
assertEquals(null, ResolutionUtils.getParentQualifiedName(style));
style = resolver.getStyle("Theme.Holo.Light", true);
assertNotNull(style);
assertEquals("android:Theme.Light", ResolutionUtils.getParentQualifiedName(style));
style = resolver.getStyle("ATheme", false);
assertNotNull(style);
assertEquals("android:Theme", ResolutionUtils.getParentQualifiedName(style));
style = resolver.getStyle("AppTheme", false);
assertNotNull(style);
assertEquals("ATheme", ResolutionUtils.getParentQualifiedName(style));
style = resolver.getStyle("ATheme.Red", false);
assertNotNull(style);
assertEquals("ATheme", ResolutionUtils.getParentQualifiedName(style));
}
use of com.android.tools.idea.configurations.Configuration 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.configurations.Configuration 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