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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..853f5c4818e7042517fac9ec667a6b1bb9bd8f30 |
--- /dev/null |
+++ b/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java |
@@ -0,0 +1,83 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.content.browser; |
+ |
+import android.app.Activity; |
+import android.content.pm.ActivityInfo; |
+import android.util.Log; |
+ |
+import com.google.common.annotations.VisibleForTesting; |
+ |
+import org.chromium.base.ApplicationStatus; |
+import org.chromium.base.CalledByNative; |
+import org.chromium.base.JNINamespace; |
+ |
+/** |
+ * This is the implementation of the C++ counterpart ScreenOrientationProvider. |
+ */ |
+@JNINamespace("content") |
+class ScreenOrientationProvider { |
+ private static final String TAG = "ScreenOrientationProvider"; |
+ |
+ // Has to be kept in sync with: |
Michael van Ouwerkerk
2014/03/12 14:42:55
Ugh. There are ways to automate this. They are ugl
mlamouri (slow - plz ping)
2014/03/12 20:19:55
Done.
|
+ // third_party/WebKit/public/platform/WebScreenOrientation.h |
+ private static final byte PORTRAIT_PRIMARY = 1 << 0; |
+ private static final byte LANDSCAPE_PRIMARY = 1 << 1; |
+ private static final byte PORTRAIT_SECONDARY = 1 << 2; |
+ private static final byte LANDSCAPE_SECONDARY = 1 << 3; |
+ |
+ private int getOrientationFromWebScreenOrientations(byte orientations) { |
+ switch (orientations) { |
+ case PORTRAIT_PRIMARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
+ case PORTRAIT_SECONDARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; |
+ case LANDSCAPE_PRIMARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
+ case LANDSCAPE_SECONDARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; |
+ case PORTRAIT_PRIMARY | PORTRAIT_SECONDARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; |
+ case LANDSCAPE_PRIMARY | LANDSCAPE_SECONDARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; |
+ case PORTRAIT_PRIMARY | PORTRAIT_SECONDARY | LANDSCAPE_PRIMARY | LANDSCAPE_SECONDARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR; |
+ default: |
+ Log.w(TAG, "Trying to lock to unsupported orientation!"); |
+ return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
+ } |
+ } |
+ |
+ @VisibleForTesting |
+ @CalledByNative |
+ static ScreenOrientationProvider create() { |
+ return new ScreenOrientationProvider(); |
+ } |
+ |
+ @CalledByNative |
+ void lockOrientation(byte orientations) { |
+ Activity activity = ApplicationStatus.getLastTrackedFocusedActivity(); |
+ if (activity == null) |
Michael van Ouwerkerk
2014/03/12 14:42:55
Braces please. http://source.android.com/source/co
mlamouri (slow - plz ping)
2014/03/12 20:19:55
Done.
|
+ return; |
+ |
+ int orientation = getOrientationFromWebScreenOrientations(orientations); |
+ if (orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) |
Michael van Ouwerkerk
2014/03/12 14:42:55
Braces.
mlamouri (slow - plz ping)
2014/03/12 20:19:55
Done.
|
+ return; |
+ |
+ activity.setRequestedOrientation(orientation); |
+ } |
+ |
+ @CalledByNative |
+ void unlockOrientation() { |
+ Activity activity = ApplicationStatus.getLastTrackedFocusedActivity(); |
+ if (activity == null) |
Michael van Ouwerkerk
2014/03/12 14:42:55
And braces.
mlamouri (slow - plz ping)
2014/03/12 20:19:55
Done.
|
+ return; |
+ |
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
+ } |
+ |
+ private ScreenOrientationProvider() { |
+ } |
+} |