예제 #1
0
  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());
 }