From 5da6430fff7812e58ee7e9a05c62d72c36f366c8 Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Mon, 5 Nov 2012 14:16:59 -0800 Subject: [PATCH] Optimize keyguard/IME interactions Change the keyguard window to LAYOUT_IN_SCREEN | LAYOUT_INSET_DECOR and make the ViewManagerHost fitSystemWindows. This eliminates the need to resize the actual window and associated surfaces when the IME comes and goes. Force the widget pager to measure at the fullscreen size of the keyguard, even if the IME is showing. This causes the widgets to clip instead of resize, removing a few more moving parts that can be distracting/affect performance. Partially improves bug 7427586 Change-Id: I0d86d0ca8045f737fa97ca5d1e7f6a49f746b999 --- .../impl/keyguard/KeyguardViewManager.java | 4 ++- .../impl/keyguard/SlidingChallengeLayout.java | 28 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewManager.java b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewManager.java index 7c117d9f1323c..6d886521b7784 100644 --- a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewManager.java +++ b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewManager.java @@ -122,6 +122,7 @@ public class KeyguardViewManager { class ViewManagerHost extends FrameLayout { public ViewManagerHost(Context context) { super(context); + setFitsSystemWindows(true); } @Override @@ -164,7 +165,8 @@ public class KeyguardViewManager { mKeyguardHost = new ViewManagerHost(mContext); - int flags = WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN + int flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN + | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; if (!mNeedsInput) { diff --git a/policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java b/policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java index 2712494b50e1a..f98ba352f5468 100644 --- a/policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java +++ b/policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java @@ -29,6 +29,7 @@ import android.graphics.Paint; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.util.AttributeSet; +import android.util.DisplayMetrics; import android.util.FloatProperty; import android.util.Log; import android.util.Property; @@ -64,6 +65,8 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout private Drawable mFrameDrawable; private boolean mEdgeCaptured; + private DisplayMetrics mDisplayMetrics; + // Initialized during measurement from child layoutparams private View mExpandChallengeView; private KeyguardSecurityContainer mChallengeView; @@ -264,7 +267,8 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mTouchSlopSquare = mTouchSlop * mTouchSlop; - final float density = res.getDisplayMetrics().density; + mDisplayMetrics = res.getDisplayMetrics(); + final float density = mDisplayMetrics.density; // top half of the lock icon, plus another 25% to be sure mDragHandleClosedAbove = (int) (DRAG_HANDLE_CLOSED_ABOVE * density + 0.5f); @@ -887,9 +891,27 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout continue; } // Don't measure the challenge view twice! - if (child != mChallengeView) { - measureChildWithMargins(child, widthSpec, 0, heightSpec, 0); + if (child == mChallengeView) continue; + + // Measure children. Widget frame measures special, so that we can ignore + // insets for the IME. + int parentWidthSpec = widthSpec, parentHeightSpec = heightSpec; + final LayoutParams lp = (LayoutParams) child.getLayoutParams(); + if (lp.childType == LayoutParams.CHILD_TYPE_WIDGETS) { + final View root = getRootView(); + if (root != null) { + // This calculation is super dodgy and relies on several assumptions. + // Specifically that the root of the window will be padded in for insets + // and that the window is LAYOUT_IN_SCREEN. + final int windowWidth = mDisplayMetrics.widthPixels; + final int windowHeight = mDisplayMetrics.heightPixels - root.getPaddingTop(); + parentWidthSpec = MeasureSpec.makeMeasureSpec( + windowWidth, MeasureSpec.EXACTLY); + parentHeightSpec = MeasureSpec.makeMeasureSpec( + windowHeight, MeasureSpec.EXACTLY); + } } + measureChildWithMargins(child, parentWidthSpec, 0, parentHeightSpec, 0); } }