Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(863)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ScreenOrientationListener.java

Issue 398013002: Poll for Display rotation on Android 4.0 and 4.1 when needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/ScreenOrientationListener.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationListener.java b/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationListener.java
index 7e809c0e27578f5fdbf9ebe9cdd67fe464869d66..cb0cd5fe7cdb96d562966998466ac7119a2e2e6e 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationListener.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationListener.java
@@ -60,6 +60,13 @@ public class ScreenOrientationListener {
* when the last observer is removed.
*/
void stopListening();
+
+ /**
+ * Toggle the accurate mode. Starts listening accurately if the listener
+ * wasn't or stop doing so if it was. This might be a no-op if the
+ * listener always listen accurately.
+ */
+ void toggleAccurateMode();
}
/**
@@ -69,10 +76,16 @@ public class ScreenOrientationListener {
*
* This method is known to not correctly detect 180 degrees changes but it
* is the only method that will work before API Level 17 (excluding polling).
+ * When toggleAccurateMode() is called, it will start polling in order to
+ * find out if the display has changed.
*/
private class ScreenOrientationConfigurationListener
implements ScreenOrientationListenerBackend, ComponentCallbacks {
+ private static final long POLLING_DELAY = 500;
+
+ private boolean mAccurateMode = false;
+
// ScreenOrientationListenerBackend implementation:
@Override
@@ -85,6 +98,29 @@ public class ScreenOrientationListener {
mAppContext.unregisterComponentCallbacks(this);
}
+ @Override
+ public void toggleAccurateMode() {
+ // If mAccurateMode is set to true, a Runnable will be started and
+ // will get restarted every POLLING_DELAY until mAccurateMode is set
+ // to false.
+ mAccurateMode = !mAccurateMode;
+
+ if (mAccurateMode) {
+ final ScreenOrientationConfigurationListener self = this;
+ ThreadUtils.postOnUiThreadDelayed(new Runnable() {
+ @Override
+ public void run() {
+ self.onConfigurationChanged(null);
+
+ if (self.mAccurateMode) {
+ ThreadUtils.postOnUiThreadDelayed(this,
+ ScreenOrientationConfigurationListener.POLLING_DELAY);
+ }
+ }
+ }, POLLING_DELAY);
+ }
+ }
+
// ComponentCallbacks implementation:
@Override
@@ -123,6 +159,11 @@ public class ScreenOrientationListener {
displayManager.unregisterDisplayListener(this);
}
+ @Override
+ public void toggleAccurateMode() {
+ // Always accurate. Do nothing.
+ }
+
// DisplayListener implementation:
@Override
@@ -244,6 +285,15 @@ public class ScreenOrientationListener {
}
/**
+ * Toggle the accurate mode. Starts listening accurately if the listener
+ * wasn't or stop doing so if it was. This might be a no-op if the
+ * listener always listen accurately.
+ */
+ public void toggleAccurateMode() {
+ mBackend.toggleAccurateMode();
+ }
+
+ /**
* This should be called by classes extending ScreenOrientationListener when
* it is possible that there is a screen orientation change. If there is an
* actual change, the observers will get notified.
@@ -252,12 +302,12 @@ public class ScreenOrientationListener {
int previousOrientation = mOrientation;
updateOrientation();
- DeviceDisplayInfo.create(mAppContext).updateNativeSharedDisplayInfo();
-
if (mOrientation == previousOrientation) {
return;
}
+ DeviceDisplayInfo.create(mAppContext).updateNativeSharedDisplayInfo();
+
for (ScreenOrientationObserver observer : mObservers) {
observer.onScreenOrientationChanged(mOrientation);
}

Powered by Google App Engine
This is Rietveld 408576698