OSDN Git Service

Introduce transparent bars to the keyguard.
authorJohn Spurlock <jspurlock@google.com>
Sat, 21 Sep 2013 22:41:53 +0000 (18:41 -0400)
committerJohn Spurlock <jspurlock@google.com>
Mon, 23 Sep 2013 19:59:15 +0000 (15:59 -0400)
Driven by a new framework config bool. Tested on all layouts,
but disabled by default.  Can be enabled with a config overlay.

(Sliding/MultiPane)ChallengeLayout have custom measure/layout
logic that peeks at the root view's padding (!).  So we must keep
the root view's padding = system window insets. However, we need
the scrims + the fullscreen camera widget preview to use the entire
display size if the bars are transparent.

So the approach is to maintain the root view's
(KeyguardViewManager$ViewManagerHost) padding as before via
setFitsSystemWindows(true) but allow non KeyguardHostViews to
extend into the padding if bars are transparent via a custom
measure/draw on the root view.

KeyguardHostView background + challege scrims moved up to the
root view.

Also:
- Remove logspam line for fixed bug.

- Fix status bar staying opaque on interaction on secure keyguard.

Known issues:
- Nav bar blip dismissing global actions, keyguard app widget picker
bars are opaque.  Both will use the new inherit flag once it exists.

- Emergency dialer layout dance, will be fixed in the phone project.

Bug:10606085
Change-Id: I2648b4ee9a54a67324ce9dcbab976ad4da4bbcfa

12 files changed:
core/res/res/values/config.xml
core/res/res/values/symbols.xml
packages/Keyguard/res/layout-land/keyguard_host_view.xml
packages/Keyguard/res/layout-port/keyguard_host_view.xml
packages/Keyguard/res/layout-sw600dp-port/keyguard_host_view.xml
packages/Keyguard/res/values/alias.xml
packages/Keyguard/src/com/android/keyguard/KeyguardHostView.java
packages/Keyguard/src/com/android/keyguard/KeyguardViewBase.java
packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java
packages/Keyguard/src/com/android/keyguard/MultiPaneChallengeLayout.java
packages/Keyguard/src/com/android/keyguard/SlidingChallengeLayout.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java

index 0adda56..84a0d37 100644 (file)
     <!-- Don't show lock screen before unlock screen (PIN/pattern/password) -->
     <bool name="config_enableLockBeforeUnlockScreen">false</bool>
 
-    <!-- Diable lockscreen rotation by default -->
+    <!-- Disable lockscreen rotation by default -->
     <bool name="config_enableLockScreenRotation">false</bool>
 
+    <!-- Disable lockscreen transparent bars by default -->
+    <bool name="config_enableLockScreenTransparentBars">false</bool>
+
     <!-- Enable puk unlockscreen by default.
          If unlock screen is disabled, the puk should be unlocked through Emergency Dialer -->
     <bool name="config_enable_puk_unlock_screen">true</bool>
index 8370b9f..14b319f 100644 (file)
   <java-symbol type="bool" name="config_disableMenuKeyInLockScreen" />
   <java-symbol type="bool" name="config_enableLockBeforeUnlockScreen" />
   <java-symbol type="bool" name="config_enableLockScreenRotation" />
+  <java-symbol type="bool" name="config_enableLockScreenTransparentBars" />
   <java-symbol type="bool" name="config_lidControlsSleep" />
   <java-symbol type="bool" name="config_reverseDefaultRotation" />
   <java-symbol type="bool" name="config_showNavigationBar" />
index eeb9ee7..87b8b59 100644 (file)
             androidprv:layout_maxHeight="480dp" />
         <include layout="@layout/keyguard_multi_user_selector"/>
 
-        <View android:layout_width="match_parent"
-              android:layout_height="match_parent"
-              androidprv:layout_childType="scrim"
-              android:background="#99000000" />
-
         <com.android.keyguard.KeyguardSecurityContainer
             android:id="@+id/keyguard_security_container"
             android:layout_width="wrap_content"
index 8498dcf..355739e 100644 (file)
                 android:layout_gravity="center"/>
         </FrameLayout>
 
