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

Commit 767b1b45 authored by lbill's avatar lbill
Browse files

(2/2)Refine the requireScrollMixin usage for footer buttons

- Use the 2 buttons APIs by SUW design lib suggestion
- Do not handle the FooterButton visibility when
  isExpressiveStyle is true
- Do not handle the FooterButton visibility when
  isExpressiveStyle is true
- Deprecate static BiometricUtils.isExpressiveStyle(context, false)
  original logic always assume the UI will be used in SUW
- Deprecate static BiometricUtils.useExpressiveStyle(context, intent)
  Always rely on ThemeHelper.shouldApplyGlifExpressiveStyle(context)

Flag: N/A EXEMPT for the bug fixing
Bug: 412572626
Bug: 418694831
Bug: 418679772
Bug: 418643097
Bug: 418637456
Bug: 419178138

Test: atest FaceEnrollIntroductionTest
Test: manual check both SUW & Settings UI visual meet expressive
Test: manual tap "More" and show "I agree"
      Swipe back from Edu page and make sure the buttons
      showing correctly
Test: Folded & Unfolded, orientation changed and the buttons
      works as expected
Change-Id: Ia17da47461363c54f61c29a77589288f880100a6
parent 948cfe03
Loading
Loading
Loading
Loading
+17 −16
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import com.google.android.setupdesign.GlifLayout;
import com.google.android.setupdesign.span.LinkSpan;
import com.google.android.setupdesign.template.RequireScrollMixin;
import com.google.android.setupdesign.util.DynamicColorPalette;
import com.google.android.setupdesign.util.ThemeHelper;

import java.util.List;

