private void updateSize() { Device device = mConfiguration.getDevice(); if (device == null) { return; } Screen screen = device.getDefaultHardware().getScreen(); if (screen == null) { return; } FolderConfiguration folderConfig = mConfiguration.getFullConfig(); ScreenOrientationQualifier qualifier = folderConfig.getScreenOrientationQualifier(); ScreenOrientation orientation = qualifier == null ? ScreenOrientation.PORTRAIT : qualifier.getValue(); // compute width and height to take orientation into account. int x = screen.getXDimension(); int y = screen.getYDimension(); int screenWidth, screenHeight; if (x > y) { if (orientation == ScreenOrientation.LANDSCAPE) { screenWidth = x; screenHeight = y; } else { screenWidth = y; screenHeight = x; } } else { if (orientation == ScreenOrientation.LANDSCAPE) { screenWidth = y; screenHeight = x; } else { screenWidth = x; screenHeight = y; } } int width = RenderPreviewManager.getMaxWidth(); int height = RenderPreviewManager.getMaxHeight(); if (screenWidth > 0) { double scale = getScale(screenWidth, screenHeight); width = (int) (screenWidth * scale); height = (int) (screenHeight * scale); } if (width != mWidth || height != mHeight) { mWidth = width; mHeight = height; Image thumbnail = mThumbnail; mThumbnail = null; if (thumbnail != null) { thumbnail.dispose(); } if (mHeight != 0) { mAspectRatio = mWidth / (double) mHeight; } } }
@Nullable private static String getResolutionString(Device device) { Screen screen = device.getDefaultHardware().getScreen(); return String.format( java.util.Locale.US, "%1$d \u00D7 %2$d: %3$s", // U+00D7: Unicode multiplication sign screen.getXDimension(), screen.getYDimension(), screen.getPixelDensity().getResourceValue()); }
private static String getNexusLabel(Device d) { String name = d.getName(); Screen screen = d.getDefaultHardware().getScreen(); float length = (float) screen.getDiagonalLength(); return String.format( java.util.Locale.US, "%1$s (%3$s\", %2$s)", name, getResolutionString(d), Float.toString(length)); }
boolean computeAndSetRealScale(boolean redraw) { // compute average dpi of X and Y ConfigurationChooser chooser = mEditor.getConfigurationChooser(); Configuration config = chooser.getConfiguration(); Device device = config.getDevice(); Screen screen = device.getDefaultHardware().getScreen(); double dpi = (screen.getXdpi() + screen.getYdpi()) / 2.; // get the monitor dpi float monitor = AdtPrefs.getPrefs().getMonitorDensity(); if (monitor == 0.f) { ResolutionChooserDialog dialog = new ResolutionChooserDialog(chooser.getShell()); if (dialog.open() == Window.OK) { monitor = dialog.getDensity(); AdtPrefs.getPrefs().setMonitorDensity(monitor); } else { return false; } } mEditor.getCanvasControl().setScale(monitor / dpi, redraw); return true; }
/** * Returns a copy of the object that shares no state with it, but is initialized to equivalent * values. * * @return A copy of the object. */ public Screen deepCopy() { Screen s = new Screen(); s.mScreenSize = mScreenSize; s.mDiagonalLength = mDiagonalLength; s.mPixelDensity = mPixelDensity; s.mScreenRatio = mScreenRatio; s.mXDimension = mXDimension; s.mYDimension = mYDimension; s.mXdpi = mXdpi; s.mYdpi = mYdpi; s.mMultitouch = mMultitouch; s.mMechanism = mMechanism; s.mScreenType = mScreenType; s.mScreenRound = mScreenRound; return s; }