Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cddf296c authored by Hao Dong's avatar Hao Dong
Browse files

Hide description text view if there is overlap.

1. Includes udfps enroll view in xml files and cleans up FingerprintEnrollEnrolling adding udfps enroll view code.
2. Clean up SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS flag.
3. If description text view has overlap with udfps progress view, hide the description text view.

Test: atest FingerprintEnrollEnrollingTest
Test: manually test by setting both display and text largest size and
start enrolling fingerprint; the description is hidden if it's too long.
Bug: 260970216
Change-Id: I085dc62993ffa22d018dd57517c96d69e9d9cbcb
parent 55769475
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -96,4 +96,6 @@
        </LinearLayout>

    </LinearLayout>

    <include layout="@layout/udfps_enroll_view" />
</com.google.android.setupdesign.GlifLayout>
 No newline at end of file
+7 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
<com.google.android.setupdesign.GlifLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/setup_wizard_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
@@ -41,10 +42,11 @@
          <FrameLayout
              android:id="@+id/layout_container"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_height="0dp"
              android:clipChildren="false"
              android:clipToPadding="false"
              android:layout_gravity="center_horizontal|bottom">
              android:layout_gravity="center_horizontal|bottom"
              tools:ignore="Suspicious0dp">

              <!-- Animation res MUST be set in code -->
              <com.airbnb.lottie.LottieAnimationView
@@ -59,6 +61,9 @@
                  android:clipChildren="false"
                  android:clipToPadding="false"
                  app:lottie_speed=".85" />

              <include layout="@layout/udfps_enroll_view" />

          </FrameLayout>

          <TextView