-        <View android:layout_width="match_parent"
-              android:layout_height="match_parent"
-              androidprv:layout_childType="scrim"
-              android:background="#99000000" />
-
         <com.android.keyguard.KeyguardSecurityContainer
             android:id="@+id/keyguard_security_container"
             android:layout_width="wrap_content"
index 77bc9b5..42dbe9d 100644 (file)
 
         <include layout="@layout/keyguard_multi_user_selector"/>
 
-        <View android:layout_width="match_parent"
-              android:layout_height="match_parent"
-              androidprv:layout_childType="scrim"
-              android:background="#99000000" />
-
         <com.android.keyguard.KeyguardSecurityContainer
             android:id="@+id/keyguard_security_container"
             android:layout_width="wrap_content"
index 47291b2..c964391 100644 (file)
@@ -46,6 +46,9 @@
     <!-- Alias used to reference framework configuration for screen rotation.  -->
     <item type="bool" name="config_enableLockScreenRotation">@*android:bool/config_enableLockScreenRotation</item>
 
+    <!-- Alias used to reference framework configuration for transparent bars.  -->
+    <item type="bool" name="config_enableLockScreenTransparentBars">@*android:bool/config_enableLockScreenTransparentBars</item>
+
     <!-- Alias used to reference framework activity duration.  -->
     <item type="integer" name="config_activityDefaultDur">@*android:integer/config_activityDefaultDur</item>
 
index 0787286..aa43711 100644 (file)
@@ -319,6 +319,7 @@ public class KeyguardHostView extends KeyguardViewBase {
     }
 
     private SlidingChallengeLayout mSlidingChallengeLayout;
