From 742402a93f0f2a917e46e4570f66fe2128402f76 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Tue, 6 Jun 2023 13:12:59 -0700 Subject: [PATCH] Set gravity to end if we begin clipping subviews. In the pin view, after a certain number of pin inputs, the pin dots begin to get cut off. This is because the gravity is centered. During the layout pass, we calculate what to set the gravity to. We use the local visible rect to determine if the first child (the leftmost dot) is clipped or not visible. This will help us indicate whether we are overflowing. In this case we want to justify all of the dots to the end. Otherwise, we want to remain centered. Fixes: 285576678 Test: Tested non hinting pin view with overflow. Tested deletion and full deletion as well. Change-Id: I037f265ec80b1a105f0658217adc4383a3181987 --- .../keyguard/PinShapeNonHintingView.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/SystemUI/src/com/android/keyguard/PinShapeNonHintingView.java b/packages/SystemUI/src/com/android/keyguard/PinShapeNonHintingView.java index 4557b3418e19f..500910c910c39 100644 --- a/packages/SystemUI/src/com/android/keyguard/PinShapeNonHintingView.java +++ b/packages/SystemUI/src/com/android/keyguard/PinShapeNonHintingView.java @@ -30,6 +30,7 @@ import android.transition.TransitionManager; import android.transition.TransitionValues; import android.util.AttributeSet; import android.util.Log; +import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -51,11 +52,29 @@ public class PinShapeNonHintingView extends LinearLayout implements PinShapeInpu private int mPosition = 0; private final PinShapeAdapter mPinShapeAdapter; private ValueAnimator mValueAnimator = ValueAnimator.ofFloat(1f, 0f); + private Rect mFirstChildVisibleRect = new Rect(); public PinShapeNonHintingView(Context context, AttributeSet attrs) { super(context, attrs); mPinShapeAdapter = new PinShapeAdapter(context); } + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + super.onLayout(changed, l, t, r, b); + if (getChildCount() > 0) { + View firstChild = getChildAt(0); + boolean isVisible = firstChild.getLocalVisibleRect(mFirstChildVisibleRect); + boolean clipped = mFirstChildVisibleRect.left > 0 + || mFirstChildVisibleRect.right < firstChild.getWidth(); + if (!isVisible || clipped) { + setGravity(Gravity.END | Gravity.CENTER_VERTICAL); + return; + } + } + + setGravity(Gravity.CENTER); + } + @Override public void append() { int size = getResources().getDimensionPixelSize(R.dimen.password_shape_size);