OSDN Git Service

Separate skip and clear button in pattern screen
authorMaurice Lam <yukl@google.com>
Wed, 21 Mar 2018 21:06:07 +0000 (14:06 -0700)
committerMaurice Lam <yukl@google.com>
Wed, 21 Mar 2018 21:06:07 +0000 (14:06 -0700)
So that the action performed is always the same as what the button
label says.

Test: m -j RunSettingsRoboTests
Bug: 72197171
Change-Id: Ia2a02b630a86874d002e462e41fdf676c2d27203

res/layout/choose_lock_pattern_common_footer.xml
src/com/android/settings/password/SetupChooseLockPattern.java
tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java

index d80702e..fc36624 100644 (file)
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
 
-    <!-- left : cancel, or re-try -->
+    <!-- left : skip -->
+    <Button android:id="@+id/skip_button"
+        style="@style/SuwGlifButton.Secondary"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/skip_label"
+        android:visibility="gone" />
+
+    <!-- left : retry -->
     <Button android:id="@+id/footerLeftButton"
         style="@style/SuwGlifButton.Secondary"
         android:layout_width="wrap_content"
index 8853950..c9858b8 100644 (file)
@@ -25,7 +25,6 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
-import android.widget.TextView;
 
 import com.android.settings.R;
 import com.android.settings.SetupRedactionInterstitial;
@@ -70,6 +69,17 @@ public class SetupChooseLockPattern extends ChooseLockPattern {
                         ChooseLockTypeDialogFragment.newInstance(mUserId)
                                 .show(getChildFragmentManager(), null));
             }
+            // enable skip button only during setup wizard and not with fingerprint flow.
+            if (!mForFingerprint) {
+                Button skipButton = view.findViewById(R.id.skip_button);
+                skipButton.setVisibility(View.VISIBLE);
+                skipButton.setOnClickListener(v -> {
+                    SetupSkipDialog dialog = SetupSkipDialog.newInstance(
+                            getActivity().getIntent()
+                                    .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
+                    dialog.show(getFragmentManager());
+                });
+            }
             return view;
         }
 
@@ -82,16 +92,6 @@ public class SetupChooseLockPattern extends ChooseLockPattern {
         }
 
         @Override
-        protected void updateFooterLeftButton(Stage stage, TextView footerLeftButton) {
-            super.updateFooterLeftButton(stage, footerLeftButton);
-            // enable skip button only during setupwizard and not with fingerprint flow.
-            if (!mForFingerprint) {
-                footerLeftButton.setVisibility(View.VISIBLE);
-                footerLeftButton.setText(R.string.skip_label);
-            }
-        }
-
-        @Override
         protected void updateStage(Stage stage) {
             super.updateStage(stage);
             if (!getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui)
@@ -102,14 +102,6 @@ public class SetupChooseLockPattern extends ChooseLockPattern {
         }
 
         @Override
-        public void handleLeftButton() {
-            SetupSkipDialog dialog = SetupSkipDialog.newInstance(
-                    getActivity().getIntent()
-                            .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
-            dialog.show(getFragmentManager());
-        }
-
-        @Override
         protected Intent getRedactionInterstitialIntent(Context context) {
             // Setup wizard's redaction interstitial is deferred to optional step. Enable that
             // optional step if the lock screen was set up.
index a98db11..63bf711 100644 (file)
@@ -29,6 +29,8 @@ import android.view.View;
 import android.widget.Button;
 
 import com.android.internal.widget.LockPatternView;
+import com.android.internal.widget.LockPatternView.Cell;
+import com.android.internal.widget.LockPatternView.DisplayMode;
 import com.android.settings.R;
 import com.android.settings.SetupRedactionInterstitial;
 import com.android.settings.password.ChooseLockPattern.ChooseLockPatternFragment;
@@ -47,6 +49,9 @@ import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowAlertDialog;
 import org.robolectric.shadows.ShadowPackageManager;
 import org.robolectric.util.ReflectionHelpers;
+import org.robolectric.util.ReflectionHelpers.ClassParameter;
+
+import java.util.Arrays;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(shadows = {
@@ -120,16 +125,28 @@ public class SetupChooseLockPatternTest {
 
     @Test
     public void skipButton_shouldBeVisible_duringNonFingerprintFlow() {
-        Button button = mActivity.findViewById(R.id.footerLeftButton);
-        assertThat(button).isNotNull();
-        assertThat(button.getVisibility()).isEqualTo(View.VISIBLE);
+        Button skipButton = mActivity.findViewById(R.id.skip_button);
+        assertThat(skipButton).isNotNull();
+        assertThat(skipButton.getVisibility()).isEqualTo(View.VISIBLE);
 
-        button.performClick();
+        skipButton.performClick();
         AlertDialog chooserDialog = ShadowAlertDialog.getLatestAlertDialog();
         assertThat(chooserDialog).isNotNull();
     }
 
     @Test
+    public void clearButton_shouldBeVisible_duringRetryStage() {
+        enterPattern();
+
+        Button clearButton = mActivity.findViewById(R.id.footerLeftButton);
+        assertThat(clearButton.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(clearButton.isEnabled()).isTrue();
+
+        clearButton.performClick();
+        assertThat(findFragment(mActivity).mChosenPattern).isNull();
+    }
+
+    @Test
     public void skipButton_shouldNotBeVisible_duringFingerprintFlow() {
         mActivity = Robolectric.buildActivity(
                 SetupChooseLockPattern.class,
@@ -140,13 +157,32 @@ public class SetupChooseLockPatternTest {
                                 .setForFingerprint(true)
                                 .build()))
                 .setup().get();
-        Button button = mActivity.findViewById(R.id.footerLeftButton);
-        assertThat(button).isNotNull();
-        assertThat(button.getVisibility()).isEqualTo(View.GONE);
+        Button skipButton = mActivity.findViewById(R.id.skip_button);
+        assertThat(skipButton).isNotNull();
+        assertThat(skipButton.getVisibility()).isEqualTo(View.GONE);
     }
 
     private ChooseLockPatternFragment findFragment(Activity activity) {
         return (ChooseLockPatternFragment)
                 activity.getFragmentManager().findFragmentById(R.id.main_content);
     }
+
+    private void enterPattern() {
+        LockPatternView lockPatternView = mActivity.findViewById(R.id.lockPattern);
+        lockPatternView.setPattern(
+                DisplayMode.Animate,
+                Arrays.asList(
+                        createCell(0, 0),
+                        createCell(0, 1),
+                        createCell(1, 1),
+                        createCell(1, 0)));
+        ReflectionHelpers.callInstanceMethod(lockPatternView, "notifyPatternDetected");
+    }
+
+    private Cell createCell(int row, int column) {
+        return ReflectionHelpers.callConstructor(
+                Cell.class,
+                ClassParameter.from(int.class, row),
+                ClassParameter.from(int.class, column));
+    }
 }