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

Commit 1eb3724e authored by Hao Dong's avatar Hao Dong Committed by Android (Google) Code Review
Browse files

Merge "Hide description text view if there is overlap." into udc-dev

parents 6e3aba53 cddf296c
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -96,4 +96,6 @@
        </LinearLayout>
        </LinearLayout>


    </LinearLayout>
    </LinearLayout>

    <include layout="@layout/udfps_enroll_view" />
</com.google.android.setupdesign.GlifLayout>
</com.google.android.setupdesign.GlifLayout>
 No newline at end of file
+7 −2
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@
<com.google.android.setupdesign.GlifLayout
<com.google.android.setupdesign.GlifLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/setup_wizard_layout"
    android:id="@+id/setup_wizard_layout"
    android:layout_width="match_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_height="match_parent"
@@ -41,10 +42,11 @@
          <FrameLayout
          <FrameLayout
              android:id="@+id/layout_container"
              android:id="@+id/layout_container"
              android:layout_width="match_parent"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_height="0dp"
              android:clipChildren="false"
              android:clipChildren="false"
              android:clipToPadding="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 -->
              <!-- Animation res MUST be set in code -->
              <com.airbnb.lottie.LottieAnimationView
              <com.airbnb.lottie.LottieAnimationView
@@ -59,6 +61,9 @@
                  android:clipChildren="false"
                  android:clipChildren="false"
                  android:clipToPadding="false"
                  android:clipToPadding="false"
                  app:lottie_speed=".85" />
                  app:lottie_speed=".85" />

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

          </FrameLayout>
          </FrameLayout>


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


                case Surface.ROTATION_0:
                case Surface.ROTATION_0:
                case Surface.ROTATION_180:
                case Surface.ROTATION_180:
                    if (FeatureFlagUtils.isEnabled(getApplicationContext(),
                    // In the portrait mode, layout_container's height is 0, so it's
                            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
                    // always shown at the bottom of the screen.
                    // 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(
                    final FrameLayout portraitLayoutContainer = layout.findViewById(
                            R.id.layout_container);
                            R.id.layout_container);
                        final ViewGroup.LayoutParams containerLp =
                                portraitLayoutContainer.getLayoutParams();
                        containerLp.height = 0;


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


                        portraitLayoutContainer.addView(udfpsEnrollView);
                    // TODO(b/260970216) Instead of hiding the description text view, we should
                        setOnHoverListener(false, layout, udfpsEnrollView);
                    //  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);
                    setContentView(layout);
                    break;
                    break;


                case Surface.ROTATION_270:
                case Surface.ROTATION_270:
                default:
                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);
                    setOnHoverListener(true, layout, udfpsEnrollView);
                    }

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


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

        DisplayInfo displayInfo = new DisplayInfo();
        DisplayInfo displayInfo = new DisplayInfo();
        getDisplay().getDisplayInfo(displayInfo);
        getDisplay().getDisplayInfo(displayInfo);
        mScaleFactor = mUdfpsUtils.getScaleFactor(displayInfo);
        mScaleFactor = mUdfpsUtils.getScaleFactor(displayInfo);
@@ -1305,6 +1291,24 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
                : R.id.sud_layout_content).setOnHoverListener(onHoverListener);
                : 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 {
    public static class IconTouchDialog extends InstrumentedDialogFragment {


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


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


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


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


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


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


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


        final GlifLayout defaultLayout = mActivity.findViewById(R.id.setup_wizard_layout);
        final GlifLayout defaultLayout = mActivity.findViewById(R.id.setup_wizard_layout);
@@ -320,10 +311,36 @@ public class FingerprintEnrollEnrollingTest {
                .intersect(rectUdfpsEnrollView.get())).isFalse();
                .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
    @Test
    public void forwardEnrollProgressEvents() {
    public void forwardEnrollProgressEvents() {
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);
        initializeActivityFor(TYPE_UDFPS_OPTICAL);
        initializeActivityFor(TYPE_UDFPS_OPTICAL);


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


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


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


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


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


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


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


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


        EnrollListener listener = new EnrollListener(mActivity);
        EnrollListener listener = new EnrollListener(mActivity);