+    private MultiPaneChallengeLayout mMultiPaneChallengeLayout;
 
     @Override
     public boolean onTouchEvent(MotionEvent ev) {
@@ -372,8 +373,10 @@ public class KeyguardHostView extends KeyguardViewBase {
         mAppWidgetContainer.setViewStateManager(mViewStateManager);
         mAppWidgetContainer.setLockPatternUtils(mLockPatternUtils);
 
+        mMultiPaneChallengeLayout =
+                (MultiPaneChallengeLayout) findViewById(R.id.multi_pane_challenge);
         ChallengeLayout challenge = mSlidingChallengeLayout != null ? mSlidingChallengeLayout :
-            (ChallengeLayout) findViewById(R.id.multi_pane_challenge);
+                mMultiPaneChallengeLayout;
         challenge.setOnBouncerStateChangedListener(mViewStateManager);
         mAppWidgetContainer.setBouncerAnimationDuration(challenge.getBouncerAnimationDuration());
         mViewStateManager.setPagedView(mAppWidgetContainer);
@@ -399,6 +402,11 @@ public class KeyguardHostView extends KeyguardViewBase {
         updateSecurityViews();
     }
 
+    public void setScrimView(View scrim) {
+        if (mSlidingChallengeLayout != null) mSlidingChallengeLayout.setScrimView(scrim);
+        if (mMultiPaneChallengeLayout != null) mMultiPaneChallengeLayout.setScrimView(scrim);
+    }
+
     private void setBackButtonEnabled(boolean enabled) {
         if (mContext instanceof Activity) return;  // always enabled in activity mode
         setSystemUiVisibility(enabled ?
index 893562e..bff1f93 100644 (file)
@@ -18,11 +18,6 @@ package com.android.keyguard;
 
 import android.app.Activity;
 import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.ColorFilter;
-import android.graphics.PixelFormat;
-import android.graphics.PorterDuff;
-import android.graphics.drawable.Drawable;
 import android.media.AudioManager;
 import android.media.IAudioService;
 import android.os.RemoteException;
@@ -45,7 +40,6 @@ import android.widget.FrameLayout;
  */
 public abstract class KeyguardViewBase extends FrameLayout {
 
-    private static final int BACKGROUND_COLOR = 0x70000000;
     private AudioManager mAudioManager;
     private TelephonyManager mTelephonyManager = null;
     protected KeyguardViewMediator.ViewMediatorCallback mViewMediatorCallback;
@@ -55,38 +49,12 @@ public abstract class KeyguardViewBase extends FrameLayout {
     // the audio service will bring up the volume dialog.
     private static final boolean KEYGUARD_MANAGES_VOLUME = true;
 
-    // This is a faster way to draw the background on devices without hardware acceleration
-    private static final Drawable mBackgroundDrawable = new Drawable() {
-        @Override
-        public void draw(Canvas canvas) {
-            canvas.drawColor(BACKGROUND_COLOR, PorterDuff.Mode.SRC);
-        }
-
-        @Override
-        public void setAlpha(int alpha) {
-        }
-
-        @Override
-        public void setColorFilter(ColorFilter cf) {
-        }
-
-        @Override
-        public int getOpacity() {
-            return PixelFormat.TRANSLUCENT;
-        }
-    };
-
     public KeyguardViewBase(Context context) {
         this(context, null);
     }
 
     public KeyguardViewBase(Context context, AttributeSet attrs) {
         super(context, attrs);
-        resetBackground();
-    }
-
-    public void resetBackground() {
-        setBackground(mBackgroundDrawable);
     }
 
     /**
index 4837458..177e0f8 100644 (file)
@@ -26,8 +26,12 @@ import android.content.Context;
 import android.content.pm.ActivityInfo;
 import android.content.res.Configuration;
 import android.content.res.Resources;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
 import android.graphics.PixelFormat;
+import android.graphics.PorterDuff;
 import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Parcelable;
@@ -67,7 +71,7 @@ public class KeyguardViewManager {
     private WindowManager.LayoutParams mWindowLayoutParams;
     private boolean mNeedsInput = false;
 
-    private FrameLayout mKeyguardHost;
+    private ViewManagerHost mKeyguardHost;
     private KeyguardHostView mKeyguardView;
 
     private boolean mScreenOn = false;
@@ -108,7 +112,11 @@ public class KeyguardViewManager {
         // useful on any keyguard screen but can be re-shown by dialogs or SHOW_WHEN_LOCKED
         // activities. Other disabled bits are handled by the KeyguardViewMediator talking
         // directly to the status bar service.
-        final int visFlags = View.STATUS_BAR_DISABLE_HOME;
+        int visFlags = View.STATUS_BAR_DISABLE_HOME;
+        if (shouldEnableTransparentBars()) {
+            visFlags |= View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS
+                      | View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION;
+        }
         if (DEBUG) Log.v(TAG, "show:setSystemUiVisibility(" + Integer.toHexString(visFlags)+")");
         mKeyguardHost.setSystemUiVisibility(visFlags);
 
@@ -124,16 +132,81 @@ public class KeyguardViewManager {
                 || res.getBoolean(R.bool.config_enableLockScreenRotation);
     }
 
+    private boolean shouldEnableTransparentBars() {
+        Resources res = mContext.getResources();
+        return res.getBoolean(R.bool.config_enableLockScreenTransparentBars);
+    }
+
     class ViewManagerHost extends FrameLayout {
-        public ViewManagerHost(Context context) {
+        private static final int BACKGROUND_COLOR = 0x70000000;
+        // This is a faster way to draw the background on devices without hardware acceleration
+        private final Drawable mBackgroundDrawable = new Drawable() {
+            @Override
+            public void draw(Canvas canvas) {
+                canvas.drawColor(BACKGROUND_COLOR, PorterDuff.Mode.SRC);
+            }
+
+            @Override
+            public void setAlpha(int alpha) {
+            }
+
+            @Override
+            public void setColorFilter(ColorFilter cf) {
+            }
+
+            @Override
+            public int getOpacity() {
+                return PixelFormat.TRANSLUCENT;
+            }
+        };
+        private final View mScrimView;
+        private boolean mExtendIntoPadding;
+        public ViewManagerHost(Context context, boolean extendIntoPadding) {
             super(context);
+            mExtendIntoPadding = extendIntoPadding;
             setFitsSystemWindows(true);
+            setClipToPadding(!mExtendIntoPadding);
+            setBackground(mBackgroundDrawable);
+
+            mScrimView = new View(context);
+            mScrimView.setVisibility(View.GONE);
+            mScrimView.setBackgroundColor(0x99000000);
+            addView(mScrimView);
+        }
+
+        private boolean considerPadding(View child) {
+            return !mExtendIntoPadding || child instanceof KeyguardHostView;
+        }
+
+        @Override
+        protected void measureChildWithMargins(View child,
+                int parentWidthMeasureSpec, int widthUsed,
+                int parentHeightMeasureSpec, int heightUsed) {
+            if (considerPadding(child)) {
+                // don't extend into padding (default behavior)
+                super.measureChildWithMargins(child,
+                        parentWidthMeasureSpec, widthUsed,
+                        parentHeightMeasureSpec, heightUsed);
+            } else {
+                // allowed to extend into padding (scrim / camera preview)
+                child.measure(parentWidthMeasureSpec, parentHeightMeasureSpec);
+            }
         }
 
         @Override
-        protected boolean fitSystemWindows(Rect insets) {
-            Log.v("TAG", "bug 7643792: fitSystemWindows(" + insets.toShortString() + ")");
-            return super.fitSystemWindows(insets);
+        protected void onLayout(boolean changed, int l, int t, int r, int b) {
+            final int count = getChildCount();
+            for (int i = 0; i < count; i++) {
+                final View child = getChildAt(i);
+                int cl = l, ct = t, cr = r, cb = b;
+                if (considerPadding(child)) {
+                    cl += mPaddingLeft;
+                    ct += mPaddingTop;
+                    cr -= mPaddingRight;
+                    cb -= mPaddingBottom;
+                }
+                child.layout(cl, ct, cr, cb);
+            }
         }
 
         @Override
@@ -179,7 +252,7 @@ public class KeyguardViewManager {
         if (mKeyguardHost == null) {
             if (DEBUG) Log.d(TAG, "keyguard host is null, creating it...");
 
-            mKeyguardHost = new ViewManagerHost(mContext);
+            mKeyguardHost = new ViewManagerHost(mContext, shouldEnableTransparentBars());
 
             int flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                     | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
@@ -233,6 +306,7 @@ public class KeyguardViewManager {
         mKeyguardView.setViewMediatorCallback(mViewMediatorCallback);
         mKeyguardView.initializeSwitchingUserState(options != null &&
                 options.getBoolean(IS_SWITCHING_USER));
+        mKeyguardView.setScrimView(mKeyguardHost.mScrimView);
 
         // HACK
         // The keyguard view will have set up window flags in onFinishInflate before we set
index 8fd39c0..76a7fe3 100644 (file)
@@ -172,10 +172,12 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
             mScrimView.setOnClickListener(null);
         }
         mScrimView = scrim;
-        mScrimView.setAlpha(mIsBouncing ? 1.0f : 0.0f);
-        mScrimView.setVisibility(mIsBouncing ? VISIBLE : INVISIBLE);
-        mScrimView.setFocusable(true);
-        mScrimView.setOnClickListener(mScrimClickListener);
+        if (mScrimView != null) {
+            mScrimView.setAlpha(mIsBouncing ? 1.0f : 0.0f);
+            mScrimView.setVisibility(mIsBouncing ? VISIBLE : INVISIBLE);
+            mScrimView.setFocusable(true);
+            mScrimView.setOnClickListener(mScrimClickListener);
+        }
     }
 
     private int getVirtualHeight(LayoutParams lp, int height, int heightUsed) {
index 05b35a1..4a4e7fa 100644 (file)
@@ -367,9 +367,11 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
             mScrimView.setOnClickListener(null);
         }
         mScrimView = scrim;
-        mScrimView.setVisibility(mIsBouncing ? VISIBLE : GONE);
-        mScrimView.setFocusable(true);
-        mScrimView.setOnClickListener(mScrimClickListener);
+        if (mScrimView != null) {
+            mScrimView.setVisibility(mIsBouncing ? VISIBLE : GONE);
+            mScrimView.setFocusable(true);
+            mScrimView.setOnClickListener(mScrimClickListener);
+        }
     }
 
     /**
index a600aae..e77b420 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.systemui.statusbar.phone;
 
+import android.app.StatusBarManager;
 import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.Paint;
@@ -111,6 +112,10 @@ public class StatusBarWindowView extends FrameLayout
         if (!handled) {
             handled = super.onTouchEvent(ev);
         }
+        final int action = ev.getAction();
+        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
+            mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
+        }
         return handled;
     }