android.view.Display.getRotation()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中android.view.Display.getRotation()方法的一些代码示例,展示了Display.getRotation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Display.getRotation()方法的具体详情如下:
包路径:android.view.Display
类名称:Display
方法名:getRotation

Display.getRotation介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

Display display = ((WindowManager) getSystemService(WINDOW_SERVICE))
    .getDefaultDisplay();

int orientation = display.getRotation();

if (orientation == Surface.ROTATION_90
    || orientation == Surface.ROTATION_270) {
  // TODO: add logic for landscape mode here            
}

代码示例来源:origin: stackoverflow.com

Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();

代码示例来源:origin: stackoverflow.com

public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
 {            
   if (isPreviewRunning)
   {
     mCamera.stopPreview();
   }
   Parameters parameters = mCamera.getParameters();
   Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
   if(display.getRotation() == Surface.ROTATION_0)
   {
     parameters.setPreviewSize(height, width);                           
     mCamera.setDisplayOrientation(90);
   }
   if(display.getRotation() == Surface.ROTATION_90)
   {
     parameters.setPreviewSize(width, height);                           
   }
   if(display.getRotation() == Surface.ROTATION_180)
   {
     parameters.setPreviewSize(height, width);               
   }
   if(display.getRotation() == Surface.ROTATION_270)
   {
     parameters.setPreviewSize(width, height);
     mCamera.setDisplayOrientation(180);
   }
   mCamera.setParameters(parameters);
   previewCamera();                      
 }

代码示例来源:origin: libgdx/libgdx

@Override
public int getRotation () {
  int orientation = 0;
  if (context instanceof Activity) {
    orientation = ((Activity)context).getWindowManager().getDefaultDisplay().getRotation();
  } else {
    orientation = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
  }
  switch (orientation) {
  case Surface.ROTATION_0:
    return 0;
  case Surface.ROTATION_90:
    return 90;
  case Surface.ROTATION_180:
    return 180;
  case Surface.ROTATION_270:
    return 270;
  default:
    return 0;
  }
}

代码示例来源:origin: libgdx/libgdx

@Override
public int getRotation () {
  int orientation = 0;
  if (context instanceof Activity) {
    orientation = ((Activity)context).getWindowManager().getDefaultDisplay().getRotation();
  } else {
    orientation = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
  }
  switch (orientation) {
  case Surface.ROTATION_0:
    return 0;
  case Surface.ROTATION_90:
    return 90;
  case Surface.ROTATION_180:
    return 180;
  case Surface.ROTATION_270:
    return 270;
  default:
    return 0;
  }
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

public static boolean getCurrentScreenLand(Activity context) {
    return context.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_90 ||
        context.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_270;

  }
}

代码示例来源:origin: journeyapps/zxing-android-embedded

private int getDisplayRotation() {
  return windowManager.getDefaultDisplay().getRotation();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Returns the current device rotation.
 * Surface.ROTATION_0 = device in natural default rotation
 * Surface.ROTATION_90 = device in rotated 90deg counterclockwise
 * Surface.ROTATION_180 = device in rotated 180deg counterclockwise
 * Surface.ROTATION_270 = device in rotated 270deg counterclockwise
 *
 * When the Manifest locks the orientation, this value will not change during
 * gametime, but if the orientation of the screen is based off the sensor,
 * this value will change as the device is rotated.
 * @return Current device rotation amount
 */
private int getScreenRotation() {
  return windowManager.getDefaultDisplay().getRotation();
}

代码示例来源:origin: florent37/CameraFragment

public static int getDeviceDefaultOrientation(Context context) {
  WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  Configuration config = context.getResources().getConfiguration();
  int rotation = windowManager.getDefaultDisplay().getRotation();
  if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) &&
      config.orientation == Configuration.ORIENTATION_LANDSCAPE)
      || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) &&
      config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
    return Configuration.ORIENTATION_LANDSCAPE;
  } else {
    return Configuration.ORIENTATION_PORTRAIT;
  }
}

代码示例来源:origin: guardianproject/haven

public int getCorrectCameraOrientation(int facing, int orientation) {
  int rotation = context.getWindowManager().getDefaultDisplay().getRotation();
  int degrees = 0;
  switch(rotation){
    case Surface.ROTATION_0:
      degrees = 0;
      break;
    case Surface.ROTATION_90:
      degrees = 90;
      break;
    case Surface.ROTATION_180:
      degrees = 180;
      break;
    case Surface.ROTATION_270:
      degrees = 270;
      break;
  }
  int result;
  if(facing == CameraView.FACING_FRONT){
    result = (orientation + degrees) % 360;
    result = (360 - result) % 360;
  }else{
    result = (orientation - degrees + 360) % 360;
  }
  return result;
}

