Search in sources :

Example 11 with State

use of com.android.sdklib.devices.State in project android by JetBrains.

the class ConfigurationTest method _testCreateSimilar.

public void _testCreateSimilar() throws Exception {
    VirtualFile file1 = myFixture.copyFileToProject(TEST_FILE, "res/layout/layout1.xml");
    VirtualFile file2 = myFixture.copyFileToProject(TEST_FILE, "res/layout-no-rNO/layout1.xml");
    VirtualFile file3 = myFixture.copyFileToProject(TEST_FILE, "res/layout-xlarge-land/layout1.xml");
    myFixture.copyFileToProject(TEST_FILE, "res/layout-en/layout2.xml");
    final AndroidFacet facet = AndroidFacet.getInstance(myModule);
    assertNotNull(facet);
    ConfigurationManager manager = facet.getConfigurationManager();
    assertNotNull(manager);
    assertSame(manager, facet.getConfigurationManager());
    Configuration configuration1 = manager.getConfiguration(file1);
    configuration1.getConfigurationManager().setLocale(Locale.create("en"));
    configuration1.setTheme("Theme.Dialog");
    Device device = manager.getDevices().get(manager.getDevices().size() / 2 - 2);
    State state = device.getAllStates().get(device.getAllStates().size() - 1);
    configuration1.getConfigurationManager().selectDevice(device);
    configuration1.setDeviceStateName(state.getName());
    configuration1.save();
    Configuration configuration2 = manager.createSimilar(file2, file1);
    assertEquals(configuration1.getTheme(), configuration2.getTheme());
    Device device2 = configuration2.getDevice();
    assertEquals(configuration1.getDevice(), device2);
    assertEquals(Locale.create("no-rNO"), configuration2.getLocale());
    assertEquals(Locale.create("en"), configuration1.getLocale());
    State portrait = device.getState("Portrait");
    assertNotNull(portrait);
    configuration1.setDeviceState(portrait);
    Configuration configuration3 = manager.createSimilar(file3, file1);
    assertEquals(configuration1.getTheme(), configuration3.getTheme());
    assertNotSame(configuration3.getDeviceState(), portrait);
    assertEquals("Landscape", configuration3.getDeviceState().getName());
    assertEquals(ScreenSize.XLARGE, configuration3.getDevice().getDefaultHardware().getScreen().getSize());
    assertEquals(configuration1.getLocale(), configuration3.getLocale());
    // Ensure project-wide location switching works: both locales should update
    configuration1.getConfigurationManager().setLocale(Locale.create("no"));
    assertEquals(Locale.create("no"), configuration1.getLocale());
    assertEquals(configuration1.getLocale(), configuration3.getLocale());
}
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) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 12 with State

use of com.android.sdklib.devices.State in project android by JetBrains.

the class OrientationMenuAction method createPopupActionGroup.

@Override
@NotNull
protected DefaultActionGroup createPopupActionGroup() {
    DefaultActionGroup group = new DefaultActionGroup(null, true);
    Configuration configuration = myRenderContext.getConfiguration();
    if (configuration != null) {
        Device device = configuration.getDevice();
        if (device != null) {
            List<State> states = device.getAllStates();
            State current = configuration.getDeviceState();
            if (states.size() > 1 && current != null) {
                State flip = configuration.getNextDeviceState(current);
                State nextSate = flip == null ? current : flip;
                String title = getPresentationDescription(nextSate);
                group.add(new SetDeviceStateAction(myRenderContext, title, nextSate, false, true));
                group.addSeparator();
            }
            for (State config : states) {
                String stateName = config.getName();
                String title = stateName;
                VirtualFile better = ConfigurationMatcher.getBetterMatch(configuration, null, stateName, null, null);
                if (better != null) {
                    title = ConfigurationAction.getBetterMatchLabel(stateName, better, configuration.getFile());
                }
                group.add(new SetDeviceStateAction(myRenderContext, title, config, config == current, false));
            }
            group.addSeparator();
        }
        group.addSeparator();
        DefaultActionGroup uiModeGroup = new DefaultActionGroup("_UI Mode", true);
        UiMode currentUiMode = configuration.getUiMode();
        for (UiMode uiMode : UiMode.values()) {
            String title = uiMode.getShortDisplayValue();
            boolean checked = uiMode == currentUiMode;
            uiModeGroup.add(new SetUiModeAction(myRenderContext, title, uiMode, checked));
        }
        group.add(uiModeGroup);
        group.addSeparator();
        DefaultActionGroup nightModeGroup = new DefaultActionGroup("_Night Mode", true);
        NightMode currentNightMode = configuration.getNightMode();
        for (NightMode nightMode : NightMode.values()) {
            String title = nightMode.getShortDisplayValue();
            boolean checked = nightMode == currentNightMode;
            nightModeGroup.add(new SetNightModeAction(myRenderContext, title, nightMode, checked));
        }
        group.add(nightModeGroup);
    }
    return group;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Device(com.android.sdklib.devices.Device) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) NightMode(com.android.resources.NightMode) UiMode(com.android.resources.UiMode) State(com.android.sdklib.devices.State) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with State

use of com.android.sdklib.devices.State in project android by JetBrains.