+57 −53
Original line number Diff line number Diff line
@@ -261,6 +261,8 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
            int rotation = getApplicationContext().getDisplay().getRotation();
            final GlifLayout layout = (GlifLayout) getLayoutInflater().inflate(
                    R.layout.udfps_enroll_enrolling, null, false);
            final UdfpsEnrollView udfpsEnrollView = layout.findViewById(R.id.udfps_animation_view);
            updateUdfpsEnrollView(udfpsEnrollView, props.get(0));
            switch (rotation) {
                case Surface.ROTATION_90:
                    final LinearLayout layoutContainer = layout.findViewById(
@@ -276,33 +278,17 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
                            ? 0 : (int) getResources().getDimension(
                            R.dimen.rotation_90_enroll_padding_end), 0);
                    layoutContainer.setLayoutParams(lp);
                    if (FeatureFlagUtils.isEnabled(getApplicationContext(),
                            FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS)) {
                        final UdfpsEnrollView udfpsEnrollView = addUdfpsEnrollView(props.get(0));
                        layout.addView(udfpsEnrollView);

                    setOnHoverListener(true, layout, udfpsEnrollView);
                    }
                    setContentView(layout, lp);
                    break;

                case Surface.ROTATION_0:
                case Surface.ROTATION_180:
                    if (FeatureFlagUtils.isEnabled(getApplicationContext(),
                            FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS)) {
                        final UdfpsEnrollView udfpsEnrollView = addUdfpsEnrollView(props.get(0));
                        // In the portrait mode, set layout_container's height 0, so it's
                    // In the portrait mode, layout_container's height is 0, so it's
                    // always shown at the bottom of the screen.
                        // Add udfps enroll view into layout_container instead of
                        // udfps_enroll_enrolling, so that when the content is too long to
                        // make udfps_enroll_enrolling larger than the screen, udfps enroll
                        // view could still be set to right position by setting bottom margin to
                        // its parent view (layout_container) because it's always at the
                        // bottom of the screen.
                    final FrameLayout portraitLayoutContainer = layout.findViewById(
                            R.id.layout_container);
                        final ViewGroup.LayoutParams containerLp =
                                portraitLayoutContainer.getLayoutParams();
                        containerLp.height = 0;

                    // In the portrait mode, the title and lottie animation view may
                    // overlap when title needs three lines, so adding some paddings
@@ -320,22 +306,24 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
                    fingerprintView.setPadding(0, -layoutLottieAnimationPadding,
                            0, layoutLottieAnimationPadding);

                        portraitLayoutContainer.addView(udfpsEnrollView);
                        setOnHoverListener(false, layout, udfpsEnrollView);
                    // TODO(b/260970216) Instead of hiding the description text view, we should
                    //  make the header view scrollable if the text is too long.
                    // If description text view has overlap with udfps progress view, hide it.
                    View view = layout.getDescriptionTextView();
                    layout.getViewTreeObserver().addOnDrawListener(() -> {
                        if (view.getVisibility() == View.VISIBLE
                                && hasOverlap(view, udfpsEnrollView)) {
                            view.setVisibility(View.GONE);
                        }
                    });

                    setOnHoverListener(false, layout, udfpsEnrollView);
                    setContentView(layout);
                    break;

                case Surface.ROTATION_270:
                default:
                    if (FeatureFlagUtils.isEnabled(getApplicationContext(),
                            FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS)) {
                        final UdfpsEnrollView udfpsEnrollView = addUdfpsEnrollView(props.get(0));
                        layout.addView(udfpsEnrollView);
                    setOnHoverListener(true, layout, udfpsEnrollView);
                    }

                    setContentView(layout);
                    break;
            }
@@ -1235,10 +1223,8 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
        }
    }

    private UdfpsEnrollView addUdfpsEnrollView(FingerprintSensorPropertiesInternal udfpsProps) {
        UdfpsEnrollView udfpsEnrollView = (UdfpsEnrollView) getLayoutInflater().inflate(
                R.layout.udfps_enroll_view, null, false);

    private UdfpsEnrollView updateUdfpsEnrollView(UdfpsEnrollView udfpsEnrollView,
                                                  FingerprintSensorPropertiesInternal udfpsProps) {
        DisplayInfo displayInfo = new DisplayInfo();
        getDisplay().getDisplayInfo(displayInfo);
        mScaleFactor = mUdfpsUtils.getScaleFactor(displayInfo);
@@ -1305,6 +1291,24 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
                : R.id.sud_layout_content).setOnHoverListener(onHoverListener);
    }


    @VisibleForTesting boolean hasOverlap(View view1, View view2) {
        int[] firstPosition = new int[2];
        int[] secondPosition = new int[2];

        view1.getLocationOnScreen(firstPosition);
        view2.getLocationOnScreen(secondPosition);

        // Rect constructor parameters: left, top, right, bottom
        Rect rectView1 = new Rect(firstPosition[0], firstPosition[1],
                firstPosition[0] + view1.getMeasuredWidth(),
                firstPosition[1] + view1.getMeasuredHeight());
        Rect rectView2 = new Rect(secondPosition[0], secondPosition[1],
                secondPosition[0] + view2.getMeasuredWidth(),
                secondPosition[1] + view2.getMeasuredHeight());
        return rectView1.intersect(rectView2);
    }

    public static class IconTouchDialog extends InstrumentedDialogFragment {

        @Override
+14 −16
Original line number Diff line number Diff line
@@ -161,7 +161,6 @@ public class UdfpsEnrollView extends FrameLayout implements UdfpsEnrollHelper.Li
        MarginLayoutParams marginLayoutParams = (MarginLayoutParams) getLayoutParams();
        FrameLayout.LayoutParams params = (LayoutParams) getLayoutParams();
        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];