@@ -159,15 +160,14 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final boolean isExpressiveStyle = BiometricUtils.isExpressiveStyle(
                getBaseContext(), false);
        final boolean isSuw = WizardManagerHelper.isAnySetupWizard(getIntent());

        if (shouldShowSplitScreenDialog()) {
            final BiometricsSplitScreenDialog splitDialog = BiometricsSplitScreenDialog
                    .newInstance(getModality(), !WizardManagerHelper.isAnySetupWizard(getIntent()));
                    .newInstance(getModality(), !isSuw);
            splitDialog.setPositiveButtonListener((dialog, which) -> {
                dialog.dismiss();
                if (!WizardManagerHelper.isAnySetupWizard(getIntent())) {
                if (!isSuw) {
                    updateOnboardingScreenInfoActions(
                            BiometricsOnboardingProto.OnboardingAction.ACTION_SKIP_VALUE);
                    Intent resultData = newResultIntent();
@@ -230,15 +230,16 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
        mFooterBarMixin = layout.getMixin(FooterBarMixin.class);
        mFooterBarMixin.setPrimaryButton(getPrimaryFooterButton());
        mFooterBarMixin.setSecondaryButton(getSecondaryFooterButton(), true /* usePrimaryStyle */);
        if (!isExpressiveStyle) {
            mFooterBarMixin.getSecondaryButton().setVisibility(
                    mHasScrolledToBottom ? View.VISIBLE : View.INVISIBLE);
        }

        final RequireScrollMixin requireScrollMixin = layout.getMixin(RequireScrollMixin.class);
        requireScrollMixin.requireScrollWithButton(this, getPrimaryFooterButton(),
                getMoreButtonTextRes(), this::onNextButtonClick);
        if (!isExpressiveStyle) {
        requireScrollMixin.requireScrollWithButton(this,
                getPrimaryFooterButton(),
                getSecondaryFooterButton(),
                getMoreButtonTextRes(),
                this::onNextButtonClick);
        if (!ThemeHelper.shouldApplyGlifExpressiveStyle(layout.getContext())) {
            mFooterBarMixin.getSecondaryButton().setVisibility(
                    mHasScrolledToBottom ? View.VISIBLE : View.INVISIBLE);
            requireScrollMixin.setOnRequireScrollStateChangedListener(
                    scrollNeeded -> {
                        boolean enrollmentCompleted = checkMaxEnrolled() != 0;
@@ -256,13 +257,13 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
                                        : View.INVISIBLE);
                        mHasScrolledToBottom = !scrollNeeded;
                    });
        }

            final boolean isScrollNeeded = requireScrollMixin.isScrollingRequired();
            final boolean enrollmentCompleted = checkMaxEnrolled() != 0;
            getSecondaryFooterButton().setVisibility(
                    !isScrollNeeded && !enrollmentCompleted ? View.VISIBLE : View.INVISIBLE);
        }
    }

    @Override
    protected void onStart() {
+7 −0
Original line number Diff line number Diff line
@@ -541,7 +541,10 @@ public class BiometricUtils {
     * @param context that for applying Expressive Style
     * @param isSettingsPreference Apply Expressive style on Settings Preference or not.
     * @return true if device using Expressive Style theme, otherwise false.
     *
     * @deprecated Use useExpressiveStyle(context, intent) instead
     */
    @Deprecated
    public static boolean isExpressiveStyle(@NonNull Context context,
            boolean isSettingsPreference) {
        return isSettingsPreference ? SettingsThemeHelper.isExpressiveTheme(context) :
@@ -554,7 +557,11 @@ public class BiometricUtils {
     * @param intent intent The original intent that was used to start the step, usually
     *               via {@link Activity#getIntent()}, Null will assume calling from Settings Flow.
     * @return true if device using Expressive Style theme, otherwise false.
     *
     * @deprecated Using either ThemeHelper.shouldApplyGlifExpressiveStyle()
     *             or SettingsThemeHelper.isExpressiveTheme() is more practical.
     */
    @Deprecated
    public static boolean useExpressiveStyle(@NonNull Context context, @Nullable Intent intent) {
        if (WizardManagerHelper.isAnySetupWizard(intent)) {
            return ThemeHelper.shouldApplyGlifExpressiveStyle(context);
+3 −2
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.template.FooterButton;
import com.google.android.setupcompat.util.WizardManagerHelper;
import com.google.android.setupdesign.util.LottieAnimationHelper;
import com.google.android.setupdesign.util.ThemeHelper;
import com.google.android.setupdesign.view.IllustrationVideoView;

import java.util.Arrays;
@@ -120,8 +121,6 @@ public class FaceEnrollEducation extends BiometricEnrollBase {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mIsUsingExpressiveStyle = BiometricUtils.useExpressiveStyle(getApplicationContext(),
                getIntent());

        setContentView(R.layout.face_enroll_education);

@@ -133,6 +132,8 @@ public class FaceEnrollEducation extends BiometricEnrollBase {
        mIllustrationDefault = findViewById(R.id.illustration_default);
        mIllustrationLottie = findViewById(R.id.illustration_lottie);
        mIllustrationAccessibility = findViewById(R.id.illustration_accessibility);
        mIsUsingExpressiveStyle = ThemeHelper.shouldApplyGlifExpressiveStyle(
                getApplicationContext());
        if (mIsUsingExpressiveStyle && mIllustrationAccessibility instanceof ImageView) {
            ((ImageView) mIllustrationAccessibility).setImageResource(
                    R.drawable.face_enroll_icon_large_expressive);
+2 −1
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.widget.FooterPreference;

import com.google.android.setupcompat.util.WizardManagerHelper;
import com.google.android.setupdesign.util.ThemeHelper;

import java.util.ArrayList;

@@ -457,7 +458,7 @@ public class ChooseLockGeneric extends SettingsActivity {
                }
            } else {
                textView.setText("");
                if (BiometricUtils.useExpressiveStyle(getContext(), getIntent())) {
                if (ThemeHelper.shouldApplyGlifExpressiveStyle(getContext())) {
                    textView.setVisibility(View.GONE);
                }
            }
+64 −11
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settingslib.widget.SettingsThemeHelper;

import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.template.FooterButton;
@@ -99,6 +100,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.Shadows;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowActivity;

import java.util.ArrayList;
@@ -112,7 +115,8 @@ import java.util.List;
        ShadowDevicePolicyManager.class,
        ShadowSensorPrivacyManager.class,
        SettingsShadowResources.class,
        ShadowAlertDialogCompat.class
        ShadowAlertDialogCompat.class,
        FaceEnrollIntroductionTest.ShadowSettingsThemeHelper.class,
})
public class FaceEnrollIntroductionTest {

@@ -202,6 +206,15 @@ public class FaceEnrollIntroductionTest {
        ShadowAlertDialogCompat.reset();
    }

    private void setupNonExpressiveActivity() {
        ShadowSettingsThemeHelper.setExpressiveTheme(false);
        setupActivity();
    }

    private void setupExpressiveActivity() {
        ShadowSettingsThemeHelper.setExpressiveTheme(true);
        setupActivity();
    }
    private void setupActivity() {
        final Intent testIntent = new Intent();
        // Set the challenge token so the confirm screen will not be shown
@@ -233,6 +246,7 @@ public class FaceEnrollIntroductionTest {
    }

    private void setupActivityForPosture() {
        ShadowSettingsThemeHelper.setExpressiveTheme(false);
        final Intent testIntent = new Intent();
        // Set the challenge token so the confirm screen will not be shown
        testIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
@@ -288,6 +302,21 @@ public class FaceEnrollIntroductionTest {
        when(mFaceManager.getEnrolledFaces(userId)).thenReturn(faces);
    }

    @Implements(SettingsThemeHelper.class)
    public static class ShadowSettingsThemeHelper {
        private static boolean sIsExpressiveTheme;

        /** Shadow implementation of isExpressiveTheme */
        @Implementation
        public static boolean isExpressiveTheme(@NonNull Context context) {
            return sIsExpressiveTheme;
        }

        static void setExpressiveTheme(boolean isExpressiveTheme) {
            sIsExpressiveTheme = isExpressiveTheme;
        }
    }

    @Test
    public void intro_CheckCanEnroll() {
        setFaceManagerToHave(0 /* numEnrollments */);
@@ -347,16 +376,40 @@ public class FaceEnrollIntroductionTest {

    @Test
    public void testFaceEnrollIntroduction_hasHeader() {
        setupActivity();
        setupNonExpressiveActivity();
        TextView headerTextView = getGlifLayout(mActivity).findViewById(R.id.suc_layout_title);

        assertThat(headerTextView).isNotNull();
        assertThat(headerTextView.getText().toString()).isNotEmpty();
    }

    @Test
    public void testFaceEnrollIntroduction_hasFooterBar_hasFooterButtons() {
        setupNonExpressiveActivity();
        FooterBarMixin footer = getGlifLayout(mActivity).getMixin(FooterBarMixin.class);

        assertThat(footer).isNotNull();
        assertThat(footer.getPrimaryButton()).isNotNull();
        assertThat(footer.getPrimaryButton().getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(footer.getSecondaryButton()).isNotNull();
        assertThat(footer.getSecondaryButton().getVisibility()).isEqualTo(View.VISIBLE);
    }

    @Test
    public void testFaceEnrollIntroduction_isExpressiveStyle_hasFooterBar_hasFooterButtons() {
        setupExpressiveActivity();
        FooterBarMixin footer = getGlifLayout(mActivity).getMixin(FooterBarMixin.class);

        assertThat(footer).isNotNull();
        assertThat(footer.getPrimaryButton()).isNotNull();
        assertThat(footer.getPrimaryButton().getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(footer.getSecondaryButton()).isNotNull();
        assertThat(footer.getSecondaryButton().getVisibility()).isEqualTo(View.VISIBLE);
    }

    @Test
    public void testFaceEnrollIntroduction_hasDescription_weakFace() throws Exception {
        setupActivity();
        setupNonExpressiveActivity();
        SettingsShadowResources.overrideResource(
                R.bool.config_face_intro_show_less_secure,
                true);
@@ -387,7 +440,7 @@ public class FaceEnrollIntroductionTest {
    @Test
    public void testFaceEnrollIntroduction_hasDescriptionNoLessSecure_strongFace()
            throws Exception {
        setupActivity();
        setupNonExpressiveActivity();
        SettingsShadowResources.overrideResource(
                R.bool.config_face_intro_show_less_secure,
                true);
@@ -418,7 +471,7 @@ public class FaceEnrollIntroductionTest {

    @Test
    public void testFaceEnrollIntroduction_hasBottomScrollView() {
        setupActivity();
        setupNonExpressiveActivity();
        BottomScrollView scrollView = getGlifLayout(mActivity)
                .findViewById(com.google.android.setupdesign.R.id.sud_scroll_view);

@@ -428,7 +481,7 @@ public class FaceEnrollIntroductionTest {

    @Test
    public void testFaceEnrollIntroduction_showFooterPrimaryButton() {
        setupActivity();
        setupNonExpressiveActivity();
        FooterBarMixin footer = getGlifLayout(mActivity).getMixin(FooterBarMixin.class);
        FooterButton footerButton = footer.getPrimaryButton();

@@ -440,7 +493,7 @@ public class FaceEnrollIntroductionTest {

    @Test
    public void testFaceEnrollIntroduction_footerSecondaryButtonWhenCanEnroll() {
        setupActivity();
        setupNonExpressiveActivity();
        FooterBarMixin footer = getGlifLayout(mActivity).getMixin(FooterBarMixin.class);
        FooterButton footerButton = footer.getSecondaryButton();

@@ -477,7 +530,7 @@ public class FaceEnrollIntroductionTest {

    @Test
    public void testFaceEnrollIntroduction_defaultNeverLaunchPostureGuidance() {
        setupActivity();
        setupNonExpressiveActivity();

        assertThat(mActivity.launchPostureGuidance()).isFalse();
        assertThat(mActivity.getDevicePostureState()).isEqualTo(DEVICE_POSTURE_UNKNOWN);
@@ -485,7 +538,7 @@ public class FaceEnrollIntroductionTest {

    @Test
    public void testFaceEnrollIntroduction_onStartNeverRegisterPostureChangeCallback() {
        setupActivity();
        setupNonExpressiveActivity();
        mActivity.onStart();

        assertThat(mActivity.getPostureGuidanceIntent()).isNull();
@@ -692,7 +745,7 @@ public class FaceEnrollIntroductionTest {

    @Test
    public void testFaceEnrollIntroduction_forwardsEnrollOptions() {
        setupActivity();
        setupNonExpressiveActivity();
        final Intent intent = mActivity.getEnrollingIntent();

        assertThat(intent.getIntExtra(BiometricUtils.EXTRA_ENROLL_REASON, -1))
@@ -701,7 +754,7 @@ public class FaceEnrollIntroductionTest {

    @Test
    public void drops_pendingIntents() {
        setupActivity();
        setupNonExpressiveActivity();

        mController.start();
        Shadows.shadowOf(Looper.getMainLooper()).idle();