List of usage examples for android.view Surface ROTATION_270
int ROTATION_270
To view the source code for android.view Surface ROTATION_270.
Click Source Link
From source file:Main.java
/** * Untested, taken from stack-overflow./*from ww w . ja va 2 s . c o m*/ * * @param activity */ public static void disableScreenOrientationChange(Activity activity) { final int orientation = activity.getResources().getConfiguration().orientation; final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } }
From source file:Main.java
public static int getPortraitCamearaDisplayOrientation(Context context, int cameraId, boolean isFrontCamera) { if (cameraId < 0 || cameraId > getCameraNumber()) { return -1; }/*from w w w .ja va2 s. c o m*/ Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int rotation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).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 (isFrontCamera) { result = (cameraInfo.orientation + degrees) % 360; result = (360 - result) % 360; } else { result = (cameraInfo.orientation - degrees + 360) % 360; } return result; }
From source file:Main.java
public static int getDisplayRotation(Activity activity) { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); switch (rotation) { case Surface.ROTATION_0: return 0; case Surface.ROTATION_90: return 90; case Surface.ROTATION_180: return 180; case Surface.ROTATION_270: return 270; }/* w w w. j ava2s . c o m*/ return 0; }
From source file:Main.java
static int calculateOrientation(Activity activity, int cameraId) { if (cameraId == NO_CAMERA) return 0; DisplayMetrics dm = new DisplayMetrics(); Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int cameraRotationOffset = info.orientation; activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int currentScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (currentScreenRotation) { case Surface.ROTATION_0: degrees = 0;/* w ww. j a v a 2 s .c om*/ break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int orientation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { orientation = (cameraRotationOffset + degrees) % 360; orientation = (360 - orientation) % 360; } else { orientation = (cameraRotationOffset - degrees + 360) % 360; } return orientation; }
From source file:Main.java
public static void lockOrientation(Activity activity) { Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int rotation = display.getRotation(); int tempOrientation = activity.getResources().getConfiguration().orientation; int orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; switch (tempOrientation) { case Configuration.ORIENTATION_LANDSCAPE: if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; else/*from ww w . ja v a 2s .com*/ orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; case Configuration.ORIENTATION_PORTRAIT: if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270) orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; else orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } activity.setRequestedOrientation(orientation); }
From source file:Main.java
private static int getDeviceOrientationDegree(Context context) { int degrees = 0; WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); int rotation = windowManager.getDefaultDisplay().getRotation(); switch (rotation) { case Surface.ROTATION_0: degrees = 0;/*from w w w . jav a 2 s.c om*/ break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } return degrees; }
From source file:Main.java
public static int getOrientationInDegree(Activity activity) { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0;/*from w w w . jav a 2s.com*/ break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } return degrees; }
From source file:Main.java
public static int setCameraDisplayOrientation(int cameraId, android.hardware.Camera camera, int displayRotation) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int degrees = 0; switch (displayRotation) { case Surface.ROTATION_0: degrees = 0;//ww w. ja va 2 s. c o m break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int camRotationDegree = 0; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { camRotationDegree = (info.orientation + degrees) % 360; camRotationDegree = (360 - camRotationDegree) % 360; // compensate the mirror } else { camRotationDegree = (info.orientation - degrees + 360) % 360; } if (camera != null) { camera.setDisplayOrientation(camRotationDegree); } return camRotationDegree; }
From source file:Main.java
public static int setCameraDisplayOrientation(int cameraId, android.hardware.Camera camera, int displayRotation) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int degrees = 0; switch (displayRotation) { case Surface.ROTATION_0: degrees = 0;//from w ww .j av a2 s.c om break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int camRotationDegree = 0; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { camRotationDegree = (info.orientation + degrees) % 360; camRotationDegree = (360 - camRotationDegree) % 360; // compensate the mirror } else { camRotationDegree = (info.orientation - degrees + 360) % 360; } if (camera != null) { try { camera.setDisplayOrientation(camRotationDegree); } catch (RuntimeException e) { // java.lang.RuntimeException: set display orientation failed e.printStackTrace(); } } return camRotationDegree; }
From source file:Main.java
public static int getOrientationHint(Activity activity, int cameraId) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0;/* w ww. j av a 2 s . c om*/ break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result = 0; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation - degrees + 360) % 360; } else { // back-facing camera result = (info.orientation + degrees) % 360; } return result; }