Search in sources :

Example 16 with ScreenOrientation

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

the class CanvasResizeInteraction method coveredAreaForConfig.

/**
   * Returns the {@link Area} of the {@link ScreenView} that is covered by the given {@link FolderConfiguration}
   */
@SuppressWarnings("SuspiciousNameCombination")
@NotNull
private Area coveredAreaForConfig(@NotNull FolderConfiguration config, @NotNull ScreenView screenView) {
    int x0 = screenView.getX();
    int y0 = screenView.getY();
    JComponent layeredPane = myDesignSurface.getLayeredPane();
    int width = layeredPane.getWidth();
    int height = layeredPane.getHeight();
    int maxDim = Math.max(width, height);
    int minX = 0;
    int maxX = -1;
    int minY = 0;
    int maxY = -1;
    int dpi = screenView.getConfiguration().getDensity().getDpiValue();
    SmallestScreenWidthQualifier smallestWidthQualifier = config.getSmallestScreenWidthQualifier();
    if (smallestWidthQualifier != null) {
        // Restrict the area due to a sw<N>dp qualifier
        minX = smallestWidthQualifier.getValue() * dpi / 160;
        minY = smallestWidthQualifier.getValue() * dpi / 160;
    }
    ScreenWidthQualifier widthQualifier = config.getScreenWidthQualifier();
    if (widthQualifier != null) {
        // Restrict the area due to a w<N>dp qualifier
        minX = Math.max(minX, widthQualifier.getValue() * dpi / 160);
    }
    ScreenHeightQualifier heightQualifier = config.getScreenHeightQualifier();
    if (heightQualifier != null) {
        // Restrict the area due to a h<N>dp qualifier
        minY = Math.max(minY, heightQualifier.getValue() * dpi / 160);
    }
    ScreenSizeQualifier sizeQualifier = config.getScreenSizeQualifier();
    if (sizeQualifier != null && sizeQualifier.getValue() != null) {
        // Restrict the area due to a screen size qualifier (SMALL, NORMAL, LARGE, XLARGE)
        switch(sizeQualifier.getValue()) {
            case SMALL:
                maxX = 320 * dpi / 160;
                maxY = 470 * dpi / 160;
                break;
            case NORMAL:
                break;
            case LARGE:
                minX = 480 * dpi / 160;
                minY = 640 * dpi / 160;
                break;
            case XLARGE:
                minX = 720 * dpi / 160;
                minY = 960 * dpi / 160;
                break;
        }
    }
    ScreenRatioQualifier ratioQualifier = config.getScreenRatioQualifier();
    ScreenRatio ratio = ratioQualifier != null ? ratioQualifier.getValue() : null;
    ScreenOrientationQualifier orientationQualifier = config.getScreenOrientationQualifier();
    ScreenOrientation orientation = orientationQualifier != null ? orientationQualifier.getValue() : null;
    Polygon portrait = new Polygon();
    Polygon landscape = new Polygon();
    if (orientation == null || orientation.equals(ScreenOrientation.PORTRAIT)) {
        constructPolygon(portrait, ratio, maxDim, true);
        portrait.translate(x0, y0);
    }
    if (orientation == null || orientation.equals(ScreenOrientation.LANDSCAPE)) {
        constructPolygon(landscape, ratio, maxDim, false);
        landscape.translate(x0, y0);
    }
    Area portraitArea = new Area(portrait);
    Area landscapeArea = new Area(landscape);
    Area portraitBounds = new Area(new Rectangle(Coordinates.getSwingX(screenView, minX), Coordinates.getSwingY(screenView, minY), maxX >= 0 ? Coordinates.getSwingDimension(screenView, maxX - minX) : width, maxY >= 0 ? Coordinates.getSwingDimension(screenView, maxY - minY) : height));
    Area landscapeBounds = new Area(new Rectangle(Coordinates.getSwingX(screenView, minY), Coordinates.getSwingY(screenView, minX), maxY >= 0 ? Coordinates.getSwingDimension(screenView, maxY - minY) : width, maxX >= 0 ? Coordinates.getSwingDimension(screenView, maxX - minX) : height));
    portraitArea.intersect(portraitBounds);
    landscapeArea.intersect(landscapeBounds);
    portraitArea.add(landscapeArea);
    return portraitArea;
}
Also used : ScreenRatio(com.android.resources.ScreenRatio) ScreenOrientation(com.android.resources.ScreenOrientation) Area(java.awt.geom.Area) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with ScreenOrientation

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

the class IconPreviewFactory method getPreviewCacheDirForConfiguration.

@NotNull
private static File getPreviewCacheDirForConfiguration(@NotNull Configuration configuration) {
    int density = configuration.getDensity().getDpiValue();
    State state = configuration.getDeviceState();
    Screen screen = state != null ? state.getHardware().getScreen() : null;
    int xDimension = DEFAULT_X_DIMENSION;
    int yDimension = DEFAULT_Y_DIMENSION;
    if (screen != null) {
        xDimension = screen.getXDimension();
        yDimension = screen.getYDimension();
        density = screen.getPixelDensity().getDpiValue();
    }
    ScreenOrientation orientation = state != null ? state.getOrientation() : ScreenOrientation.PORTRAIT;
    if ((orientation == ScreenOrientation.LANDSCAPE && xDimension < yDimension) || (orientation == ScreenOrientation.PORTRAIT && xDimension > yDimension)) {
        int temp = xDimension;
        //noinspection SuspiciousNameCombination
        xDimension = yDimension;
        yDimension = temp;
    }
    String theme = getTheme(configuration);
    String apiVersion = getApiVersion(configuration);
    String cacheFolder = theme + File.separator + xDimension + "x" + yDimension + "-" + density + "-" + apiVersion;
    return new File(getPreviewCacheDir(), cacheFolder);
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation) State(com.android.sdklib.devices.State) Screen(com.android.sdklib.devices.Screen) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

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