Search in sources :

Example 36 with FolderConfiguration

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?
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Device(com.android.sdklib.devices.Device) State(com.android.sdklib.devices.State) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 37 with FolderConfiguration

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);
}
Also used : VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) IAndroidTarget(com.android.sdklib.IAndroidTarget) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 38 with FolderConfiguration

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()));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Example 39 with FolderConfiguration

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;
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Example 40 with FolderConfiguration

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;
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) ResourceResolver(com.android.ide.common.resources.ResourceResolver) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Aggregations

FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)69 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 NotNull (org.jetbrains.annotations.NotNull)14 VersionQualifier (com.android.ide.common.resources.configuration.VersionQualifier)12 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)12 Nullable (org.jetbrains.annotations.Nullable)12 ResourceItem (com.android.ide.common.res2.ResourceItem)10 LocaleQualifier (com.android.ide.common.resources.configuration.LocaleQualifier)10 DensityQualifier (com.android.ide.common.resources.configuration.DensityQualifier)9 ResourceFolderType (com.android.resources.ResourceFolderType)9 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)7 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 Project (com.intellij.openapi.project.Project)7 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)6 ResourceResolver (com.android.ide.common.resources.ResourceResolver)6 LayoutDirectionQualifier (com.android.ide.common.resources.configuration.LayoutDirectionQualifier)6 ScreenOrientationQualifier (com.android.ide.common.resources.configuration.ScreenOrientationQualifier)6 ScreenSizeQualifier (com.android.ide.common.resources.configuration.ScreenSizeQualifier)6 SessionParams (com.android.ide.common.rendering.api.SessionParams)5 CountryCodeQualifier (com.android.ide.common.resources.configuration.CountryCodeQualifier)5