use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class NestedConfigurationTest method test.
public void test() throws Exception {
VirtualFile file = myFixture.copyFileToProject(TEST_FILE, "res/layout/layout1.xml");
final AndroidFacet facet = AndroidFacet.getInstance(myModule);
assertNotNull(facet);
ConfigurationManager manager = facet.getConfigurationManager();
assertNotNull(manager);
assertSame(manager, facet.getConfigurationManager());
Configuration parent = Configuration.create(manager, file, new FolderConfiguration());
assertNotNull(parent);
parent.startBulkEditing();
parent.setDisplayName("myconfig");
parent.setTheme("@style/Theme1");
parent.setNightMode(NightMode.NIGHT);
parent.setActivity("tes.tpkg.MyActivity1");
parent.setUiMode(UiMode.TELEVISION);
IAndroidTarget target = parent.getConfigurationManager().getTarget();
Device device = parent.getConfigurationManager().getDefaultDevice();
State deviceState = device != null ? device.getState("Portrait") : null;
if (target != null) {
parent.setTarget(target);
}
if (device != null) {
parent.setDevice(device, false);
assertNotNull(deviceState);
parent.setDeviceState(deviceState);
}
parent.setLocale(Locale.create("en-rUS"));
parent.finishBulkEditing();
NestedConfiguration configuration = NestedConfiguration.create(parent);
// Inherit locale
assertFalse(configuration.isOverridingLocale());
parent.setLocale(Locale.create("en-rUS"));
assertEquals(Locale.create("en-rUS"), configuration.getLocale());
parent.setLocale(Locale.create("de"));
assertEquals(Locale.create("de"), configuration.getLocale());
// Override locale
configuration.setOverrideLocale(true);
assertTrue(configuration.isOverridingLocale());
configuration.setLocale(Locale.create("no"));
assertEquals(Locale.create("no"), configuration.getLocale());
parent.setLocale(Locale.create("es"));
assertEquals(Locale.create("no"), configuration.getLocale());
// Inherit UI mode
assertFalse(configuration.isOverridingUiMode());
parent.setUiMode(UiMode.DESK);
assertSame(UiMode.DESK, configuration.getUiMode());
parent.setUiMode(UiMode.APPLIANCE);
assertSame(UiMode.APPLIANCE, configuration.getUiMode());
// Override UI mode
configuration.setOverrideUiMode(true);
assertTrue(configuration.isOverridingUiMode());
configuration.setUiMode(UiMode.CAR);
assertSame(UiMode.CAR, configuration.getUiMode());
parent.setUiMode(UiMode.DESK);
assertSame(UiMode.CAR, configuration.getUiMode());
// Inherit orientation
assertNotNull(device);
State portrait = device.getState("Portrait");
State landscape = device.getState("Landscape");
assertNotNull(portrait);
assertNotNull(landscape);
assertFalse(configuration.isOverridingDeviceState());
assertEquals(ScreenOrientation.PORTRAIT, configuration.getFullConfig().getScreenOrientationQualifier().getValue());
parent.setDeviceState(landscape);
assertEquals(ScreenOrientation.LANDSCAPE, configuration.getFullConfig().getScreenOrientationQualifier().getValue());
assertEquals(landscape, configuration.getDeviceState());
parent.setDeviceState(portrait);
assertEquals(portrait, configuration.getDeviceState());
// Override orientation
configuration.setOverrideDeviceState(true);
assertTrue(configuration.isOverridingDeviceState());
configuration.setDeviceState(landscape);
assertEquals(landscape, configuration.getDeviceState());
parent.setDeviceState(landscape);
parent.setDeviceState(portrait);
assertEquals(landscape, configuration.getDeviceState());
// TODO: Inherit device -- with overridden state
// TODO: Test listener; I should NOT fire when a parent changes an attribute I don't
// care about!!
// Also test that calling the setters are firing events, clear resources, etc
// In order for this to work, I would need to have listeners attach and detach... How
// can I do this?
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class ConfigurationTest method testTargetSpecificFolder.
public void testTargetSpecificFolder() throws Exception {
final AndroidFacet facet = AndroidFacet.getInstance(myModule);
assertNotNull(facet);
ConfigurationManager manager = facet.getConfigurationManager();
assertNotNull(manager);
assertSame(manager, facet.getConfigurationManager());
for (IAndroidTarget target : manager.getTargets()) {
if (ConfigurationManager.isLayoutLibTarget(target)) {
manager.setTarget(target);
break;
}
}
FolderConfiguration folderConfig = new FolderConfiguration();
folderConfig.setVersionQualifier(new VersionQualifier(11));
Configuration configuration = Configuration.create(manager, null, folderConfig);
assertNotNull(configuration);
IAndroidTarget target = configuration.getTarget();
assertNotNull(target);
assertTrue(target.getVersion().getFeatureLevel() >= 11);
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class WidgetCreator method createColorResource.
/**
* Create a color resource with the provided name and color.
*
* IF the color name is empty, the method won't create the resource and won't throw any exception
*
* @param colorName The name for the color value
* @param color The value for the resource
* @param model
*/
protected static void createColorResource(@NotNull String colorName, @NotNull Color color, @NotNull NlModel model) {
if (colorName.isEmpty()) {
Logger.getInstance(FloatingActionButtonCreator.class).error("The color name can't be empty. Aborting color resource creation");
return;
}
VirtualFile primaryResourceDir = model.getFacet().getPrimaryResourceDir();
FolderConfiguration configForFolder = FolderConfiguration.getConfigForFolder(ResourceFolderType.VALUES.getName());
if (primaryResourceDir != null && configForFolder != null) {
AndroidResourceUtil.createValueResource(model.getProject(), primaryResourceDir, colorName, ResourceType.COLOR, COLORS_XML, Collections.singletonList(configForFolder.getFolderName(ResourceFolderType.VALUES)), // write the color value in hex format (#RRGGBB)
String.format("#%06X", color.getRGB()));
}
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class LayoutTestUtilities method createScreen.
public static ScreenView createScreen(DesignSurface surface, NlModel model, SelectionModel selectionModel, double scale, @SwingCoordinate int x, @SwingCoordinate int y, Density density) {
Configuration configuration = mock(Configuration.class);
when(configuration.getDensity()).thenReturn(density);
when(configuration.getFile()).thenReturn(model.getFile().getVirtualFile());
when(configuration.getFullConfig()).thenReturn(new FolderConfiguration());
ScreenView screenView = mock(ScreenView.class);
when(screenView.getConfiguration()).thenReturn(configuration);
when(screenView.getModel()).thenReturn(model);
when(screenView.getScale()).thenReturn(scale);
when(screenView.getSelectionModel()).thenReturn(selectionModel);
when(screenView.getSize()).thenReturn(new Dimension());
when(screenView.getSurface()).thenReturn(surface);
when(screenView.getX()).thenReturn(x);
when(screenView.getY()).thenReturn(y);
when(surface.getScreenView(anyInt(), anyInt())).thenReturn(screenView);
return screenView;
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project platform_frameworks_base by android.
the class Main method getSessionParams.
/**
* Uses Theme.Material and Target sdk version as 22.
*/
private SessionParams getSessionParams(LayoutPullParser layoutParser, ConfigGenerator configGenerator, LayoutLibTestCallback layoutLibCallback, String themeName, boolean isProjectTheme, RenderingMode renderingMode, int targetSdk) {
FolderConfiguration config = configGenerator.getFolderConfig();
ResourceResolver resourceResolver = ResourceResolver.create(sProjectResources.getConfiguredResources(config), sFrameworkRepo.getConfiguredResources(config), themeName, isProjectTheme);
SessionParams sessionParams = new SessionParams(layoutParser, renderingMode, null, /*used for caching*/
configGenerator.getHardwareConfig(), resourceResolver, layoutLibCallback, 0, targetSdk, getLayoutLog());
sessionParams.setFlag(RenderParamsFlags.FLAG_DO_NOT_RENDER_ON_CREATE, true);
return sessionParams;
}
Aggregations