From 18ec43f7f78c510f64a9f1012b0d3749e73987cb Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Thu, 24 Jun 2021 11:11:44 -0400 Subject: [PATCH] PIN bouncer - basic landscape support As with Android 11, there are specific scenarios where the bouncer can be shown in landscape position. The UX updates for Android 12 made this completely unusable. Return the PIN bouncer to a functional state. There is still outstanding work to fully support landscape for keyguard. Fixes: 185735801 Test: manual (use camera over ls, rotate, hit unlock) Change-Id: I3090afe1534cfa2b01bd35b91e1e273858117743 --- .../res-keyguard/layout/keyguard_pin_view.xml | 4 +-- .../values-sw360dp-land/dimens.xml | 26 ++++++++++++++ .../SystemUI/res-keyguard/values/dimens.xml | 2 ++ .../com/android/keyguard/KeyguardPINView.java | 36 +++++++++++++++++++ .../com/android/keyguard/NumPadButton.java | 13 +++++-- .../src/com/android/keyguard/NumPadKey.java | 13 +++++-- 6 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 packages/SystemUI/res-keyguard/values-sw360dp-land/dimens.xml diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml b/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml index a957df6537ff3..02cb2bcfad819 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_pin_view.xml @@ -44,7 +44,7 @@ android:id="@+id/row0" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingBottom="16dp" + android:paddingBottom="@dimen/num_pad_entry_row_margin_bottom" > diff --git a/packages/SystemUI/res-keyguard/values-sw360dp-land/dimens.xml b/packages/SystemUI/res-keyguard/values-sw360dp-land/dimens.xml new file mode 100644 index 0000000000000..eb5843b5a1b7c --- /dev/null +++ b/packages/SystemUI/res-keyguard/values-sw360dp-land/dimens.xml @@ -0,0 +1,26 @@ + + + + 4dp + 4dp + 4dp + 50dp + 4dp + diff --git a/packages/SystemUI/res-keyguard/values/dimens.xml b/packages/SystemUI/res-keyguard/values/dimens.xml index e8f7b353f7a9e..7e3c87b24f07b 100644 --- a/packages/SystemUI/res-keyguard/values/dimens.xml +++ b/packages/SystemUI/res-keyguard/values/dimens.xml @@ -41,6 +41,7 @@ 20dp 18dp + 12dp @@ -88,6 +89,7 @@ 72dp + 16dp 6dp 12dp diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java index 2325b554d5075..8fc4240e1054d 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java @@ -17,16 +17,20 @@ package com.android.keyguard; import android.content.Context; +import android.content.res.Configuration; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import android.view.animation.AnimationUtils; +import android.widget.LinearLayout; import com.android.internal.jank.InteractionJankMonitor; import com.android.settingslib.animation.AppearAnimationUtils; import com.android.settingslib.animation.DisappearAnimationUtils; import com.android.systemui.R; +import java.util.List; + /** * Displays a PIN pad for unlocking. */ @@ -63,6 +67,11 @@ public class KeyguardPINView extends KeyguardPinBasedInputView { R.dimen.disappear_y_translation); } + @Override + protected void onConfigurationChanged(Configuration newConfig) { + updateMargins(); + } + @Override protected void resetState() { } @@ -72,6 +81,33 @@ public class KeyguardPINView extends KeyguardPinBasedInputView { return R.id.pinEntry; } + private void updateMargins() { + int bottomMargin = mContext.getResources().getDimensionPixelSize( + R.dimen.num_pad_row_margin_bottom); + + for (ViewGroup vg : List.of(mRow1, mRow2, mRow3)) { + ((LinearLayout.LayoutParams) vg.getLayoutParams()).setMargins(0, 0, 0, bottomMargin); + } + + bottomMargin = mContext.getResources().getDimensionPixelSize( + R.dimen.num_pad_entry_row_margin_bottom); + ((LinearLayout.LayoutParams) mRow0.getLayoutParams()).setMargins(0, 0, 0, bottomMargin); + + if (mEcaView != null) { + int ecaTopMargin = mContext.getResources().getDimensionPixelSize( + R.dimen.keyguard_eca_top_margin); + int ecaBottomMargin = mContext.getResources().getDimensionPixelSize( + R.dimen.keyguard_eca_bottom_margin); + ((LinearLayout.LayoutParams) mEcaView.getLayoutParams()).setMargins(0, ecaTopMargin, + 0, ecaBottomMargin); + } + + View entryView = findViewById(R.id.pinEntry); + ViewGroup.LayoutParams lp = entryView.getLayoutParams(); + lp.height = mContext.getResources().getDimensionPixelSize(R.dimen.keyguard_password_height); + entryView.setLayoutParams(lp); + } + @Override protected void onFinishInflate() { super.onFinishInflate(); diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadButton.java b/packages/SystemUI/src/com/android/keyguard/NumPadButton.java index 0d31906d2f808..099e6f4b5341e 100644 --- a/packages/SystemUI/src/com/android/keyguard/NumPadButton.java +++ b/packages/SystemUI/src/com/android/keyguard/NumPadButton.java @@ -17,6 +17,7 @@ package com.android.keyguard; import android.content.Context; import android.content.res.ColorStateList; +import android.content.res.Configuration; import android.graphics.drawable.Drawable; import android.graphics.drawable.RippleDrawable; import android.graphics.drawable.VectorDrawable; @@ -26,7 +27,6 @@ import android.view.MotionEvent; import androidx.annotation.Nullable; import com.android.settingslib.Utils; -import com.android.systemui.R; /** * Similar to the {@link NumPadKey}, but displays an image. @@ -35,6 +35,7 @@ public class NumPadButton extends AlphaOptimizedImageButton { @Nullable private NumPadAnimator mAnimator; + private int mOrientation; public NumPadButton(Context context, AttributeSet attrs) { super(context, attrs); @@ -48,6 +49,11 @@ public class NumPadButton extends AlphaOptimizedImageButton { } } + @Override + protected void onConfigurationChanged(Configuration newConfig) { + mOrientation = newConfig.orientation; + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); @@ -55,7 +61,10 @@ public class NumPadButton extends AlphaOptimizedImageButton { // Set width/height to the same value to ensure a smooth circle for the bg, but shrink // the height to match the old pin bouncer int width = getMeasuredWidth(); - int height = mAnimator == null ? (int) (width * .75f) : width; + + boolean shortenHeight = mAnimator == null + || mOrientation == Configuration.ORIENTATION_LANDSCAPE; + int height = shortenHeight ? (int) (width * .66f) : width; setMeasuredDimension(getMeasuredWidth(), height); } diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadKey.java b/packages/SystemUI/src/com/android/keyguard/NumPadKey.java index cffa630c6ec80..232c6fc990681 100644 --- a/packages/SystemUI/src/com/android/keyguard/NumPadKey.java +++ b/packages/SystemUI/src/com/android/keyguard/NumPadKey.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.android.keyguard; import android.content.Context; +import android.content.res.Configuration; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.graphics.drawable.RippleDrawable; @@ -52,6 +52,7 @@ public class NumPadKey extends ViewGroup { @Nullable private NumPadAnimator mAnimator; + private int mOrientation; private View.OnClickListener mListener = new View.OnClickListener() { @Override @@ -139,6 +140,11 @@ public class NumPadKey extends ViewGroup { } } + @Override + protected void onConfigurationChanged(Configuration newConfig) { + mOrientation = newConfig.orientation; + } + /** * Reload colors from resources. **/ @@ -171,7 +177,10 @@ public class NumPadKey extends ViewGroup { // Set width/height to the same value to ensure a smooth circle for the bg, but shrink // the height to match the old pin bouncer int width = getMeasuredWidth(); - int height = mAnimator == null ? (int) (width * .75f) : width; + + boolean shortenHeight = mAnimator == null + || mOrientation == Configuration.ORIENTATION_LANDSCAPE; + int height = shortenHeight ? (int) (width * .66f) : width; setMeasuredDimension(getMeasuredWidth(), height); }