Java Code Examples for android.content.pm.activityinfo#SCREEN_ORIENTATION_REVERSE_PORTRAIT
The following examples show how to use
android.content.pm.activityinfo#SCREEN_ORIENTATION_REVERSE_PORTRAIT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrientationManagerImpl.java From Camera2 with Apache License 2.0 | 6 votes |
private int calculateCurrentScreenOrientation() { int displayRotation = getDisplayRotation(mActivity); // Display rotation >= 180 means we need to use the REVERSE landscape/portrait boolean standard = displayRotation < 180; if (mActivity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { return standard ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } else { if (displayRotation == 90 || displayRotation == 270) { // If displayRotation = 90 or 270 then we are on a landscape // device. On landscape devices, portrait is a 90 degree // clockwise rotation from landscape, so we need // to flip which portrait we pick as display rotation is counter clockwise standard = !standard; } return standard ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } }
Example 2
Source File: ScreenOrientationManager.java From aptoide-client-v8 with GNU General Public License v3.0 | 6 votes |
public void lock() { int orientation; int rotation = windowManager.getDefaultDisplay() .getRotation(); switch (rotation) { default: 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; } activity.setRequestedOrientation(orientation); }
Example 3
Source File: CaptureActivity.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 6 votes |
private int getCurrentOrientation() { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } } else { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_270: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } } }
Example 4
Source File: CaptureActivity.java From barcodescanner-lib-aar with MIT License | 6 votes |
private int getCurrentOrientation() { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } } else { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_270: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } } }
Example 5
Source File: CaptureActivity.java From CodeScaner with MIT License | 6 votes |
private int getCurrentOrientation() { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } } else { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_270: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } } }
Example 6
Source File: CustomChecks.java From fullscreen-video-view with Apache License 2.0 | 6 votes |
@Override public void perform(UiController uiController, View view) { uiController.loopMainThreadUntilIdle(); int orientation = getActivityOrientation(view); boolean checkOrientation = false; switch (orientationType) { case PORTRAIT: checkOrientation = orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT; break; case LANDSCAPE: checkOrientation = orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE; break; } if (checkOrientation) { isOrientation[0] = true; } }
Example 7
Source File: CaptureActivity.java From ZXing-Standalone-library with Apache License 2.0 | 6 votes |
private int getCurrentOrientation() { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } } else { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_270: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } } }
Example 8
Source File: CaptureActivity.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
private int getCurrentOrientation() { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } } else { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_270: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } } }
Example 9
Source File: Launcher.java From TurboLauncher with Apache License 2.0 | 5 votes |
private int mapConfigurationOriActivityInfoOri(int configOri) { final Display d = getWindowManager().getDefaultDisplay(); int naturalOri = Configuration.ORIENTATION_LANDSCAPE; switch (d.getRotation()) { case Surface.ROTATION_0: case Surface.ROTATION_180: // We are currently in the same basic orientation as the natural // orientation naturalOri = configOri; break; case Surface.ROTATION_90: case Surface.ROTATION_270: // We are currently in the other basic orientation to the natural // orientation naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; break; } int[] oriMap = { ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE }; // Since the map starts at portrait, we need to offset if this device's // natural orientation // is landscape. int indexOffset = 0; if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { indexOffset = 1; } return oriMap[(d.getRotation() + indexOffset) % 4]; }
Example 10
Source File: U.java From Taskbar with Apache License 2.0 | 5 votes |
@SuppressLint("SwitchIntDef") private static ApplicationType getApplicationType(Context context, AppEntry entry) { if(isGame(context, entry.getPackageName())) return ApplicationType.APP_FULLSCREEN; try { ActivityInfo info = context.getPackageManager().getActivityInfo( ComponentName.unflattenFromString(entry.getComponentName()), 0 ); switch(info.screenOrientation) { case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: return ApplicationType.APP_LANDSCAPE; case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: return ApplicationType.APP_PORTRAIT; } } catch (PackageManager.NameNotFoundException e) { /* Gracefully fail */ } return context.getPackageName().equals(BuildConfig.ANDROIDX86_APPLICATION_ID) ? ApplicationType.APP_LANDSCAPE : ApplicationType.APP_PORTRAIT; }
Example 11
Source File: SDLActivity.java From android-port with GNU General Public License v3.0 | 5 votes |
/** * This can be overridden */ public void setOrientationBis(int w, int h, boolean resizable, String hint) { int orientation = -1; if (hint.contains("LandscapeRight") && hint.contains("LandscapeLeft")) { orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; } else if (hint.contains("LandscapeRight")) { orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } else if (hint.contains("LandscapeLeft")) { orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } else if (hint.contains("Portrait") && hint.contains("PortraitUpsideDown")) { orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; } else if (hint.contains("Portrait")) { orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } else if (hint.contains("PortraitUpsideDown")) { orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } /* no valid hint */ if (orientation == -1) { if (resizable) { /* no fixed orientation */ } else { if (w > h) { orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; } else { orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; } } } Log.v("SDL", "setOrientation() orientation=" + orientation + " width=" + w +" height="+ h +" resizable=" + resizable + " hint=" + hint); if (orientation != -1) { mSingleton.setRequestedOrientation(orientation); } }
Example 12
Source File: StreamActivity.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 5 votes |
@Override public void onResume() { super.onResume(); if (getResources().getConfiguration().orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { Log.d(LOG_TAG, "Orientations is reverse portrait"); } Log.d(LOG_TAG, "Current orientation: " + getResources().getConfiguration().orientation); }
Example 13
Source File: SDLActivity.java From simpleSDL with MIT License | 5 votes |
/** * This can be overridden */ public void setOrientationBis(int w, int h, boolean resizable, String hint) { int orientation = -1; if (hint.contains("LandscapeRight") && hint.contains("LandscapeLeft")) { orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; } else if (hint.contains("LandscapeRight")) { orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } else if (hint.contains("LandscapeLeft")) { orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } else if (hint.contains("Portrait") && hint.contains("PortraitUpsideDown")) { orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; } else if (hint.contains("Portrait")) { orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } else if (hint.contains("PortraitUpsideDown")) { orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } /* no valid hint */ if (orientation == -1) { if (resizable) { /* no fixed orientation */ } else { if (w > h) { orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; } else { orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; } } } Log.v("SDL", "setOrientation() orientation=" + orientation + " width=" + w +" height="+ h +" resizable=" + resizable + " hint=" + hint); if (orientation != -1) { mSingleton.setRequestedOrientation(orientation); } }
Example 14
Source File: CustomMediaController.java From ZZShow with Apache License 2.0 | 4 votes |
public 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: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; } } // if the device's natural orientation is landscape or if the device // is square: else{ 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: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; } } return orientation; }
Example 15
Source File: RotateUtil.java From FloatWindow with Apache License 2.0 | 4 votes |
@Override public void onSensorChanged(SensorEvent event) { float[] values = event.values; int orientation = ORIENTATION_UNKNOWN; float X = -values[DATA_X]; float Y = -values[DATA_Y]; float Z = -values[DATA_Z]; float magnitude = X * X + Y * Y; // Don't trust the angle if the magnitude is small compared to the y // value if (magnitude * 4 >= Z * Z) { // 屏幕旋转时 float OneEightyOverPi = 57.29577957855f; float angle = (float) Math.atan2(-Y, X) * OneEightyOverPi; orientation = 90 - Math.round(angle); // normalize to 0 - 359 range while (orientation >= 360) { orientation -= 360; } while (orientation < 0) { orientation += 360; } } //竖屏 if (screenIsPortrait(orientation)) { //上次非竖屏,屏幕旋转 if (!isLastLandscape) { isChangeOrientation = true; if (FwContent.isDebug) { L.v("onSensorChanged: 横屏 ----> 竖屏"); } } else { isChangeOrientation = false; if (FwContent.isDebug) { L.v("onSensorChanged: 竖屏 ----> 竖屏"); } } isLastLandscape = true; // 横屏处理 } else if (screenIsLandscape(orientation)) { //上次竖屏,屏幕旋转 if (isLastLandscape) { isChangeOrientation = true; if (FwContent.isDebug) { L.v("onSensorChanged: 竖屏 ---->横屏"); } } else { isChangeOrientation = false; if (FwContent.isDebug) { L.v("onSensorChanged: 横屏 ----> 横屏"); } } isLastLandscape = false; } // 页面变化,回调 if (isChangeOrientation) { mSensorRotateChanged.onRotateChanged(); isChangeOrientation = false; } // 不拦截时,对应页面也可以收到页面的改变 if (!isInterrupt && mActivityRef != null && mActivityRef.get() != null) { // 根据手机屏幕的朝向角度,来设置内容的横竖屏,并且记录状态 int requestedOrientation = 0; if (orientation > 45 && orientation < 135) { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } else if (orientation > 135 && orientation < 225) { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } else if (orientation > 225 && orientation < 315) { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } else if ((orientation > 315 && orientation < 360) || (orientation > 0 && orientation < 45)) { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } // 接收重力感应监听的结果,来改变屏幕朝向 mActivityRef.get().setRequestedOrientation(requestedOrientation); } }
Example 16
Source File: MediaPlayer.java From HeroVideo-master with Apache License 2.0 | 4 votes |
private int getScreenOrientation() { 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: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; } } // if the device's natural orientation is landscape or if the device // is square: else { 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: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; } } return orientation; }
Example 17
Source File: CustomMediaContoller.java From MD with Apache License 2.0 | 4 votes |
public 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: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; } } // if the device's natural orientation is landscape or if the device // is square: else { 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: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; } } return orientation; }
Example 18
Source File: WindowUtils.java From DanDanPlayForAndroid with MIT License | 4 votes |
/** * 获取界面方向 */ 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: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; } } // if the device's natural orientation is landscape or if the device // is square: else { 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: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; } } return orientation; }
Example 19
Source File: ScreenOrientationProvider.java From 365browser with Apache License 2.0 | 4 votes |
private static int getOrientationFromWebScreenOrientations(byte orientation, @Nullable WindowAndroid window, Context context) { switch (orientation) { case ScreenOrientationValues.DEFAULT: return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; case ScreenOrientationValues.PORTRAIT_PRIMARY: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; case ScreenOrientationValues.PORTRAIT_SECONDARY: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; case ScreenOrientationValues.LANDSCAPE_PRIMARY: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; case ScreenOrientationValues.LANDSCAPE_SECONDARY: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; case ScreenOrientationValues.PORTRAIT: return ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; case ScreenOrientationValues.LANDSCAPE: return ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; case ScreenOrientationValues.ANY: return ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR; case ScreenOrientationValues.NATURAL: // If the tab is being reparented, we don't have a display strongly associated with // it, so we get the default display. DisplayAndroid displayAndroid = (window != null) ? window.getDisplay() : DisplayAndroid.getNonMultiDisplay(context); int rotation = displayAndroid.getRotation(); if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) { if (displayAndroid.getDisplayHeight() >= displayAndroid.getDisplayWidth()) { return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } else { if (displayAndroid.getDisplayHeight() < displayAndroid.getDisplayWidth()) { return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } default: Log.w(TAG, "Trying to lock to unsupported orientation!"); return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; } }
Example 20
Source File: VideoPlayerActivity.java From VCL-Android with Apache License 2.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.GINGERBREAD) private int getScreenOrientation(){ WindowManager wm = (WindowManager) VLCApplication.getAppContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int rot = getScreenRotation(); /* * Since getRotation() returns the screen's "natural" orientation, * which is not guaranteed to be SCREEN_ORIENTATION_PORTRAIT, * we have to invert the SCREEN_ORIENTATION value if it is "naturally" * landscape. */ @SuppressWarnings("deprecation") boolean defaultWide = display.getWidth() > display.getHeight(); if(rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) defaultWide = !defaultWide; if(defaultWide) { switch (rot) { case Surface.ROTATION_0: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; case Surface.ROTATION_180: // SCREEN_ORIENTATION_REVERSE_PORTRAIT only available since API // Level 9+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); case Surface.ROTATION_270: // SCREEN_ORIENTATION_REVERSE_LANDSCAPE only available since API // Level 9+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); default: return 0; } } else { switch (rot) { case Surface.ROTATION_0: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; case Surface.ROTATION_180: // SCREEN_ORIENTATION_REVERSE_PORTRAIT only available since API // Level 9+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); case Surface.ROTATION_270: // SCREEN_ORIENTATION_REVERSE_LANDSCAPE only available since API // Level 9+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); default: return 0; } } }