Search in sources :

Example 1 with ScreenOrientation

use of com.android.resources.ScreenOrientation in project android_frameworks_base by DirtyUnicorns.

the class RenderAction method getConfiguration.

// VisibleForTesting
public static Configuration getConfiguration(RenderParams params) {
    Configuration config = new Configuration();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    ScreenSize screenSize = hardwareConfig.getScreenSize();
    if (screenSize != null) {
        switch(screenSize) {
            case SMALL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL;
                break;
            case NORMAL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL;
                break;
            case LARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE;
                break;
            case XLARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE;
                break;
        }
    }
    Density density = hardwareConfig.getDensity();
    if (density == null) {
        density = Density.MEDIUM;
    }
    config.screenWidthDp = hardwareConfig.getScreenWidth() / density.getDpiValue();
    config.screenHeightDp = hardwareConfig.getScreenHeight() / density.getDpiValue();
    if (config.screenHeightDp < config.screenWidthDp) {
        //noinspection SuspiciousNameCombination
        config.smallestScreenWidthDp = config.screenHeightDp;
    } else {
        config.smallestScreenWidthDp = config.screenWidthDp;
    }
    config.densityDpi = density.getDpiValue();
    // never run in compat mode:
    config.compatScreenWidthDp = config.screenWidthDp;
    config.compatScreenHeightDp = config.screenHeightDp;
    ScreenOrientation orientation = hardwareConfig.getOrientation();
    if (orientation != null) {
        switch(orientation) {
            case PORTRAIT:
                config.orientation = Configuration.ORIENTATION_PORTRAIT;
                break;
            case LANDSCAPE:
                config.orientation = Configuration.ORIENTATION_LANDSCAPE;
                break;
            case SQUARE:
                //noinspection deprecation
                config.orientation = Configuration.ORIENTATION_SQUARE;
                break;
        }
    } else {
        config.orientation = Configuration.ORIENTATION_UNDEFINED;
    }
    ScreenRound roundness = hardwareConfig.getScreenRoundness();
    if (roundness != null) {
        switch(roundness) {
            case ROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
                break;
            case NOTROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_NO;
        }
    } else {
        config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_UNDEFINED;
    }
    String locale = params.getLocale();
    if (locale != null && !locale.isEmpty())
        config.locale = new Locale(locale);
    return config;
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation) Locale(java.util.Locale) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) Configuration(android.content.res.Configuration) ScreenSize(com.android.resources.ScreenSize) Density(com.android.resources.Density) ScreenRound(com.android.resources.ScreenRound)

Example 2 with ScreenOrientation

use of com.android.resources.ScreenOrientation in project android_frameworks_base by ResurrectionRemix.

the class RenderAction method getConfiguration.

// VisibleForTesting
public static Configuration getConfiguration(RenderParams params) {
    Configuration config = new Configuration();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    ScreenSize screenSize = hardwareConfig.getScreenSize();
    if (screenSize != null) {
        switch(screenSize) {
            case SMALL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL;
                break;
            case NORMAL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL;
                break;
            case LARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE;
                break;
            case XLARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE;
                break;
        }
    }
    Density density = hardwareConfig.getDensity();
    if (density == null) {
        density = Density.MEDIUM;
    }
    config.screenWidthDp = hardwareConfig.getScreenWidth() / density.getDpiValue();
    config.screenHeightDp = hardwareConfig.getScreenHeight() / density.getDpiValue();
    if (config.screenHeightDp < config.screenWidthDp) {
        //noinspection SuspiciousNameCombination
        config.smallestScreenWidthDp = config.screenHeightDp;
    } else {
        config.smallestScreenWidthDp = config.screenWidthDp;
    }
    config.densityDpi = density.getDpiValue();
    // never run in compat mode:
    config.compatScreenWidthDp = config.screenWidthDp;
    config.compatScreenHeightDp = config.screenHeightDp;
    ScreenOrientation orientation = hardwareConfig.getOrientation();
    if (orientation != null) {
        switch(orientation) {
            case PORTRAIT:
                config.orientation = Configuration.ORIENTATION_PORTRAIT;
                break;
            case LANDSCAPE:
                config.orientation = Configuration.ORIENTATION_LANDSCAPE;
                break;
            case SQUARE:
                //noinspection deprecation
                config.orientation = Configuration.ORIENTATION_SQUARE;
                break;
        }
    } else {
        config.orientation = Configuration.ORIENTATION_UNDEFINED;
    }
    ScreenRound roundness = hardwareConfig.getScreenRoundness();
    if (roundness != null) {
        switch(roundness) {
            case ROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
                break;
            case NOTROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_NO;
        }
    } else {
        config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_UNDEFINED;
    }
    String locale = params.getLocale();
    if (locale != null && !locale.isEmpty())
        config.locale = new Locale(locale);
    return config;
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation) Locale(java.util.Locale) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) Configuration(android.content.res.Configuration) ScreenSize(com.android.resources.ScreenSize) Density(com.android.resources.Density) ScreenRound(com.android.resources.ScreenRound)

Example 3 with ScreenOrientation

use of com.android.resources.ScreenOrientation in project android by JetBrains.

the class ScreenshotViewer method getDescriptorsToFrame.

// returns the list of descriptors capable of framing the given image
private static List<DeviceArtDescriptor> getDescriptorsToFrame(final BufferedImage image) {
    double imgAspectRatio = image.getWidth() / (double) image.getHeight();
    final ScreenOrientation orientation = imgAspectRatio >= (1 - ImageUtils.EPSILON) ? ScreenOrientation.LANDSCAPE : ScreenOrientation.PORTRAIT;
    List<DeviceArtDescriptor> allDescriptors = DeviceArtDescriptor.getDescriptors(null);
    return ContainerUtil.filter(allDescriptors, descriptor -> {
        return descriptor.canFrameImage(image, orientation);
    });
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation)

