Index: content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java b/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java |
index 442e2d2873e2923fec564df05ca14e4f5a752d85..32040605000cc5b8a8abcc5085d57e9c1b602d84 100644 |
--- a/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java |
+++ b/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java |
@@ -13,17 +13,20 @@ import org.chromium.base.ApplicationStatus; |
import org.chromium.base.CalledByNative; |
import org.chromium.base.JNINamespace; |
import org.chromium.base.ThreadUtils; |
+import org.chromium.content_public.common.ScreenOrientationConstants; |
import org.chromium.content_public.common.ScreenOrientationValues; |
+import org.chromium.ui.gfx.DeviceDisplayInfo; |
/** |
* This is the implementation of the C++ counterpart ScreenOrientationProvider. |
*/ |
@JNINamespace("content") |
-class ScreenOrientationProvider { |
+public class ScreenOrientationProvider { |
private static final String TAG = "ScreenOrientationProvider"; |
- private static int getOrientationFromWebScreenOrientations(byte orientations) { |
- switch (orientations) { |
+ private static int getOrientationFromWebScreenOrientations(byte orientation, |
+ Activity activity) { |
+ switch (orientation) { |
case ScreenOrientationValues.DEFAULT: |
return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
case ScreenOrientationValues.PORTRAIT_PRIMARY: |
@@ -40,6 +43,20 @@ class ScreenOrientationProvider { |
return ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; |
case ScreenOrientationValues.ANY: |
return ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR; |
+ case ScreenOrientationValues.NATURAL: |
+ DeviceDisplayInfo displayInfo = DeviceDisplayInfo.create(activity); |
+ int rotation = displayInfo.getRotationDegrees(); |
+ if (rotation == 0 || rotation == 180) { |
+ if (displayInfo.getDisplayHeight() >= displayInfo.getDisplayWidth()) { |
+ return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
+ } |
+ return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
+ } else { |
+ if (displayInfo.getDisplayHeight() < displayInfo.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; |
@@ -47,13 +64,14 @@ class ScreenOrientationProvider { |
} |
@CalledByNative |
- static void lockOrientation(byte orientations) { |
- Activity activity = ApplicationStatus.getLastTrackedFocusedActivity(); |
- if (activity == null) { |
- return; |
- } |
+ static void lockOrientation(byte orientation) { |
+ lockOrientation(orientation, ApplicationStatus.getLastTrackedFocusedActivity()); |
+ } |
+ |
+ public static void lockOrientation(byte webScreenOrientation, Activity activity) { |
+ if (activity == null) return; |
- int orientation = getOrientationFromWebScreenOrientations(orientations); |
+ int orientation = getOrientationFromWebScreenOrientations(webScreenOrientation, activity); |
if (orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
return; |
} |
@@ -70,10 +88,20 @@ class ScreenOrientationProvider { |
int defaultOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
+ // Activities opened from a shortcut may have EXTRA_ORIENTATION set. In |
+ // which case, we want to use that as the default orientation. |
+ int orientation = activity.getIntent().getIntExtra( |
+ ScreenOrientationConstants.EXTRA_ORIENTATION, |
+ ScreenOrientationValues.DEFAULT); |
+ defaultOrientation = getOrientationFromWebScreenOrientations( |
+ (byte)orientation, activity); |
+ |
try { |
- ActivityInfo info = activity.getPackageManager().getActivityInfo( |
- activity.getComponentName(), PackageManager.GET_META_DATA); |
- defaultOrientation = info.screenOrientation; |
+ if (defaultOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
+ ActivityInfo info = activity.getPackageManager().getActivityInfo( |
+ activity.getComponentName(), PackageManager.GET_META_DATA); |
+ defaultOrientation = info.screenOrientation; |
+ } |
} catch (PackageManager.NameNotFoundException e) { |
// Do nothing, defaultOrientation should be SCREEN_ORIENTATION_UNSPECIFIED. |
} finally { |