@@ -176,7 +175,6 @@ public class UdfpsEnrollView extends FrameLayout implements UdfpsEnrollHelper.Li
            marginLayoutParams.rightMargin = rightMargin;
            marginLayoutParams.topMargin = topMargin;
            setLayoutParams(params);
            });
        } else {
            final int[] coords = parentView.getLocationOnScreen();
            final int parentLeft = coords[0];
+32 −23
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Vibrator;
import android.util.FeatureFlagUtils;
import android.view.Display;
import android.view.Surface;
import android.view.View;
@@ -203,8 +202,6 @@ public class FingerprintEnrollEnrollingTest {

    @Test
    public void fingerprintUdfpsOverlayEnrollment_showOverlayPortrait() {
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);
        initializeActivityFor(TYPE_UDFPS_OPTICAL);
        when(mMockDisplay.getRotation()).thenReturn(Surface.ROTATION_0);

@@ -216,8 +213,6 @@ public class FingerprintEnrollEnrollingTest {

    @Test
    public void fingerprintUdfpsOverlayEnrollment_showOverlayLandscape() {
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);
        initializeActivityFor(TYPE_UDFPS_OPTICAL);
        when(mMockDisplay.getRotation()).thenReturn(Surface.ROTATION_90);

@@ -229,8 +224,6 @@ public class FingerprintEnrollEnrollingTest {

    @Test
    public void fingerprintUdfpsOverlayEnrollment_usesCorrectProgressBarFillColor() {
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);
        initializeActivityFor(TYPE_UDFPS_OPTICAL);
        final TypedArray ta = mActivity.obtainStyledAttributes(null,
                R.styleable.BiometricsEnrollView, R.attr.biometricsEnrollStyle,
@@ -250,9 +243,7 @@ public class FingerprintEnrollEnrollingTest {

    @Test
    public void fingerprintUdfpsOverlayEnrollment_checkViewOverlapPortrait() {
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);
        when(mMockDisplay.getRotation()).thenReturn(Surface.ROTATION_90);
        when(mMockDisplay.getRotation()).thenReturn(Surface.ROTATION_0);
        initializeActivityFor(TYPE_UDFPS_OPTICAL);

        final GlifLayout defaultLayout = mActivity.findViewById(R.id.setup_wizard_layout);
@@ -320,10 +311,36 @@ public class FingerprintEnrollEnrollingTest {
                .intersect(rectUdfpsEnrollView.get())).isFalse();
    }

    @Test
    public void fingerprintUdfpsOverlayEnrollment_descriptionViewGoneWithOverlap() {
        initializeActivityWithoutCreate(TYPE_UDFPS_OPTICAL);
        doReturn(true).when(mActivity).hasOverlap(any(), any());
        when(mMockDisplay.getRotation()).thenReturn(Surface.ROTATION_0);
        createActivity();

        final GlifLayout defaultLayout = spy(mActivity.findViewById(R.id.setup_wizard_layout));
        final TextView descriptionTextView = defaultLayout.getDescriptionTextView();

        defaultLayout.getViewTreeObserver().dispatchOnDraw();
        assertThat(descriptionTextView.getVisibility()).isEqualTo(View.GONE);
    }

    @Test
    public void fingerprintUdfpsOverlayEnrollment_descriptionViewVisibleWithoutOverlap() {
        initializeActivityWithoutCreate(TYPE_UDFPS_OPTICAL);
        doReturn(false).when(mActivity).hasOverlap(any(), any());
        when(mMockDisplay.getRotation()).thenReturn(Surface.ROTATION_0);
        createActivity();

        final GlifLayout defaultLayout = spy(mActivity.findViewById(R.id.setup_wizard_layout));
        final TextView descriptionTextView = defaultLayout.getDescriptionTextView();

        defaultLayout.getViewTreeObserver().dispatchOnDraw();
        assertThat(descriptionTextView.getVisibility()).isEqualTo(View.VISIBLE);
    }

    @Test
    public void forwardEnrollProgressEvents() {
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);
        initializeActivityFor(TYPE_UDFPS_OPTICAL);

        EnrollListener listener = new EnrollListener(mActivity);
@@ -337,8 +354,6 @@ public class FingerprintEnrollEnrollingTest {

    @Test
    public void forwardEnrollHelpEvents() {
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);
        initializeActivityFor(TYPE_UDFPS_OPTICAL);

        EnrollListener listener = new EnrollListener(mActivity);
@@ -352,8 +367,6 @@ public class FingerprintEnrollEnrollingTest {

    @Test
    public void forwardEnrollAcquiredEvents() {
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);
        initializeActivityFor(TYPE_UDFPS_OPTICAL);

        EnrollListener listener = new EnrollListener(mActivity);
@@ -368,8 +381,6 @@ public class FingerprintEnrollEnrollingTest {

    @Test
    public void forwardEnrollPointerDownEvents() {
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);
        initializeActivityFor(TYPE_UDFPS_OPTICAL);

        EnrollListener listener = new EnrollListener(mActivity);
@@ -383,8 +394,6 @@ public class FingerprintEnrollEnrollingTest {

    @Test
    public void forwardEnrollPointerUpEvents() {
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);
        initializeActivityFor(TYPE_UDFPS_OPTICAL);

        EnrollListener listener = new EnrollListener(mActivity);