代码示例来源:origin: ACRA/acra

private void collectRotation(@NonNull Display display, JSONObject container) throws JSONException {
  container.put("rotation", rotationToString(display.getRotation()));
}

代码示例来源:origin: journeyapps/zxing-android-embedded

@Override
  public void onOrientationChanged(int orientation) {
    WindowManager localWindowManager = windowManager;
    RotationCallback localCallback = RotationListener.this.callback;
    if(windowManager != null && localCallback != null) {
      int newRotation = localWindowManager.getDefaultDisplay().getRotation();
      if (newRotation != lastRotation) {
        lastRotation = newRotation;
        localCallback.onRotationChanged(newRotation);
      }
    }
  }
};

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

private int getCurrentOrientation() {
  int rotation = getWindowManager().getDefaultDisplay().getRotation();
  switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_90:
      return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    default:
      return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
  }
}

代码示例来源:origin: square/assertj-android

@TargetApi(FROYO)
public DisplayAssert hasRotation(int rotation) {
 isNotNull();
 int actualRotation = actual.getRotation();
 assertThat(actualRotation) //
   .overridingErrorMessage("Expected rotation <%s> but was <%s>", rotation, actualRotation) //
   .isEqualTo(rotation);
 return this;
}

代码示例来源:origin: vondear/RxTool

@Override
  public void onOrientationChanged(int orientation) {
    if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN ||
        mDisplay == null) {
      return;
    }
    final int rotation = mDisplay.getRotation();
    if (mLastKnownRotation != rotation) {
      mLastKnownRotation = rotation;
      dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(rotation));
    }
  }
};

代码示例来源:origin: google/cameraview

@Override
  public void onOrientationChanged(int orientation) {
    if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN ||
        mDisplay == null) {
      return;
    }
    final int rotation = mDisplay.getRotation();
    if (mLastKnownRotation != rotation) {
      mLastKnownRotation = rotation;
      dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(rotation));
    }
  }
};

代码示例来源:origin: daniulive/SmarterStreaming

public void onConfigurationChanged(Configuration newConfig) {
  try {
    super.onConfigurationChanged(newConfig);
    Log.i(TAG, "onConfigurationChanged");
    if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
      if (!isRTSPPublisherRunning && !isPushingRtmp && !isRecording && !isPushingRtsp) {
        int rotation = getWindowManager().getDefaultDisplay().getRotation();
        if (Surface.ROTATION_270 == rotation) {
          Log.i(TAG, "onConfigurationChanged rotation=" + rotation + " LANDSCAPE_LEFT_HOME_KEY");
          currentOrigentation = LANDSCAPE_LEFT_HOME_KEY;
        } else {
          Log.i(TAG, "onConfigurationChanged rotation=" + rotation + " LANDSCAPE");
          currentOrigentation = LANDSCAPE;
        }
      }
    } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
      if (!isRTSPPublisherRunning && !isPushingRtmp && !isRecording && !isPushingRtsp) {
        currentOrigentation = PORTRAIT;
      }
    }
  } catch (Exception ex) {
  }
}

代码示例来源:origin: vondear/RxTool

public void enable(Display display) {
  mDisplay = display;
  mOrientationEventListener.enable();
  // Immediately dispatch the first callback
  dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(display.getRotation()));
}

代码示例来源:origin: google/cameraview

public void enable(Display display) {
  mDisplay = display;
  mOrientationEventListener.enable();
  // Immediately dispatch the first callback
  dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(display.getRotation()));
}

代码示例来源:origin: ACRA/acra

@NonNull
private JSONObject collectDisplayData(@NonNull Display display) throws JSONException {
  final DisplayMetrics metrics = new DisplayMetrics();
  display.getMetrics(metrics);
  final JSONObject result = new JSONObject();
  collectCurrentSizeRange(display, result);
  collectFlags(display, result);
  collectMetrics(display, result);
  collectRealMetrics(display, result);
  collectName(display, result);
  collectRealSize(display, result);
  collectRectSize(display, result);
  collectSize(display, result);
  collectRotation(display, result);
  collectIsValid(display, result);
  result.put("orientation", display.getRotation())
      .put("refreshRate", display.getRefreshRate());
  //noinspection deprecation
  result.put("height", display.getHeight())
      .put("width", display.getWidth())
      .put("pixelFormat", display.getPixelFormat());
  return result;
}

相关文章