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 }
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int rotation = display.getRotation();
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(); }
@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; } }
@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; } }
public static boolean getCurrentScreenLand(Activity context) { return context.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_90 || context.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_270; } }
private int getDisplayRotation() { return windowManager.getDefaultDisplay().getRotation(); }
/** * 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(); }
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; } }
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; }
private void collectRotation(@NonNull Display display, JSONObject container) throws JSONException { container.put("rotation", rotationToString(display.getRotation())); }
@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); } } } };
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; } }
@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; }
@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)); } } };
@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)); } } };
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) { } }
public void enable(Display display) { mDisplay = display; mOrientationEventListener.enable(); // Immediately dispatch the first callback dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(display.getRotation())); }
public void enable(Display display) { mDisplay = display; mOrientationEventListener.enable(); // Immediately dispatch the first callback dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(display.getRotation())); }
@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; }