From dbde425e216e47ec9fbbf521146636c40fe3198e Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Wed, 24 Mar 2010 15:47:17 -0400 Subject: [PATCH] Use the Display orientation rather than the accelerometer. Register to receive configuration changes and query the Display rotation as that will reflect both device orientation and an open keyboard. Bug: 2219138 Change-Id: Ibd6119ae0c7d473e1a9ede3af24bb4b584c9db71 --- core/java/android/webkit/BrowserFrame.java | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/core/java/android/webkit/BrowserFrame.java b/core/java/android/webkit/BrowserFrame.java index b758d22617303..7e871d0e25cd7 100644 --- a/core/java/android/webkit/BrowserFrame.java +++ b/core/java/android/webkit/BrowserFrame.java @@ -17,7 +17,10 @@ package android.webkit; import android.app.ActivityManager; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.content.res.AssetManager; import android.database.Cursor; import android.graphics.Bitmap; @@ -31,7 +34,7 @@ import android.provider.OpenableColumns; import android.util.Log; import android.util.TypedValue; import android.view.Surface; -import android.view.WindowOrientationListener; +import android.view.WindowManager; import junit.framework.Assert; @@ -73,8 +76,10 @@ class BrowserFrame extends Handler { // Attached Javascript interfaces private Map mJSInterfaceMap; + // WindowManager to obtain the Display configuration. + private WindowManager mWindowManager; // Orientation listener - private WindowOrientationListener mOrientationListener; + private BroadcastReceiver mOrientationListener; // message ids // a message posted when a frame loading is completed @@ -153,9 +158,15 @@ class BrowserFrame extends Handler { Log.v(LOGTAG, "BrowserFrame constructor: this=" + this); } - mOrientationListener = new WindowOrientationListener(context) { - @Override - public void onOrientationChanged(int orientation) { + mWindowManager = (WindowManager) context.getSystemService( + Context.WINDOW_SERVICE); + mOrientationListener = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (Intent.ACTION_CONFIGURATION_CHANGED.equals( + intent.getAction())) { + int orientation = + mWindowManager.getDefaultDisplay().getOrientation(); switch (orientation) { case Surface.ROTATION_90: orientation = 90; @@ -174,9 +185,12 @@ class BrowserFrame extends Handler { } sendMessage( obtainMessage(ORIENTATION_CHANGED, orientation, 0)); + } + } }; - mOrientationListener.enable(); + context.registerReceiver(mOrientationListener, + new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); } /** @@ -383,7 +397,7 @@ class BrowserFrame extends Handler { * Destroy all native components of the BrowserFrame. */ public void destroy() { - mOrientationListener.disable(); + mContext.unregisterReceiver(mOrientationListener); nativeDestroyFrame(); mBlockMessages = true; removeCallbacksAndMessages(null);