List of usage examples for android.content.res Configuration ORIENTATION_LANDSCAPE
int ORIENTATION_LANDSCAPE
To view the source code for android.content.res Configuration ORIENTATION_LANDSCAPE.
Click Source Link
From source file:Main.java
public static void rotateOrientation(Activity activity) { int currentOrientation = activity.getResources().getConfiguration().orientation; switch (currentOrientation) { case Configuration.ORIENTATION_LANDSCAPE: rotateToPortrait(activity);//from w ww.j a va 2s . co m break; case Configuration.ORIENTATION_PORTRAIT: rotateToLandscape(activity); break; default: rotateToLandscape(activity); } }
From source file:Main.java
/** * Used to determine if the device is currently in landscape mode * /*from w w w . j av a 2 s .c o m*/ * @param context The {@link Context} to use. * @return True if the device is in landscape mode, false otherwise. */ public static final boolean isLandscape(final Context context) { return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; }
From source file:Main.java
/** * Used to determine if the device is currently in landscape mode * /*w w w . ja v a2 s. c o m*/ * @param context The {@link Context} to use. * @return True if the device is in landscape mode, false otherwise. */ public static final boolean isLandscape(final Context context) { final int orientation = context.getResources().getConfiguration().orientation; return orientation == Configuration.ORIENTATION_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 www. j av a 2 s . c o 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
/** * 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. * /*w w w . j a v a 2 s . com*/ * @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
public static int getScreenOrientation(Context context) { Display display = getDefaultDisplay(context); int orientation = Configuration.ORIENTATION_UNDEFINED; if (display.getWidth() == display.getHeight()) orientation = Configuration.ORIENTATION_SQUARE; else {/*from w w w. j ava2s . c o m*/ if (display.getWidth() < display.getHeight()) orientation = Configuration.ORIENTATION_PORTRAIT; else orientation = Configuration.ORIENTATION_LANDSCAPE; } return orientation; }
From source file:Main.java
public static void hide(Context context, Window window, int smartBarHeight) { if (!hasSmartBar()) { return;//from www . j a v a 2 s . c o m } if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { return; } window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); int statusBarHeight = getStatusBarHeight(context); window.getDecorView().setPadding(0, statusBarHeight, 0, -smartBarHeight); }
From source file:MainActivity.java
public void checkOrientation(View view) { int orientation = getResources().getConfiguration().orientation; switch (orientation) { case Configuration.ORIENTATION_LANDSCAPE: Toast.makeText(MainActivity.this, "ORIENTATION_LANDSCAPE", Toast.LENGTH_SHORT).show(); break;//w ww . j a v a2 s .c o m case Configuration.ORIENTATION_PORTRAIT: Toast.makeText(MainActivity.this, "ORIENTATION_PORTRAIT", Toast.LENGTH_SHORT).show(); break; case Configuration.ORIENTATION_UNDEFINED: Toast.makeText(MainActivity.this, "ORIENTATION_UNDEFINED", Toast.LENGTH_SHORT).show(); break; } }
From source file:Main.java
public static int getSurfaceOrientation(Activity activity) { // Sanity check: if (activity == null) { return -1; // invalid value }/*w ww. ja v a 2 s . c o m*/ Configuration config = activity.getResources().getConfiguration(); Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int displayRotation; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { displayRotation = display.getRotation(); // only available from Froyo } else { displayRotation = display.getOrientation(); } int activityOrientation = SCREEN_ORIENTATION_UNKNOWN; switch (config.orientation) { case Configuration.ORIENTATION_PORTRAIT: case Configuration.ORIENTATION_SQUARE: activityOrientation = ((displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_270) ? SCREEN_ORIENTATION_PORTRAIT : SCREEN_ORIENTATION_PORTRAITUPSIDEDOWN); break; case Configuration.ORIENTATION_LANDSCAPE: activityOrientation = ((displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_90) ? SCREEN_ORIENTATION_LANDSCAPELEFT : SCREEN_ORIENTATION_LANDSCAPERIGHT); break; case Configuration.ORIENTATION_UNDEFINED: default: break; } return activityOrientation; }
From source file:Main.java
/** * Locks specified activity's orientation until it is unlocked or recreated. * * @param activity activity//w ww .j av a 2 s. c om */ 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); }