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;
}
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);
}
Aggregations