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); |
} |