Example 4 with ScreenOrientation

use of com.android.resources.ScreenOrientation in project android by JetBrains.

the class ConfigureAvdOptionsStep method createUIComponents.

private void createUIComponents() {
    Function<ScreenOrientation, Image> orientationIconFunction = new Function<ScreenOrientation, Image>() {

        @Override
        public Image apply(ScreenOrientation input) {
            return IconUtil.toImage(ORIENTATIONS.get(input).myIcon);
        }
    };
    Function<ScreenOrientation, String> orientationNameFunction = new Function<ScreenOrientation, String>() {

        @Override
        public String apply(ScreenOrientation input) {
            return ORIENTATIONS.get(input).myName;
        }
    };
    myOrientationToggle = new ASGallery<ScreenOrientation>(JBList.createDefaultListModel(ScreenOrientation.PORTRAIT, ScreenOrientation.LANDSCAPE), orientationIconFunction, orientationNameFunction, JBUI.size(50, 50), null);
    myOrientationToggle.setCellMargin(JBUI.insets(5, 20, 4, 20));
    myOrientationToggle.setBackground(JBColor.background());
    myOrientationToggle.setForeground(JBColor.foreground());
    myHardwareSkinHelpLabel = new HyperlinkLabel("How do I create a custom hardware skin?");
    myHardwareSkinHelpLabel.setHyperlinkTarget(AvdWizardUtils.CREATE_SKIN_HELP_LINK);
    mySkinComboBox = new SkinChooser(myProject, true);
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation) Function(com.google.common.base.Function) SystemImage(com.android.sdklib.repository.targets.SystemImage) HyperlinkLabel(com.intellij.ui.HyperlinkLabel)

Example 5 with ScreenOrientation

use of com.android.resources.ScreenOrientation in project android by JetBrains.

the class DeviceArtDescriptorTest method test1.

public void test1() throws IOException {
    List<DeviceArtDescriptor> specs = DeviceArtDescriptor.getDescriptors(null);
    assertEquals(22, specs.size());
    DeviceArtDescriptor nexus4 = getDescriptorFor("nexus_4", specs);
    assertNotNull(nexus4);
    Point offsets = nexus4.getScreenPos(ScreenOrientation.PORTRAIT);
    assertEquals(94, offsets.x);
    assertEquals(187, offsets.y);
    offsets = nexus4.getScreenPos(ScreenOrientation.LANDSCAPE);
    assertEquals(257, offsets.x);
    assertEquals(45, offsets.y);
    verifyFileExists(nexus4.getFrame(ScreenOrientation.LANDSCAPE));
    verifyFileExists(nexus4.getFrame(ScreenOrientation.PORTRAIT));
    verifyFileExists(nexus4.getDropShadow(ScreenOrientation.LANDSCAPE));
    verifyFileExists(nexus4.getDropShadow(ScreenOrientation.PORTRAIT));
    verifyFileExists(nexus4.getReflectionOverlay(ScreenOrientation.LANDSCAPE));
    verifyFileExists(nexus4.getReflectionOverlay(ScreenOrientation.PORTRAIT));
    for (DeviceArtDescriptor descriptor : specs) {
        String id = descriptor.getId();
        assertNotNull(id);
        assertNotNull(descriptor.getName());
        for (ScreenOrientation orientation : new ScreenOrientation[] { ScreenOrientation.LANDSCAPE, ScreenOrientation.PORTRAIT }) {
            if (orientation == ScreenOrientation.PORTRAIT && id.startsWith("tv_")) {
                continue;
            }
            assertNotNull(id, descriptor.getFrameSize(orientation));
            assertNotNull(id, descriptor.getScreenPos(orientation));
            assertNotNull(id, descriptor.getScreenSize(orientation));
            // We've pre-subtracted the crop everywhere now
            assertNull(descriptor.getCrop(orientation));
            assertTrue(id, descriptor.getFrame(orientation).exists());
            assertTrue(id, descriptor.getDropShadow(orientation).exists());
            File reflectionOverlay = descriptor.getReflectionOverlay(orientation);
            if (reflectionOverlay != null) {
                assertTrue(id, reflectionOverlay.exists());
            }
            verifyCompatibleImage(descriptor.getFrame(orientation));
            verifyCompatibleImage(descriptor.getDropShadow(orientation));
            verifyCompatibleImage(descriptor.getReflectionOverlay(orientation));
            verifyCompatibleImage(descriptor.getMask(orientation));
        }
    }
    DeviceArtDescriptor generic_phone = getDescriptorFor("phone", specs);
    assertNull(generic_phone.getReflectionOverlay(ScreenOrientation.LANDSCAPE));
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation) File(java.io.File)

Aggregations

ScreenOrientation (com.android.resources.ScreenOrientation)17 File (java.io.File)7 Configuration (android.content.res.Configuration)6 HardwareConfig (com.android.ide.common.rendering.api.HardwareConfig)6 Density (com.android.resources.Density)6 ScreenSize (com.android.resources.ScreenSize)6 ScreenRound (com.android.resources.ScreenRound)5 Locale (java.util.Locale)5 NotNull (org.jetbrains.annotations.NotNull)4 Device (com.android.sdklib.devices.Device)2 Function (com.google.common.base.Function)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 DeviceSchemaTest (com.android.dvlib.DeviceSchemaTest)1 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1 ScreenRatio (com.android.resources.ScreenRatio)1 ISystemImage (com.android.sdklib.ISystemImage)1 Screen (com.android.sdklib.devices.Screen)1 State (com.android.sdklib.devices.State)1 Storage (com.android.sdklib.devices.Storage)1 GpuMode (com.android.sdklib.internal.avd.GpuMode)1