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

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: call ScreenOrientationListener on UI thread Created 6 years, 4 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 4cd67865a4dea8d0546e81dccba009eb8867c70e..381f98b0992bfb466337d430e14cac89934af54c 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,19 @@ public class ScreenOrientationListener {
* when the last observer is removed.
*/
void stopListening();
+
+ /**
+ * Toggle the accurate mode if it wasn't already doing so. The backend
+ * will keep track of the number of times this has been called.
+ */
+ void startAccurateListening();
+
+ /**
+ * Request to stop the accurate mode. It will effectively be stopped
+ * only if this method is called as many times as
+ * startAccurateListening().
+ */
+ void stopAccurateListening();
}
/**
@@ -69,10 +82,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 int mAccurateCount = 0;
+
// ScreenOrientationListenerBackend implementation:
@Override
@@ -85,6 +104,36 @@ public class ScreenOrientationListener {
mAppContext.unregisterComponentCallbacks(this);
}
+ @Override
+ public void startAccurateListening() {
+ ++mAccurateCount;
+
+ if (mAccurateCount > 1)
+ return;
+
+ // Start polling if we went from 0 to 1. The polling will
+ // automatically stop when mAccurateCount reaches 0.
+ final ScreenOrientationConfigurationListener self = this;
+ ThreadUtils.postOnUiThreadDelayed(new Runnable() {
+ @Override
+ public void run() {
+ self.onConfigurationChanged(null);
+
+ if (self.mAccurateCount < 1)
+ return;
+
+ ThreadUtils.postOnUiThreadDelayed(this,
+ ScreenOrientationConfigurationListener.POLLING_DELAY);
+ }
+ }, POLLING_DELAY);
+ }
+
+ @Override
+ public void stopAccurateListening() {
+ --mAccurateCount;
+ assert mAccurateCount >= 0;
+ }
+
// ComponentCallbacks implementation:
@Override
@@ -123,6 +172,16 @@ public class ScreenOrientationListener {
displayManager.unregisterDisplayListener(this);
}
+ @Override
+ public void startAccurateListening() {
+ // Always accurate. Do nothing.
+ }
+
+ @Override
+ public void stopAccurateListening() {
+ // Always accurate. Do nothing.
+ }
+
// DisplayListener implementation:
@Override
@@ -235,6 +294,22 @@ public class ScreenOrientationListener {
}
/**
+ * Toggle the accurate mode if it wasn't already doing so. The backend will
+ * keep track of the number of times this has been called.
+ */
+ public void startAccurateListening() {
+ mBackend.startAccurateListening();
+ }
+
+ /**
+ * Request to stop the accurate mode. It will effectively be stopped only if
+ * this method is called as many times as startAccurateListening().
+ */
+ public void stopAccurateListening() {
+ mBackend.stopAccurateListening();
+ }
+
+ /**
* 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.
@@ -243,12 +318,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