List of usage examples for android.view Surface ROTATION_180
int ROTATION_180
To view the source code for android.view Surface ROTATION_180.
Click Source Link
From source file:Main.java
public static void setCameraDisplayOrientation(int rotation, int cameraId, Camera camera) { 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;//ww w. j a v a 2 s. com 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 (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); }
From source file:Main.java
public static int getOrientationHint(Activity activity, int cameraId, android.hardware.Camera camera) { android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0;/*from www. j a va 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; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; } else { // back-facing result = (info.orientation - degrees + 360) % 360; } return result; }
From source file:Main.java
public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { 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;//from w ww .j av a 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 result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } Log.d(TAG, "camera display orientation: " + result); camera.setDisplayOrientation(result); return result; }
From source file:Main.java
/** * Determine the rotation to apply for the preview for a given camera * @param mirror whether to account for profile camera mirroring or not *///w w w. j a va 2 s .c om public static int getRotationDegrees(Activity activity, int cameraId, boolean mirror) { int rotation = activity.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; } android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { degrees = (info.orientation + degrees) % 360; // compensate for mirrored image, useful for previews on front facing cameras if (mirror) { degrees = (360 - degrees) % 360; } } else { degrees = (info.orientation - degrees + 360) % 360; } return degrees; }
From source file:Main.java
public static void setCameraDisplayOrientation(Context mContext, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = ((Activity) mContext).getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0;//from 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 result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); }
From source file:Main.java
public static void setCameraDisplayOrientation(Activity activity, int cameraId, android.hardware.Camera camera) { android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0;/*w ww .j ava 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; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); }
From source file:Main.java
public static int getCameraDisplayOrientation(@NonNull Activity activity, @NonNull CameraInfo info) { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); switch (rotation) { case Surface.ROTATION_0: degrees = 0;//ww w . ja va 2 s. co m break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { return (360 - ((info.orientation + degrees) % 360)) % 360; } else { return (info.orientation - degrees + 360) % 360; } }
From source file:Main.java
public static int convertRotationToTiOrientationMode(int rotation) { switch (rotation) { case Surface.ROTATION_0: return ORIENTATION_PORTRAIT; case Surface.ROTATION_90: return ORIENTATION_LANDSCAPE; case Surface.ROTATION_180: return ORIENTATION_PORTRAIT_REVERSE; case Surface.ROTATION_270: return ORIENTATION_LANDSCAPE_REVERSE; default://w w w .java 2 s.com return ORIENTATION_UNKNOWN; } }
From source file:Main.java
@SuppressLint("NewApi") public static void lockScreenOrientation(Activity activity) { switch (activity.getResources().getConfiguration().orientation) { case Configuration.ORIENTATION_PORTRAIT: if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else {// w ww . j a v a 2s. com int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_180) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } break; case Configuration.ORIENTATION_LANDSCAPE: if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } break; } }
From source file:Main.java
private static int getCameraDisplayOrientation_1(Activity activity, @SuppressWarnings("deprecation") Camera.CameraInfo cameraInfo) { // android.hardware.Camera.CameraInfo info = // new android.hardware.Camera.CameraInfo(); // android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0;/* w ww . j a v a 2 s. co m*/ break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; default: { Log.e(TAG, "un deal with handler task"); } break; } int result; //noinspection deprecation if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (cameraInfo.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (cameraInfo.orientation - degrees + 360) % 360; } return result; }