the class NestedConfiguration method getDeviceState.

@Override
@Nullable
public State getDeviceState() {
    if (isOverridingDeviceState()) {
        return super.getDeviceState();
    } else {
        State state = myParent.getDeviceState();
        if (isOverridingDevice()) {
            // on our device
            if (state != null) {
                Device device = super.getDevice();
                if (device != null) {
                    String name = state.getName();
                    state = device.getState(name);
                    if (state != null) {
                        return state;
                    }
                    // No such state in this screen
                    // Try to find a *similar* one. For example,
                    // the parent may be "Landscape" and this device
                    // may have "Landscape,Closed" and "Landscape,Open"
                    // as is the case with device "3.2in HGVA slider (ADP1)".
                    int nameLen = name.length();
                    for (State s : device.getAllStates()) {
                        String n = s.getName();
                        if (n.regionMatches(0, name, 0, Math.min(nameLen, n.length()))) {
                            return s;
                        }
                    }
                    return device.getDefaultState();
                }
            }
        }
        return state;
    }
}
Also used : State(com.android.sdklib.devices.State) Device(com.android.sdklib.devices.Device) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with State

use of com.android.sdklib.devices.State in project android by JetBrains.

the class NestedConfiguration method initFrom.

/**
   * Initializes a new {@linkplain NestedConfiguration} with the overriding
   * attributes as the given other {@linkplain NestedConfiguration}, and gets
   * its values from the given {@linkplain Configuration}.
   *
   * @param configuration the configuration to initialize
   * @param other         the configuration to copy overrides from
   * @param values        the configuration to copy values from
   */
protected static void initFrom(NestedConfiguration configuration, NestedConfiguration other, Configuration values) {
    // TODO: Rewrite to use the clone method!
    configuration.startBulkEditing();
    configuration.myOverride = other.myOverride;
    configuration.setDisplayName(values.getDisplayName());
    String activity = values.getActivity();
    if (activity != null) {
        configuration.setActivity(activity);
    }
    if (configuration.isOverridingLocale()) {
        configuration.setLocale(values.getLocale());
    }
    if (configuration.isOverridingTarget()) {
        IAndroidTarget target = values.getTarget();
        if (target != null) {
            configuration.setTarget(target);
        }
    }
    if (configuration.isOverridingDevice()) {
        Device device = values.getDevice();
        if (device != null) {
            configuration.setDevice(device, true);
        }
    }
    if (configuration.isOverridingDeviceState()) {
        State deviceState = values.getDeviceState();
        if (deviceState != null) {
            configuration.setDeviceState(deviceState);
        }
    }
    if (configuration.isOverridingNightMode()) {
        configuration.setNightMode(values.getNightMode());
    }
    if (configuration.isOverridingUiMode()) {
        configuration.setUiMode(values.getUiMode());
    }
    configuration.finishBulkEditing();
}
Also used : Device(com.android.sdklib.devices.Device) State(com.android.sdklib.devices.State) IAndroidTarget(com.android.sdklib.IAndroidTarget)

Example 15 with State

use of com.android.sdklib.devices.State in project android by JetBrains.

the class ConfigureDeviceModel method buildDevice.

/**
   * Once we finish editing the device, we set it to its final configuration
   */
@NotNull
private Device buildDevice() {
    String deviceName = myDeviceData.name().get();
    myBuilder.setName(deviceName);
    myBuilder.setId(deviceName);
    myBuilder.addSoftware(myDeviceData.software().getValue());
    myBuilder.setManufacturer(myDeviceData.manufacturer().get());
    IdDisplay tag = myDeviceData.deviceType().getValueOrNull();
    myBuilder.setTagId((SystemImage.DEFAULT_TAG.equals(tag) || tag == null) ? null : tag.getId());
    List<State> states = generateStates(new AvdHardwareData(myDeviceData).buildHardware());
    myBuilder.addAllState(states);
    return myBuilder.build();
}
Also used : IdDisplay(com.android.sdklib.repository.IdDisplay) State(com.android.sdklib.devices.State) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

State (com.android.sdklib.devices.State)30 Device (com.android.sdklib.devices.Device)20 IAndroidTarget (com.android.sdklib.IAndroidTarget)8 Configuration (com.android.tools.idea.configurations.Configuration)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 Nullable (org.jetbrains.annotations.Nullable)7 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)6 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)5 NotNull (org.jetbrains.annotations.NotNull)5 Module (com.intellij.openapi.module.Module)4 Screen (com.android.sdklib.devices.Screen)3 Locale (com.android.tools.idea.rendering.Locale)3 NightMode (com.android.resources.NightMode)2 UiMode (com.android.resources.UiMode)2 LocalResourceRepository (com.android.tools.idea.res.LocalResourceRepository)2 PsiFile (com.intellij.psi.PsiFile)2 HardwareConfigHelper (com.android.ide.common.rendering.HardwareConfigHelper)1 LayoutLibrary (com.android.ide.common.rendering.LayoutLibrary)1 HardwareConfig (com.android.ide.common.rendering.api.HardwareConfig)1 DensityQualifier (com.android.ide.common.resources.configuration.DensityQualifier)1