diff options
author | mlamouri@chromium.org <mlamouri@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 13:50:09 +0000 |
---|---|---|
committer | mlamouri@chromium.org <mlamouri@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 13:50:09 +0000 |
commit | 0aa9e8b3de6affa566e3bfc6018a5d087327d89f (patch) | |
tree | e2d8154b517dd6b3af714c5d22bf279635b49d26 | |
parent | 15b5420ecf6500395d2083ade0016d61885e481a (diff) | |
download | chromium_src-0aa9e8b3de6affa566e3bfc6018a5d087327d89f.zip chromium_src-0aa9e8b3de6affa566e3bfc6018a5d087327d89f.tar.gz chromium_src-0aa9e8b3de6affa566e3bfc6018a5d087327d89f.tar.bz2 |
Update SharedDeviveDisplay from ScreenOrientationListener.
Instead of having DeviceDisplayInfo listening for onConfigurationChange,
this patch changes the update to come from ScreenOrientationListener.
Ideally, we might want to have a DisplayListener that would be used by
ScreenOrientationListener and would update a cached DeviceDisplayInfo.
BUG=354275
Review URL: https://codereview.chromium.org/219963002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260857 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 11 insertions, 27 deletions
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 a14d76b..7e809c0 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 @@ -19,6 +19,7 @@ import com.google.common.annotations.VisibleForTesting; import org.chromium.base.ObserverList; import org.chromium.base.ThreadUtils; +import org.chromium.ui.gfx.DeviceDisplayInfo; /** * ScreenOrientationListener is a class that informs its observers when the @@ -251,6 +252,8 @@ public class ScreenOrientationListener { int previousOrientation = mOrientation; updateOrientation(); + DeviceDisplayInfo.create(mAppContext).updateNativeSharedDisplayInfo(); + if (mOrientation == previousOrientation) { return; } diff --git a/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java index c154ea0..5f7e1c5 100644 --- a/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java +++ b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java @@ -4,9 +4,7 @@ package org.chromium.ui.gfx; -import android.content.ComponentCallbacks; import android.content.Context; -import android.content.res.Configuration; import android.graphics.PixelFormat; import android.graphics.Point; import android.os.Build; @@ -27,7 +25,6 @@ import org.chromium.base.JNINamespace; @JNINamespace("gfx") public class DeviceDisplayInfo { - private final Context mAppContext; private final WindowManager mWinManager; private Point mTempPoint = new Point(); @@ -156,21 +153,11 @@ public class DeviceDisplayInfo { return mAppContext.getResources().getConfiguration().smallestScreenWidthDp; } - private void registerListener() { - mAppContext.registerComponentCallbacks( - new ComponentCallbacks() { - @Override - public void onConfigurationChanged(Configuration configuration) { - updateNativeSharedDisplayInfo(); - } - - @Override - public void onLowMemory() { - } - }); - } - - private void updateNativeSharedDisplayInfo() { + /** + * Inform the native implementation to update its cached representation of + * the DeviceDisplayInfo values. + */ + public void updateNativeSharedDisplayInfo() { nativeUpdateSharedDeviceDisplayInfo( getDisplayHeight(), getDisplayWidth(), getPhysicalDisplayHeight(), getPhysicalDisplayWidth(), @@ -188,17 +175,11 @@ public class DeviceDisplayInfo { * @param context A context to use. * @return DeviceDisplayInfo associated with a given Context. */ + @CalledByNative public static DeviceDisplayInfo create(Context context) { return new DeviceDisplayInfo(context); } - @CalledByNative - private static DeviceDisplayInfo createWithListener(Context context) { - DeviceDisplayInfo deviceDisplayInfo = new DeviceDisplayInfo(context); - deviceDisplayInfo.registerListener(); - return deviceDisplayInfo; - } - private native void nativeUpdateSharedDeviceDisplayInfo( int displayHeight, int displayWidth, int physicalDisplayHeight, int physicalDisplayWidth, diff --git a/ui/gfx/android/shared_device_display_info.cc b/ui/gfx/android/shared_device_display_info.cc index 32dc73e..ae02ef5 100644 --- a/ui/gfx/android/shared_device_display_info.cc +++ b/ui/gfx/android/shared_device_display_info.cc @@ -113,8 +113,8 @@ SharedDeviceDisplayInfo::SharedDeviceDisplayInfo() smallest_dip_width_(0) { JNIEnv* env = base::android::AttachCurrentThread(); j_device_info_.Reset( - Java_DeviceDisplayInfo_createWithListener(env, - base::android::GetApplicationContext())); + Java_DeviceDisplayInfo_create( + env, base::android::GetApplicationContext())); UpdateDisplayInfo(env, j_device_info_.obj(), Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()), Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()), |