From 2b3f7ef27fc1efd8730b9615df202902fb6e6ded Mon Sep 17 00:00:00 2001 From: Jamie Garside Date: Fri, 23 Jul 2021 17:04:45 +0100 Subject: [PATCH] Make the keyguard pattern view shrink when the device is half open. This is done by converting it to use a ConstraintLayout. This allows us to set a guideline based on the screen percentage to size the pattern view. After doing that, we can resize the entry method in much the same was as we do it for the PIN pad. Note: this CL also moves the pattern view unconditionally to the bottom of the screen. This is by design; the new UX designs anchor all keyguard input methods to the bottom of the screen instead. Bug: 191347942 Test: Manually tested. Change-Id: I1b53cad22ae4d2c7d738c2b48110283f53aa2e68 --- .../layout/keyguard_pattern_view.xml | 71 +++++++++---------- .../keyguard/KeyguardInputViewController.java | 3 +- .../android/keyguard/KeyguardPatternView.java | 21 +++++- .../KeyguardPatternViewController.java | 10 ++- .../KeyguardPatternViewControllerTest.kt | 5 +- 5 files changed, 67 insertions(+), 43 deletions(-) diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_pattern_view.xml b/packages/SystemUI/res-keyguard/layout/keyguard_pattern_view.xml index ce63082868bba..f613a195ea67d 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_pattern_view.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_pattern_view.xml @@ -27,49 +27,44 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" - android:clipChildren="false" - android:clipToPadding="false" androidprv:layout_maxWidth="@dimen/keyguard_security_width" - androidprv:layout_maxHeight="@dimen/keyguard_security_height" - android:gravity="center_horizontal"> + android:clipChildren="false" + android:clipToPadding="false"> - - - + + android:layout_height="wrap_content" + androidprv:layout_constraintGuide_percent="0" + android:orientation="horizontal" /> - + + - - - + diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java index b473f6d36c5cd..75425e1e6ca35 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java @@ -204,7 +204,8 @@ public abstract class KeyguardInputViewController return new KeyguardPatternViewController((KeyguardPatternView) keyguardInputView, mKeyguardUpdateMonitor, securityMode, mLockPatternUtils, keyguardSecurityCallback, mLatencyTracker, mFalsingCollector, - emergencyButtonController, mMessageAreaControllerFactory); + emergencyButtonController, mMessageAreaControllerFactory, + mDevicePostureController); } else if (keyguardInputView instanceof KeyguardPasswordView) { return new KeyguardPasswordViewController((KeyguardPasswordView) keyguardInputView, mKeyguardUpdateMonitor, securityMode, mLockPatternUtils, diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java index 98e7fb48b7a68..a35aedf6f5033 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java @@ -15,6 +15,8 @@ */ package com.android.keyguard; +import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_HALF_OPENED; + import android.content.Context; import android.graphics.Rect; import android.os.SystemClock; @@ -22,16 +24,19 @@ import android.text.TextUtils; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; -import android.view.ViewGroup; import android.view.animation.AnimationUtils; import android.view.animation.Interpolator; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.constraintlayout.widget.ConstraintSet; + import com.android.internal.jank.InteractionJankMonitor; import com.android.internal.widget.LockPatternView; import com.android.settingslib.animation.AppearAnimationCreator; import com.android.settingslib.animation.AppearAnimationUtils; import com.android.settingslib.animation.DisappearAnimationUtils; import com.android.systemui.R; +import com.android.systemui.statusbar.policy.DevicePostureController.DevicePostureInt; public class KeyguardPatternView extends KeyguardInputView implements AppearAnimationCreator { @@ -68,7 +73,7 @@ public class KeyguardPatternView extends KeyguardInputView KeyguardMessageArea mSecurityMessageDisplay; private View mEcaView; - private ViewGroup mContainer; + private ConstraintLayout mContainer; public KeyguardPatternView(Context context) { this(context, null); @@ -90,6 +95,18 @@ public class KeyguardPatternView extends KeyguardInputView mContext, android.R.interpolator.fast_out_linear_in)); } + void onDevicePostureChanged(@DevicePostureInt int posture) { + // Update the guideline based on the device posture... + float halfOpenPercentage = + mContext.getResources().getFloat(R.dimen.half_opened_bouncer_height_ratio); + + ConstraintSet cs = new ConstraintSet(); + cs.clone(mContainer); + cs.setGuidelinePercent(R.id.pin_pad_top_guideline, posture == DEVICE_POSTURE_HALF_OPENED + ? halfOpenPercentage : 0.0f); + cs.applyTo(mContainer); + } + @Override protected void onFinishInflate() { super.onFinishInflate(); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java index d5be7bacaadc4..94e07b713915c 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java @@ -38,6 +38,7 @@ import com.android.settingslib.Utils; import com.android.systemui.R; import com.android.systemui.classifier.FalsingClassifier; import com.android.systemui.classifier.FalsingCollector; +import com.android.systemui.statusbar.policy.DevicePostureController; import java.util.List; @@ -56,6 +57,9 @@ public class KeyguardPatternViewController private final FalsingCollector mFalsingCollector; private final EmergencyButtonController mEmergencyButtonController; private final KeyguardMessageAreaController.Factory mMessageAreaControllerFactory; + private final DevicePostureController mPostureController; + private final DevicePostureController.Callback mPostureCallback = + posture -> mView.onDevicePostureChanged(posture); private KeyguardMessageAreaController mMessageAreaController; private LockPatternView mLockPatternView; @@ -192,7 +196,8 @@ public class KeyguardPatternViewController LatencyTracker latencyTracker, FalsingCollector falsingCollector, EmergencyButtonController emergencyButtonController, - KeyguardMessageAreaController.Factory messageAreaControllerFactory) { + KeyguardMessageAreaController.Factory messageAreaControllerFactory, + DevicePostureController postureController) { super(view, securityMode, keyguardSecurityCallback, emergencyButtonController); mKeyguardUpdateMonitor = keyguardUpdateMonitor; mLockPatternUtils = lockPatternUtils; @@ -203,6 +208,7 @@ public class KeyguardPatternViewController KeyguardMessageArea kma = KeyguardMessageArea.findSecurityMessageDisplay(mView); mMessageAreaController = mMessageAreaControllerFactory.create(kma); mLockPatternView = mView.findViewById(R.id.lockPatternView); + mPostureController = postureController; } @Override @@ -235,6 +241,7 @@ public class KeyguardPatternViewController getKeyguardSecurityCallback().onCancelClicked(); }); } + mPostureController.addCallback(mPostureCallback); } @Override @@ -247,6 +254,7 @@ public class KeyguardPatternViewController if (cancelBtn != null) { cancelBtn.setOnClickListener(null); } + mPostureController.removeCallback(mPostureCallback); } @Override diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt index bb71bed84f43d..8e1e42a9c9a25 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt @@ -26,6 +26,7 @@ import com.android.systemui.R import com.android.systemui.SysuiTestCase import com.android.systemui.classifier.FalsingCollector import com.android.systemui.classifier.FalsingCollectorFake +import com.android.systemui.statusbar.policy.DevicePostureController import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -62,6 +63,8 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { private lateinit var mKeyguardMessageAreaController: KeyguardMessageAreaController @Mock private lateinit var mLockPatternView: LockPatternView + @Mock + private lateinit var mPostureController: DevicePostureController private lateinit var mKeyguardPatternViewController: KeyguardPatternViewController @@ -78,7 +81,7 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { mKeyguardPatternViewController = KeyguardPatternViewController(mKeyguardPatternView, mKeyguardUpdateMonitor, mSecurityMode, mLockPatternUtils, mKeyguardSecurityCallback, mLatencyTracker, mFalsingCollector, mEmergencyButtonController, - mKeyguardMessageAreaControllerFactory) + mKeyguardMessageAreaControllerFactory, mPostureController) } @Test