List of usage examples for android.content.pm ActivityInfo SCREEN_ORIENTATION_REVERSE_LANDSCAPE
int SCREEN_ORIENTATION_REVERSE_LANDSCAPE
To view the source code for android.content.pm ActivityInfo SCREEN_ORIENTATION_REVERSE_LANDSCAPE.
Click Source Link
reverseLandscape
in the android.R.attr#screenOrientation attribute. From source file:Main.java
private static int getPlatformOrientation(int o) { int platformOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; if (o == ORIENTATION_REVERSE_LANDSCAPE && Build.VERSION.SDK_INT >= 9) { platformOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } else if (o == ORIENTATION_REVERSE_PORTRAIT && Build.VERSION.SDK_INT >= 9) { platformOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } else if (o == ORIENTATION_LANDSCAPE || o == ORIENTATION_REVERSE_LANDSCAPE) { platformOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } else if (o == ORIENTATION_PORTRAIT || o == ORIENTATION_REVERSE_PORTRAIT) { platformOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; }// ww w. j a v a2 s . com return platformOrientation; }
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/* w w w . j av a 2s. co m*/ 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
/** * Untested, taken from stack-overflow.//from w ww . j av a2 s. co 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
@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 {/*from w w w . j a v a 2 s . co m*/ 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
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 www. j a va 2 s. c om*/ 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
/** * Locks specified activity's orientation until it is unlocked or recreated. * * @param activity activity//from ww w .j a v a 2 s. co 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); }
From source file:org.inversebit.proto01.main.ElectroActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Log.d(Constants.TAG, "EA: onCreate"); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); super.onCreate(savedInstanceState); setContentView(R.layout.activity_electro); initDrawer(savedInstanceState);/*from ww w .jav a2 s . c o m*/ }
From source file:Main.java
public static void fixBitmapRotationExif(String filePath, Activity activityForScreenOrientation) { try {// w w w . jav a 2 s . c om ExifInterface exif = new ExifInterface(filePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); if (exifOrientation == ExifInterface.ORIENTATION_UNDEFINED && Build.MANUFACTURER.toLowerCase(Locale.ENGLISH).contains("htc")) return; boolean flippedHorizontally = false, flippedVertically = false; int angle = 0; if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { angle += 90; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { angle += 180; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { angle += 270; } else if (exifOrientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) { flippedHorizontally = true; } else if (exifOrientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) { flippedVertically = true; } else if (exifOrientation == ExifInterface.ORIENTATION_TRANSPOSE) { angle += 90; flippedVertically = true; } else if (exifOrientation == ExifInterface.ORIENTATION_TRANSVERSE) { angle -= 90; flippedVertically = true; } int orientation; if (activityForScreenOrientation != null) { orientation = getScreenOrientation(activityForScreenOrientation); if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { angle += 90; } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) { angle += 180; } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { angle += 270; } } orientation = 0; angle = angle % 360; if (angle == -90 && flippedVertically && !flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSVERSE; } else if (angle == -270 && flippedVertically && !flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSPOSE; } else if (angle == -90 && !flippedVertically && flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSPOSE; } else if (angle == -270 && !flippedVertically && flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSVERSE; } else { while (angle < 0) { angle += 360; } switch (angle) { case 0: if (flippedHorizontally) { orientation = ExifInterface.ORIENTATION_FLIP_HORIZONTAL; } else if (flippedVertically) { orientation = ExifInterface.ORIENTATION_FLIP_VERTICAL; } break; case 90: orientation = ExifInterface.ORIENTATION_ROTATE_90; break; case 180: orientation = ExifInterface.ORIENTATION_ROTATE_180; break; case 270: orientation = ExifInterface.ORIENTATION_ROTATE_270; break; } } if (orientation != exifOrientation) { exif.setAttribute(ExifInterface.TAG_ORIENTATION, ((Integer) orientation).toString()); exif.saveAttributes(); } } catch (IOException e) { Log.w("TAG", "-- Error in setting image"); } }
From source file:Main.java
public static Bitmap getBitmapByFixingRotationForFile(String filePath, Bitmap sourceBitmap, Activity activityForScreenOrientation, boolean freeSourceBitmap) { try {/*from www .j a v a2 s . co m*/ ExifInterface exif = new ExifInterface(filePath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); if (orientation == ExifInterface.ORIENTATION_UNDEFINED && Build.MANUFACTURER.toLowerCase(Locale.ENGLISH).contains("htc")) return null; boolean flippedHorizontally = false, flippedVertically = false; int angle = 0; if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { angle += 90; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { angle += 180; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { angle += 270; } else if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) { flippedHorizontally = true; } else if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) { flippedVertically = true; } else if (orientation == ExifInterface.ORIENTATION_TRANSPOSE) { angle += 90; flippedVertically = true; } else if (orientation == ExifInterface.ORIENTATION_TRANSVERSE) { angle -= 90; flippedVertically = true; } if (activityForScreenOrientation != null) { orientation = getScreenOrientation(activityForScreenOrientation); if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { angle += 90; } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) { angle += 180; } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { angle += 270; } } Bitmap bmp = sourceBitmap; if (bmp == null) { bmp = BitmapFactory.decodeFile(filePath, null); } if (angle != 0) { Matrix mat = new Matrix(); mat.postRotate(angle); if (flippedHorizontally) { mat.postScale(-1.f, 1.f); } if (flippedVertically) { mat.postScale(1.f, -1.f); } Bitmap rotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), mat, true); if (freeSourceBitmap || bmp != sourceBitmap) { bmp.recycle(); } bmp = rotated; } return bmp; } catch (IOException e) { Log.w("TAG", "-- Error in setting image"); } catch (OutOfMemoryError oom) { Log.w("TAG", "-- OOM Error in setting image"); } return null; }
From source file:cordova.plugins.screenorientation.CDVOrientation.java
private boolean routeScreenOrientation(JSONArray args, CallbackContext callbackContext) { String action = args.optString(0); String orientation = args.optString(1); Log.d(TAG, "Requested ScreenOrientation: " + orientation); Activity activity = cordova.getActivity(); if (orientation.equals(ANY)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } else if (orientation.equals(LANDSCAPE_PRIMARY)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else if (orientation.equals(PORTRAIT_PRIMARY)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (orientation.equals(LANDSCAPE)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } else if (orientation.equals(PORTRAIT)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } else if (orientation.equals(LANDSCAPE_SECONDARY)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } else if (orientation.equals(PORTRAIT_SECONDARY)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); }// ww w . j a v a 2 s . com callbackContext.success(); return true; }