use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class NestedConfigurationTest method testListener.
public void testListener() throws Exception {
final AndroidFacet facet = AndroidFacet.getInstance(myModule);
assertNotNull(facet);
ConfigurationManager manager = facet.getConfigurationManager();
assertNotNull(manager);
assertSame(manager, facet.getConfigurationManager());
Configuration parent = Configuration.create(manager, null, new FolderConfiguration());
assertNotNull(parent);
NestedConfiguration configuration = NestedConfiguration.create(parent);
assertNotNull(configuration);
ConfigurationListener listener = new ConfigurationListener() {
@Override
public boolean changed(int flags) {
myFlags = flags;
myChangeCount++;
return true;
}
};
configuration.addListener(listener);
myChangeCount = 0;
myFlags = 0;
configuration.setOverrideLocale(true);
configuration.setLocale(Locale.create("en-rUS"));
assertEquals(1, myChangeCount);
assertEquals(CFG_LOCALE, myFlags);
// No firing when only seeing overridden changes
myFlags = 0;
parent.setLocale(Locale.create("es"));
assertEquals(1, myChangeCount);
assertEquals(0, myFlags);
myFlags = 0;
parent.setLocale(Locale.create("de"));
parent.setUiMode(UiMode.APPLIANCE);
assertEquals(2, myChangeCount);
assertEquals(CFG_UI_MODE, myFlags);
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method testHasItem.
public void testHasItem() {
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);
ConfiguredThemeEditorStyle parent = theme.getParent();
assertNotNull(parent);
FolderConfiguration defaultConfig = new FolderConfiguration();
ConfiguredElement<ItemResourceValue> hasItem = ConfiguredElement.create(defaultConfig, new ItemResourceValue("myColor", false, "?android:attr/colorBackground", false, null));
ConfiguredElement<ItemResourceValue> hasNotItem = ConfiguredElement.create(defaultConfig, new ItemResourceValue("myHasNot", false, "?android:attr/colorBackground", false, null));
ConfiguredElement<ItemResourceValue> hasInParent = ConfiguredElement.create(defaultConfig, new ItemResourceValue("editTextStyle", true, "?android:attr/colorBackground", true, null));
assertTrue(theme.hasItem(new EditedStyleItem(hasItem, theme)));
assertFalse(theme.hasItem(new EditedStyleItem(hasNotItem, theme)));
assertTrue(theme.getParent().hasItem(new EditedStyleItem(hasInParent, parent)));
assertFalse(theme.hasItem(new EditedStyleItem(hasInParent, parent)));
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android_frameworks_base by DirtyUnicorns.
the class ConfigGenerator method getFolderConfig.
public FolderConfiguration getFolderConfig() {
FolderConfiguration config = new FolderConfiguration();
config.createDefault();
config.setDensityQualifier(new DensityQualifier(mDensity));
config.setNavigationMethodQualifier(new NavigationMethodQualifier(mNavigation));
if (mScreenWidth > mScreenHeight) {
config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenWidth, mScreenHeight));
} else {
config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenHeight, mScreenWidth));
}
config.setScreenRatioQualifier(new ScreenRatioQualifier(mRatio));
config.setScreenSizeQualifier(new ScreenSizeQualifier(mSize));
config.setTextInputMethodQualifier(new TextInputMethodQualifier(mKeyboard));
config.setTouchTypeQualifier(new TouchScreenQualifier(mTouchScreen));
config.setKeyboardStateQualifier(new KeyboardStateQualifier(mKeyboardState));
config.setScreenOrientationQualifier(new ScreenOrientationQualifier(mOrientation));
config.updateScreenWidthAndHeight();
// some default qualifiers.
config.setUiModeQualifier(new UiModeQualifier(UiMode.NORMAL));
config.setNightModeQualifier(new NightModeQualifier(NightMode.NOTNIGHT));
config.setCountryCodeQualifier(new CountryCodeQualifier());
config.setLayoutDirectionQualifier(new LayoutDirectionQualifier());
config.setNetworkCodeQualifier(new NetworkCodeQualifier());
config.setLocaleQualifier(new LocaleQualifier());
config.setVersionQualifier(new VersionQualifier());
return config;
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class ModuleResourceRepositoryTest method testOverlays.
public void testOverlays() {
myFixture.copyFileToProject(LAYOUT, "res/layout/layout1.xml");
myFixture.copyFileToProject(LAYOUT_OVERLAY, "res2/layout/layout1.xml");
myFixture.copyFileToProject(LAYOUT_IDS_1, "res2/layout/layout_ids1.xml");
myFixture.copyFileToProject(LAYOUT_IDS_2, "res2/layout/layout_ids2.xml");
VirtualFile res1 = myFixture.copyFileToProject(VALUES, "res/values/values.xml").getParent().getParent();
VirtualFile res2 = myFixture.copyFileToProject(VALUES_OVERLAY1, "res2/values/values.xml").getParent().getParent();
VirtualFile res3 = myFixture.copyFileToProject(VALUES_OVERLAY2, "res3/values/nameDoesNotMatter.xml").getParent().getParent();
myFixture.copyFileToProject(VALUES_OVERLAY2_NO, "res3/values-no/values.xml");
assertNotSame(res1, res2);
assertNotSame(res1, res3);
assertNotSame(res2, res3);
ModuleResourceRepository resources = ModuleResourceRepository.createForTest(myFacet, Arrays.asList(res1, res2, res3));
// Check that values are handled correctly. First a plain value (not overridden anywhere).
assertStringIs(resources, "title_layout_changes", "Layout Changes");
// Check that an overridden key (overridden in just one flavor) is picked up
// Overridden in res2
assertStringIs(resources, "title_crossfade", "Complex Crossfade");
// Overridden in res3
assertStringIs(resources, "title_zoom", "Zoom!");
// Make sure that new/unique strings from flavors are available
// Overridden in res2
assertStringIs(resources, "unique_string", "Unique");
// Overridden in res3
assertStringIs(resources, "another_unique_string", "Another Unique", false);
// Check that an overridden key (overridden in multiple flavors) picks the last one
// res3 (not unique because we have a values-no item too)
assertStringIs(resources, "app_name", "Very Different App Name", false);
// Layouts: Should only be offered id's from the overriding layout (plus those defined in values.xml)
// from values.xml
assertTrue(resources.hasResourceItem(ResourceType.ID, "action_next"));
// from res2 layout1.xml
assertTrue(resources.hasResourceItem(ResourceType.ID, "noteArea"));
// Layout masking does not currently work. I'm not 100% certain what the intended behavior is
// here (e.g. res1's layout1 contains @+id/button1, res2's layout1 does not; should @+id/button1 be visible?)
//assertFalse(resources.hasResourceItem(ResourceType.ID, "btn_title_refresh")); // masked in res1 by res2's layout replacement
// Check that localized lookup (qualifier matching works)
List<ResourceItem> stringList = resources.getResourceItem(ResourceType.STRING, "another_unique_string");
assertNotNull(stringList);
assertSize(2, stringList);
FolderConfiguration valueConfig = FolderConfiguration.getConfigForFolder("values-no");
assertNotNull(valueConfig);
ResourceValue stringValue = resources.getConfiguredResources(ResourceType.STRING, valueConfig).get("another_unique_string");
assertNotNull(stringValue);
assertEquals("En Annen", stringValue.getValue());
// Change flavor order and make sure things are updated and work correctly
resources.updateRoots(Arrays.asList(res1, res3, res2));
// Should now be picking app_name from res2 rather than res3 since it's now last
// res2
assertStringIs(resources, "app_name", "Different App Name", false);
// Sanity check other merging
assertStringIs(resources, "title_layout_changes", "Layout Changes");
// Overridden in res2
assertStringIs(resources, "title_crossfade", "Complex Crossfade");
// Overridden in res3
assertStringIs(resources, "title_zoom", "Zoom!");
// Overridden in res2
assertStringIs(resources, "unique_string", "Unique");
// Overridden in res3
assertStringIs(resources, "another_unique_string", "Another Unique", false);
// Hide a resource root (res2)
resources.updateRoots(Arrays.asList(res1, res3));
// No longer aliasing the main layout
// res1 layout1.xml
assertTrue(resources.hasResourceItem(ResourceType.ID, "btn_title_refresh"));
// from res1 layout1.xml
assertTrue(resources.hasResourceItem(ResourceType.ID, "noteArea"));
// from values.xml
assertTrue(resources.hasResourceItem(ResourceType.ID, "action_next"));
// No longer overridden in res2
assertStringIs(resources, "title_crossfade", "Simple Crossfade");
// Finally ensure that we can switch roots repeatedly (had some earlier bugs related to root unregistration)
resources.updateRoots(Arrays.asList(res1, res3, res2));
resources.updateRoots(Arrays.asList(res1));
resources.updateRoots(Arrays.asList(res1, res3, res2));
resources.updateRoots(Arrays.asList(res1));
resources.updateRoots(Arrays.asList(res1, res3, res2));
resources.updateRoots(Arrays.asList(res2));
resources.updateRoots(Arrays.asList(res1));
resources.updateRoots(Arrays.asList(res1, res2, res3));
assertStringIs(resources, "title_layout_changes", "Layout Changes");
// Make sure I get all the resource ids (there can be multiple; these are not replaced via overlays)
List<ResourceItem> ids = resources.getResourceItem(ResourceType.ID, "my_id");
assertNotNull(ids);
assertSize(2, ids);
Collections.sort(ids, new Comparator<ResourceItem>() {
@SuppressWarnings("ConstantConditions")
@Override
public int compare(ResourceItem item1, ResourceItem item2) {
return item1.getSource().getFile().getName().compareTo(item2.getSource().getFile().getName());
}
});
//noinspection ConstantConditions
assertEquals("layout_ids1.xml", ids.get(0).getSource().getFile().getName());
//noinspection ConstantConditions
assertEquals("layout_ids2.xml", ids.get(1).getSource().getFile().getName());
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class ResourceFolderRepositoryTest method testSerializeDensityBasedResourceValues.
public void testSerializeDensityBasedResourceValues() throws Exception {
myFixture.copyFileToProject(STRINGS, "res/values/strings.xml");
myFixture.copyFileToProject(DRAWABLE_ID_SCAN, "res/drawable-hdpi/drawable_foo.xml");
myFixture.copyFileToProject(DRAWABLE_ID_SCAN, "res/drawable-xhdpi/drawable_foo.xml");
myFixture.copyFileToProject(DRAWABLE_ID_SCAN, "res/drawable-fr/drawable_foo.xml");
final ResourceFolderRepository resources = createRepository();
assertNotNull(resources);
FolderConfiguration config = FolderConfiguration.getConfigForFolder("drawable-xhdpi");
assertNotNull(config);
// For drawable xml, the ResourceValue#getValue is the file path.
ResourceValue value = resources.getConfiguredValue(ResourceType.DRAWABLE, "drawable_foo", config);
assertNotNull(value);
String valueString = value.getValue();
assertNotNull(valueString);
assertTrue(valueString.endsWith("drawable_foo.xml"));
assertTrue(valueString.contains("drawable-xhdpi"));
DensityBasedResourceValue densityValue = (DensityBasedResourceValue) value;
assertEquals(Density.XHIGH, densityValue.getResourceDensity());
resources.saveStateToFile();
ResourceFolderRegistry.reset();
final ResourceFolderRepository fromBlob = createRepository();
assertNotNull(fromBlob);
// We don't count files that we explicitly skip against freshness.
assertTrue(fromBlob.hasFreshFileCache());
assertNotSame(resources, fromBlob);
assertTrue(fromBlob.equalFilesItems(resources));
value = fromBlob.getConfiguredValue(ResourceType.DRAWABLE, "drawable_foo", config);
assertNotNull(value);
valueString = value.getValue();
assertNotNull(valueString);
assertTrue(valueString.endsWith("drawable_foo.xml"));
assertTrue(valueString.contains("drawable-xhdpi"));
// Make sure that the resource value is still of type DensityBasedResourceValue.
densityValue = (DensityBasedResourceValue) value;
assertEquals(Density.XHIGH, densityValue.getResourceDensity());
}
Aggregations