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 int getCameraDisplayOrientation(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;//from ww w. 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; } return result; }
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; Log.w(TAG, "cameraRotationOffset = " + cameraRotationOffset); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int currentScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Log.w(TAG, "currentScreenRotation = " + currentScreenRotation); int degrees = 0; switch (currentScreenRotation) { case Surface.ROTATION_0: degrees = 0;//w w w .java2 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; } Log.w(TAG, "degrees = " + degrees); int orientation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { orientation = (cameraRotationOffset + degrees) % 360; orientation = (360 - orientation) % 360; } else { orientation = (cameraRotationOffset - degrees + 360) % 360; } Log.w(TAG, "orientation = " + orientation); return orientation; }
From source file:Main.java
static int calculateOrientationHint(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; Log.w(TAG, "OrientationHint cameraRotationOffset = " + cameraRotationOffset); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int currentScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Log.w(TAG, "OrientationHint currentScreenRotation = " + currentScreenRotation); int degrees = 0; switch (currentScreenRotation) { case Surface.ROTATION_0: degrees = 0;/* w w w . j a v 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; } Log.w(TAG, "OrientationHint degrees = " + degrees); int orientation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { orientation = (cameraRotationOffset + degrees) % 360; if (degrees != 0) { orientation = (360 - orientation) % 360; } } else { orientation = (cameraRotationOffset - degrees + 360) % 360; } Log.w(TAG, "orientationHint = " + orientation); return orientation; }
From source file:Main.java
/** * reference http://www.jianshu.com/p/1513134733d0 *//*w ww . ja va 2 s . com*/ public static void setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); 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; } 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 getScreenOrientation(Activity activity) { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int width = dm.widthPixels; int height = dm.heightPixels; int orientation; // if the device's natural orientation is portrait: if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && height > width || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && width > height) { switch (rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_90: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_180: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; case Surface.ROTATION_270: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; default:/*from ww w . ja va 2 s . co m*/ Log.e("getScreenOrientation", "Unknown screen orientation. Defaulting to portrait."); orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; } } else { // if the device's natural orientation is landscape or if the device // is square: switch (rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_90: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_180: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; case Surface.ROTATION_270: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; default: Log.e("getScreenOrientation", "Unknown screen orientation. Defaulting to landscape."); orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; } } return orientation; }
From source file:Main.java
/** * @Thach Feb 21, 2014/*from www . jav a 2s . c om*/ * @Desc lock Orientation * @param b */ @SuppressWarnings("deprecation") public static void lockOrientation(Activity act, boolean isLock) { if (act == null) { return; } if (isLock) { Display display = act.getWindowManager().getDefaultDisplay(); int rotation = display.getRotation(); int height; int width; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) { height = display.getHeight(); width = display.getWidth(); } else { Point size = new Point(); display.getSize(size); height = size.y; width = size.x; } switch (rotation) { case Surface.ROTATION_90: if (width > height) act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); else act.setRequestedOrientation(9/* reversePortait */); break; case Surface.ROTATION_180: if (height > width) act.setRequestedOrientation(9/* reversePortait */); else act.setRequestedOrientation(8/* reverseLandscape */); break; case Surface.ROTATION_270: if (width > height) act.setRequestedOrientation(8/* reverseLandscape */); else act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; default: if (height > width) act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); else act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else { act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } }
From source file:Main.java
public static void sensorRotationVector2Matrix(SensorEvent event, int rotation, float[] output) { if (!sIsTruncated) { try {/*from w w w. j a v a 2 s .c o m*/ SensorManager.getRotationMatrixFromVector(sUIThreadTmp, event.values); } catch (Exception e) { // On some Samsung devices, SensorManager#getRotationMatrixFromVector throws an exception // if the rotation vector has more than 4 elements. Since only the four first elements are used, // we can truncate the vector without losing precision. Log.e(TAG, "maybe Samsung bug, will truncate vector"); sIsTruncated = true; } } if (sIsTruncated) { System.arraycopy(event.values, 0, sTruncatedVector, 0, 4); SensorManager.getRotationMatrixFromVector(sUIThreadTmp, sTruncatedVector); } float[] values = event.values; switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: /* Notice: not supported for ROTATION_180! */ SensorManager.getRotationMatrixFromVector(output, values); break; case Surface.ROTATION_90: SensorManager.getRotationMatrixFromVector(sUIThreadTmp, values); SensorManager.remapCoordinateSystem(sUIThreadTmp, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, output); break; case Surface.ROTATION_270: SensorManager.getRotationMatrixFromVector(sUIThreadTmp, values); SensorManager.remapCoordinateSystem(sUIThreadTmp, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, output); break; } Matrix.rotateM(output, 0, 90.0F, 1.0F, 0.0F, 0.0F); }
From source file:Main.java
/** * Calculates the default orientation of the device.<br> * The default orientation of most phones is portrait, and the default orientation of most tablets is landscape. * //from ww w . ja v a 2 s . c om * @param activity Activity. * @return {@link Configuration#ORIENTATION_PORTRAIT} or {@link Configuration#ORIENTATION_LANDSCAPE} */ public static int getDefaultOrientationOfDevice(Activity activity) { Configuration configuration = activity.getResources().getConfiguration(); boolean orientationLandscape = (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE); Display display = activity.getWindowManager().getDefaultDisplay(); int rotation = display.getRotation(); boolean parallelToDefaultVerticalAxis = (rotation == Surface.ROTATION_0) || (rotation == Surface.ROTATION_180); boolean defaultOrientationLandscape = (parallelToDefaultVerticalAxis && orientationLandscape) || (!parallelToDefaultVerticalAxis && !orientationLandscape); if (defaultOrientationLandscape) { return Configuration.ORIENTATION_LANDSCAPE; } return Configuration.ORIENTATION_PORTRAIT; }
From source file:Main.java
/** * Set Camera orientation to correct one * @param context app context// w w w . j a v a 2 s .c o m * @param camera camera to set orientation */ public static void setCameraDisplayOrientation(Context context, Camera camera) { if (camera == null) { return; } Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(getCameraInformationId(), info); WindowManager winManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); int rotation = winManager.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 (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
/** * Locks specified activity's orientation until it is unlocked or recreated. * * @param activity activity// w w w . j av a 2 s . c o m */ public static void lockOrientation(Activity activity) { Configuration config = activity.getResources().getConfiguration(); final int deviceOrientation = config.orientation; int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int orientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; if (deviceOrientation == Configuration.ORIENTATION_PORTRAIT) { orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_180) orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } else if (deviceOrientation == Configuration.ORIENTATION_LANDSCAPE) { orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } activity.setRequestedOrientation(orientation); }