Fix UI bugs for udfps enroll in settings.

This CL fixes four bugs for SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS feature:
1. When the udfps view is big enough (i.e. landscape mode on panther), the progress bar's bottom is clipped by the footer button.
- Sets the footer button width WRAP_CONTENT and removes the space view to make the footer button short enough, not hiding the udfps view progress bar.

2. When both text size and display icon size are big enough on the portrait mode, the udfps view's position is wrong because its parent views are longer than the screen and scrollable.
- Add addOnDrawListener() on udfps view's parent view, whenever it's changed, recalculate the margins of udfps view to make sure it's aligned  with the sensor's position.

3. When the finger is down on the screen and the lighting circle on the sensor is shown, the fingerprint icon is not hidden.
- Propagates FingerprintManager#onPointerDown and #onPointerUp to UdfpsEnrollView and hide/show fingerprint drawable accordingly.

4. When rotating the screen, fingerprint location is not right because UdfpsEnrollHelper is recreated.
- Makes UdfpsEnrollHelper a fragment and call setRetainInstance(true) to keep it even though the configuration is changed.

Test: manually tested on device:
      Turn this flag on via adb command
      adb shell setprop
        sys.fflag.override.settings_show_udfps_enroll_in_settings true
Bug: 260617060
Change-Id: I15ffde6455cab7e9d4a394349ec39e72df5b2911
This commit is contained in:
Hao Dong
2022-12-15 16:04:43 +00:00
parent 599ffd0f3f
commit 967203de77
6 changed files with 185 additions and 21 deletions

View File

@@ -88,10 +88,22 @@ public class UdfpsEnrollView extends FrameLayout implements UdfpsEnrollHelper.Li
@Override
public void onAcquired(boolean animateIfLastStepGood) {
mHandler.post(() -> {
onFingerUp();
if (animateIfLastStepGood) mFingerprintProgressDrawable.onLastStepAcquired();
});
}
@Override
public void onPointerDown(int sensorId) {
onFingerDown();
}
@Override
public void onPointerUp(int sensorId) {
onFingerUp();
}
void setOverlayParams(UdfpsOverlayParams params) {
mOverlayParams = params;
@@ -99,7 +111,7 @@ public class UdfpsEnrollView extends FrameLayout implements UdfpsEnrollHelper.Li
mProgressBarRadius =
(int) (mOverlayParams.getScaleFactor() * getContext().getResources().getInteger(
R.integer.config_udfpsEnrollProgressBar));
mSensorRect = mOverlayParams.getSensorBounds();
mSensorRect = new Rect(mOverlayParams.getSensorBounds());
onSensorRectUpdated();
});
@@ -123,7 +135,7 @@ public class UdfpsEnrollView extends FrameLayout implements UdfpsEnrollHelper.Li
private void updateDimensions() {
// Original sensorBounds assume portrait mode.
Rect rotatedBounds = mOverlayParams.getSensorBounds();
final Rect rotatedBounds = mOverlayParams.getSensorBounds();
int rotation = mOverlayParams.getRotation();
if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
RotationUtils.rotateBounds(
@@ -137,33 +149,42 @@ public class UdfpsEnrollView extends FrameLayout implements UdfpsEnrollHelper.Li
// Use parent view's and rotatedBound's absolute coordinates to decide the margins of
// UdfpsEnrollView, so that its center keeps consistent with sensor rect's.
ViewGroup parentView = (ViewGroup) getParent();
int[] coords = parentView.getLocationOnScreen();
int parentLeft = coords[0];
int parentTop = coords[1];
int parentRight = parentLeft + parentView.getWidth();
int parentBottom = parentTop + parentView.getHeight();
MarginLayoutParams marginLayoutParams = (MarginLayoutParams) getLayoutParams();
FrameLayout.LayoutParams params = (LayoutParams) getLayoutParams();
switch (rotation) {
case Surface.ROTATION_0:
case Surface.ROTATION_180:
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
parentView.getViewTreeObserver().addOnDrawListener(() -> {
final int[] coords = parentView.getLocationOnScreen();
final int parentLeft = coords[0];
final int parentTop = coords[1];
final int parentRight = parentLeft + parentView.getWidth();
params.gravity = Gravity.RIGHT | Gravity.TOP;
marginLayoutParams.rightMargin = parentRight - rotatedBounds.right - getPaddingX();
marginLayoutParams.topMargin = rotatedBounds.top - parentTop - getPaddingY();
break;
case Surface.ROTATION_90:
final int rightMargin = parentRight - rotatedBounds.right - getPaddingX();
final int topMargin = rotatedBounds.top - parentTop - getPaddingY();
if (marginLayoutParams.rightMargin == rightMargin
&& marginLayoutParams.topMargin == topMargin) {
return;
}
marginLayoutParams.rightMargin = rightMargin;
marginLayoutParams.topMargin = topMargin;
setLayoutParams(params);
});
} else {
final int[] coords = parentView.getLocationOnScreen();
final int parentLeft = coords[0];
final int parentTop = coords[1];
final int parentRight = parentLeft + parentView.getWidth();
final int parentBottom = parentTop + parentView.getHeight();
if (rotation == Surface.ROTATION_90) {
params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
marginLayoutParams.rightMargin = parentRight - rotatedBounds.right - getPaddingX();
marginLayoutParams.bottomMargin =
parentBottom - rotatedBounds.bottom - getPaddingY();
break;
case Surface.ROTATION_270:
} else if (rotation == Surface.ROTATION_270) {
params.gravity = Gravity.LEFT | Gravity.BOTTOM;
marginLayoutParams.leftMargin = rotatedBounds.left - parentLeft - getPaddingX();
marginLayoutParams.bottomMargin =
parentBottom - rotatedBounds.bottom - getPaddingY();
break;
}
}
params.height = rotatedBounds.height() + 2 * getPaddingX();