5/ Refine SetupChooseLockPattern layout by design

Since the SetupChooseLockPattern include header icon
header title, header sub-title, pattern state description,
LockPatternView and FooterBar, there was a limited room
for LockPatternView especially in the confirm steps which
both header title and pattern description occupy 2 lines space.
Hance the PatternView size used to inconsistence in-between
1st draw and 2nd confirm draw, besides it's visual looks
jumping and small on some device which have smaller display.

This solution includes 3 changes:
1. Organized the pattern view message to leverage
   header sub-title view, then we can resever more space.
   (Set minHeight=2 for sub-title)
2. Set screen_lock_options button visibilty to GONE when
   the stage in 2nd confirmation.(Previously it's INVISIBLE
   and reserve additional space)
3. Let LockPatternView align bottom of FrameLayout to prevent
   the view juming and flicker.
4. Clean up unused forAnyBiometric flag and code.
5. GlifLayout.getDescriptionTextView() == mHeaderView
   Need setDescriptionText() to make the view from GONE -> VISIBLE
6. Polish the stage flow and ensure IntroductionStage show
   correct message
7. Add ChooseLockPattern into embeded activity white list
   Force show ChooseLockPattern in fullscreen in case the Pattern
   view truncated in `NeedToConfirmStage` where the title showing
   2 lines and push pattern view down, and get bad UX in the
   device which integrate a shorter display.
8. Add test cases for all stage and polish legacy test code.

Test: make RunSettingsRoboTests ROBOTEST_FILTER= \
     "com.android.settings.password.SetupChooseLockPatternTest"
Test: make RunSettingsRoboTests ROBOTEST_FILTER= \
     "com.android.settings.password.ChooseLockPatternTest"
Bug: 249974175
Bug: 260027850
Change-Id: I868af9b14ba99af5d78a05f6c2a570ccc07aea15
This commit is contained in:
lbill
2023-01-05 05:24:57 +00:00
parent fbed9b87ce
commit bbca300b30
9 changed files with 230 additions and 87 deletions

View File

@@ -33,30 +33,29 @@
android:clipChildren="false" android:clipChildren="false"
android:clipToPadding="false" android:clipToPadding="false"
android:orientation="vertical" android:orientation="vertical"
android:paddingTop="0dp"
android:paddingLeft="0dp" android:paddingLeft="0dp"
android:paddingRight="0dp"> android:paddingRight="0dp"
android:paddingBottom="0dp">
<TextView <!-- TODO b/249974175 Move into Glif header mixin -->
android:id="@+id/headerText" <Button
style="@style/SudDescription.Glif" android:id="@+id/screen_lock_options"
android:layout_width="match_parent" style="@style/SudGlifButton.Tertiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minLines="2" android:text="@string/setup_lock_settings_options_button_label"
android:gravity="center" android:visibility="gone"/>
android:paddingStart="?attr/sudMarginStart"
android:paddingEnd="?attr/sudMarginEnd"
android:fontFamily="@*android:string/config_headlineFontFamily" />
<com.google.android.setupdesign.view.FillContentLayout <com.google.android.setupdesign.view.FillContentLayout
style="@style/LockPatternContainerStyle" style="@style/LockPatternContainerStyle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="0dp" android:layout_height="wrap_content">
android:layout_weight="1">
<com.android.internal.widget.LockPatternView <com.android.internal.widget.LockPatternView
android:id="@+id/lockPattern" android:id="@+id/lockPattern"
android:layout_width="match_parent" android:layout_width="@dimen/biometric_auth_pattern_view_size"
android:layout_height="match_parent" android:layout_height="@dimen/biometric_auth_pattern_view_size"
android:layout_gravity="center"/> android:layout_gravity="center"/>
</com.google.android.setupdesign.view.FillContentLayout> </com.google.android.setupdesign.view.FillContentLayout>
@@ -69,13 +68,6 @@
android:textSize="14sp" android:textSize="14sp"
android:visibility="gone"/> android:visibility="gone"/>
<Button
android:id="@+id/screen_lock_options"
style="@style/SudGlifButton.Tertiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setup_lock_settings_options_button_label"
android:visibility="gone"/>
</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient> </com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
</com.google.android.setupdesign.GlifLayout> </com.google.android.setupdesign.GlifLayout>

View File

@@ -36,16 +36,13 @@
android:paddingLeft="0dp" android:paddingLeft="0dp"
android:paddingRight="0dp"> android:paddingRight="0dp">
<TextView <Button
android:id="@+id/headerText" android:id="@+id/screen_lock_options"
style="@style/SudDescription.Glif" style="@style/LockPatternButtonStyle"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minLines="2" android:text="@string/setup_lock_settings_options_button_label"
android:gravity="center" android:visibility="gone"/>
android:paddingStart="?attr/sudMarginStart"
android:paddingEnd="?attr/sudMarginEnd"
android:fontFamily="@*android:string/config_headlineFontFamily" />
<com.google.android.setupdesign.view.FillContentLayout <com.google.android.setupdesign.view.FillContentLayout
style="@style/LockPatternContainerStyle" style="@style/LockPatternContainerStyle"
@@ -69,13 +66,6 @@
android:textSize="14sp" android:textSize="14sp"
android:visibility="gone"/> android:visibility="gone"/>
<Button
android:id="@+id/screen_lock_options"
style="@style/SudGlifButton.Tertiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setup_lock_settings_options_button_label"
android:visibility="gone"/>
</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient> </com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
</com.google.android.setupdesign.GlifLayout> </com.google.android.setupdesign.GlifLayout>

0
res/values-land/dimens.xml Executable file → Normal file
View File

View File

@@ -21,6 +21,7 @@
<item name="android:minHeight">@dimen/biometric_auth_pattern_view_size</item> <item name="android:minHeight">@dimen/biometric_auth_pattern_view_size</item>
<item name="android:minWidth">@dimen/biometric_auth_pattern_view_size</item> <item name="android:minWidth">@dimen/biometric_auth_pattern_view_size</item>
<item name="android:gravity">center</item> <item name="android:gravity">center</item>
<item name="android:layout_gravity">bottom</item>
<item name="android:paddingBottom">0dp</item> <item name="android:paddingBottom">0dp</item>
<item name="android:paddingHorizontal">0dp</item> <item name="android:paddingHorizontal">0dp</item>
<item name="android:paddingTop">0dp</item> <item name="android:paddingTop">0dp</item>

View File

@@ -449,6 +449,12 @@
<item name="*android:dotColor">?android:attr/textColorSecondary</item> <item name="*android:dotColor">?android:attr/textColorSecondary</item>
</style> </style>
<style name="LockPatternButtonStyle" parent="@style/SudGlifButton.Tertiary">
<item name="android:layout_marginStart">@dimen/sud_glif_button_margin_start</item>
<item name="android:layout_marginEnd">@dimen/sud_glif_button_margin_end</item>
<item name="android:layout_gravity">start|top</item>
</style>
<style name="device_info_dialog_label"> <style name="device_info_dialog_label">
<item name="android:textAlignment">viewStart</item> <item name="android:textAlignment">viewStart</item>
<item name="android:fontFamily">@*android:string/config_headlineFontFamily</item> <item name="android:fontFamily">@*android:string/config_headlineFontFamily</item>

View File

@@ -44,6 +44,7 @@ import com.android.settings.homepage.DeepLinkHomepageActivity;
import com.android.settings.homepage.DeepLinkHomepageActivityInternal; import com.android.settings.homepage.DeepLinkHomepageActivityInternal;
import com.android.settings.homepage.SettingsHomepageActivity; import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settings.password.ChooseLockPattern;
import com.android.settingslib.users.AvatarPickerActivity; import com.android.settingslib.users.AvatarPickerActivity;
import java.util.HashSet; import java.util.HashSet;
@@ -229,6 +230,7 @@ public class ActivityEmbeddingRulesController {
addActivityFilter(activityFilters, FingerprintEnrollIntroductionInternal.class); addActivityFilter(activityFilters, FingerprintEnrollIntroductionInternal.class);
addActivityFilter(activityFilters, FingerprintEnrollEnrolling.class); addActivityFilter(activityFilters, FingerprintEnrollEnrolling.class);
addActivityFilter(activityFilters, AvatarPickerActivity.class); addActivityFilter(activityFilters, AvatarPickerActivity.class);
addActivityFilter(activityFilters, ChooseLockPattern.class);
mSplitController.registerRule(new ActivityRule(activityFilters, true /* alwaysExpand */)); mSplitController.registerRule(new ActivityRule(activityFilters, true /* alwaysExpand */));
} }

View File

@@ -212,7 +212,7 @@ public class ChooseLockPattern extends SettingsActivity {
protected LockPatternView mLockPatternView; protected LockPatternView mLockPatternView;
protected TextView mFooterText; protected TextView mFooterText;
protected FooterButton mSkipOrClearButton; protected FooterButton mSkipOrClearButton;
private FooterButton mNextButton; protected FooterButton mNextButton;
@VisibleForTesting protected LockscreenCredential mChosenPattern; @VisibleForTesting protected LockscreenCredential mChosenPattern;
private ColorStateList mDefaultHeaderColorList; private ColorStateList mDefaultHeaderColorList;
private View mSudContent; private View mSudContent;
@@ -368,31 +368,34 @@ public class ChooseLockPattern extends SettingsActivity {
Introduction( Introduction(
R.string.lock_settings_picker_biometrics_added_security_message, R.string.lock_settings_picker_biometrics_added_security_message,
R.string.lockpattern_recording_intro_header, R.string.lockpassword_choose_your_pattern_description,
LeftButtonMode.Gone, RightButtonMode.ContinueDisabled, LeftButtonMode.Gone, RightButtonMode.ContinueDisabled,
ID_EMPTY_MESSAGE, true), ID_EMPTY_MESSAGE, true),
HelpScreen( HelpScreen(
ID_EMPTY_MESSAGE, R.string.lockpattern_settings_help_how_to_record, R.string.lockpattern_settings_help_how_to_record,
R.string.lockpattern_settings_help_how_to_record,
LeftButtonMode.Gone, RightButtonMode.Ok, ID_EMPTY_MESSAGE, false), LeftButtonMode.Gone, RightButtonMode.Ok, ID_EMPTY_MESSAGE, false),
ChoiceTooShort( ChoiceTooShort(
R.string.lock_settings_picker_biometrics_added_security_message, R.string.lockpattern_recording_incorrect_too_short,
R.string.lockpattern_recording_incorrect_too_short, R.string.lockpattern_recording_incorrect_too_short,
LeftButtonMode.Retry, RightButtonMode.ContinueDisabled, LeftButtonMode.Retry, RightButtonMode.ContinueDisabled,
ID_EMPTY_MESSAGE, true), ID_EMPTY_MESSAGE, true),
FirstChoiceValid( FirstChoiceValid(
R.string.lock_settings_picker_biometrics_added_security_message, R.string.lockpattern_pattern_entered_header,
R.string.lockpattern_pattern_entered_header, R.string.lockpattern_pattern_entered_header,
LeftButtonMode.Retry, RightButtonMode.Continue, ID_EMPTY_MESSAGE, false), LeftButtonMode.Retry, RightButtonMode.Continue, ID_EMPTY_MESSAGE, false),
NeedToConfirm( NeedToConfirm(
ID_EMPTY_MESSAGE, R.string.lockpattern_need_to_confirm, R.string.lockpattern_need_to_confirm, R.string.lockpattern_need_to_confirm,
LeftButtonMode.Gone, RightButtonMode.ConfirmDisabled, LeftButtonMode.Gone, RightButtonMode.ConfirmDisabled,
ID_EMPTY_MESSAGE, true), ID_EMPTY_MESSAGE, true),
ConfirmWrong( ConfirmWrong(
ID_EMPTY_MESSAGE, R.string.lockpattern_need_to_unlock_wrong, R.string.lockpattern_need_to_unlock_wrong,
R.string.lockpattern_need_to_unlock_wrong,
LeftButtonMode.Gone, RightButtonMode.ConfirmDisabled, LeftButtonMode.Gone, RightButtonMode.ConfirmDisabled,
ID_EMPTY_MESSAGE, true), ID_EMPTY_MESSAGE, true),
ChoiceConfirmed( ChoiceConfirmed(
ID_EMPTY_MESSAGE, R.string.lockpattern_pattern_confirmed_header, R.string.lockpattern_pattern_confirmed_header,
R.string.lockpattern_pattern_confirmed_header,
LeftButtonMode.Gone, RightButtonMode.Confirm, ID_EMPTY_MESSAGE, false); LeftButtonMode.Gone, RightButtonMode.Confirm, ID_EMPTY_MESSAGE, false);
@@ -549,7 +552,9 @@ public class ChooseLockPattern extends SettingsActivity {
@Override @Override
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
mHeaderText = (TextView) view.findViewById(R.id.headerText); final GlifLayout layout = getActivity().findViewById(R.id.setup_wizard_layout);
mHeaderText = layout.getDescriptionTextView();
mHeaderText.setMinLines(2);
mDefaultHeaderColorList = mHeaderText.getTextColors(); mDefaultHeaderColorList = mHeaderText.getTextColors();
mLockPatternView = (LockPatternView) view.findViewById(R.id.lockPattern); mLockPatternView = (LockPatternView) view.findViewById(R.id.lockPattern);
mLockPatternView.setOnPatternListener(mChooseNewLockPatternListener); mLockPatternView.setOnPatternListener(mChooseNewLockPatternListener);
@@ -724,30 +729,24 @@ public class ChooseLockPattern extends SettingsActivity {
*/ */
protected void updateStage(Stage stage) { protected void updateStage(Stage stage) {
final Stage previousStage = mUiStage; final Stage previousStage = mUiStage;
final GlifLayout layout = getActivity().findViewById(R.id.setup_wizard_layout);
mUiStage = stage; mUiStage = stage;
if (stage == Stage.Introduction) {
layout.setDescriptionText(stage.headerMessage);
}
// header text, footer text, visibility and // header text, footer text, visibility and
// enabled state all known from the stage // enabled state all known from the stage
if (stage == Stage.ChoiceTooShort) { if (stage == Stage.ChoiceTooShort) {
mHeaderText.setText( layout.setDescriptionText(
getResources().getString( getResources().getString(
stage.headerMessage, stage.headerMessage,
LockPatternUtils.MIN_LOCK_PATTERN_SIZE)); LockPatternUtils.MIN_LOCK_PATTERN_SIZE));
} else { } else {
mHeaderText.setText(stage.headerMessage); layout.setDescriptionText(stage.headerMessage);
}
final GlifLayout layout = getActivity().findViewById(R.id.setup_wizard_layout);
final boolean forAnyBiometric = mForFingerprint || mForFace || mForBiometrics;
if (forAnyBiometric) {
if (stage.messageForBiometrics == ID_EMPTY_MESSAGE) {
layout.setDescriptionText("");
} else {
layout.setDescriptionText(stage.messageForBiometrics);
}
} else {
layout.getDescriptionTextView().setVisibility(View.GONE);
} }
if (stage.footerMessage == ID_EMPTY_MESSAGE) { if (stage.footerMessage == ID_EMPTY_MESSAGE) {
mFooterText.setText(""); mFooterText.setText("");
} else { } else {
@@ -765,8 +764,8 @@ public class ChooseLockPattern extends SettingsActivity {
mHeaderText.setTextColor(mDefaultHeaderColorList); mHeaderText.setTextColor(mDefaultHeaderColorList);
} }
if (stage == Stage.NeedToConfirm && forAnyBiometric) { if (stage == Stage.NeedToConfirm) {
mHeaderText.setText(""); mHeaderText.setText(stage.headerMessage);
layout.setHeaderText(R.string.lockpassword_draw_your_pattern_again_header); layout.setHeaderText(R.string.lockpassword_draw_your_pattern_again_header);
} }
} }
@@ -796,6 +795,7 @@ public class ChooseLockPattern extends SettingsActivity {
mLockPatternView.setPattern(DisplayMode.Animate, mAnimatePattern); mLockPatternView.setPattern(DisplayMode.Animate, mAnimatePattern);
break; break;
case ChoiceTooShort: case ChoiceTooShort:
case ConfirmWrong:
mLockPatternView.setDisplayMode(DisplayMode.Wrong); mLockPatternView.setDisplayMode(DisplayMode.Wrong);
postClearPatternRunnable(); postClearPatternRunnable();
announceAlways = true; announceAlways = true;
@@ -805,11 +805,6 @@ public class ChooseLockPattern extends SettingsActivity {
case NeedToConfirm: case NeedToConfirm:
mLockPatternView.clearPattern(); mLockPatternView.clearPattern();
break; break;
case ConfirmWrong:
mLockPatternView.setDisplayMode(DisplayMode.Wrong);
postClearPatternRunnable();
announceAlways = true;
break;
case ChoiceConfirmed: case ChoiceConfirmed:
break; break;
} }

View File

@@ -16,6 +16,8 @@
package com.android.settings.password; package com.android.settings.password;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@@ -30,8 +32,6 @@ import androidx.fragment.app.Fragment;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SetupRedactionInterstitial; import com.android.settings.SetupRedactionInterstitial;
import com.google.android.setupdesign.GlifLayout;
/** /**
* Setup Wizard's version of ChooseLockPattern screen. It inherits the logic and basic structure * Setup Wizard's version of ChooseLockPattern screen. It inherits the logic and basic structure
* from ChooseLockPattern class, and should remain similar to that behaviorally. This class should * from ChooseLockPattern class, and should remain similar to that behaviorally. This class should
@@ -123,15 +123,25 @@ public class SetupChooseLockPattern extends ChooseLockPattern {
startChooseLockActivity(lock, getActivity()); startChooseLockActivity(lock, getActivity());
} }
private boolean showMinimalUi() {
return getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui);
}
@Override @Override
protected void updateStage(Stage stage) { protected void updateStage(Stage stage) {
super.updateStage(stage); super.updateStage(stage);
if (!getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui) if (!showMinimalUi() && mOptionsButton != null) {
&& mOptionsButton != null) { // In landscape, keep view stub to avoid pattern view shifting, but in portrait the
// header title and description could become multiple lines in confirm stage,
// gone the button view to reserve more room for growth height of header.
@View.Visibility
final int hideOrGone =
getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE
? View.INVISIBLE : View.GONE;
mOptionsButton.setVisibility( mOptionsButton.setVisibility(
(stage == Stage.Introduction || stage == Stage.HelpScreen || (stage == Stage.Introduction || stage == Stage.HelpScreen ||
stage == Stage.ChoiceTooShort || stage == Stage.FirstChoiceValid) stage == Stage.ChoiceTooShort || stage == Stage.FirstChoiceValid)
? View.VISIBLE : View.INVISIBLE); ? View.VISIBLE : hideOrGone);
} }
if (stage.leftMode == LeftButtonMode.Gone && stage == Stage.Introduction) { if (stage.leftMode == LeftButtonMode.Gone && stage == Stage.Introduction) {
@@ -141,10 +151,6 @@ public class SetupChooseLockPattern extends ChooseLockPattern {
} else { } else {
mLeftButtonIsSkip = false; mLeftButtonIsSkip = false;
} }
final GlifLayout layout = getActivity().findViewById(R.id.setup_wizard_layout);
layout.setDescriptionText(
getString(R.string.lockpassword_choose_your_pattern_description));
} }
@Override @Override

View File

@@ -24,7 +24,9 @@ import static org.robolectric.RuntimeEnvironment.application;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
@@ -32,6 +34,7 @@ import android.widget.TextView;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockPatternView; import com.android.internal.widget.LockPatternView;
import com.android.internal.widget.LockPatternView.Cell; import com.android.internal.widget.LockPatternView.Cell;
import com.android.internal.widget.LockPatternView.DisplayMode; import com.android.internal.widget.LockPatternView.DisplayMode;
@@ -45,6 +48,7 @@ import com.android.settings.testutils.shadow.ShadowUtils;
import com.google.android.setupcompat.PartnerCustomizationLayout; import com.google.android.setupcompat.PartnerCustomizationLayout;
import com.google.android.setupcompat.template.FooterBarMixin; import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.template.FooterButton;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -94,11 +98,11 @@ public class SetupChooseLockPatternTest {
@Test @Test
public void optionsButton_whenPatternSelected_shouldBeVisible() { public void optionsButton_whenPatternSelected_shouldBeVisible() {
Button button = mActivity.findViewById(R.id.screen_lock_options); final Button button = mActivity.findViewById(R.id.screen_lock_options);
assertThat(button).isNotNull(); assertThat(button).isNotNull();
assertThat(button.getVisibility()).isEqualTo(View.VISIBLE); assertThat(button.getVisibility()).isEqualTo(View.VISIBLE);
LockPatternView lockPatternView = mActivity.findViewById(R.id.lockPattern); final LockPatternView lockPatternView = mActivity.findViewById(R.id.lockPattern);
ReflectionHelpers.callInstanceMethod(lockPatternView, "notifyPatternDetected"); ReflectionHelpers.callInstanceMethod(lockPatternView, "notifyPatternDetected");
enterPattern(); enterPattern();
@@ -106,12 +110,12 @@ public class SetupChooseLockPatternTest {
} }
private void verifyScreenLockOptionsShown() { private void verifyScreenLockOptionsShown() {
Button button = mActivity.findViewById(R.id.screen_lock_options); final Button button = mActivity.findViewById(R.id.screen_lock_options);
assertThat(button).isNotNull(); assertThat(button).isNotNull();
assertThat(button.getVisibility()).isEqualTo(View.VISIBLE); assertThat(button.getVisibility()).isEqualTo(View.VISIBLE);
button.performClick(); button.performClick();
AlertDialog chooserDialog = ShadowAlertDialogCompat.getLatestAlertDialog(); final AlertDialog chooserDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
assertThat(chooserDialog).isNotNull(); assertThat(chooserDialog).isNotNull();
int count = chooserDialog.getListView().getCount(); int count = chooserDialog.getListView().getCount();
assertWithMessage("List items shown").that(count).isEqualTo(3); assertWithMessage("List items shown").that(count).isEqualTo(3);
@@ -149,9 +153,10 @@ public class SetupChooseLockPatternTest {
@Test @Test
public void skipButton_shouldBeVisible_duringNonFingerprintFlow() { public void skipButton_shouldBeVisible_duringNonFingerprintFlow() {
PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout); final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final Button skipOrClearButton = final Button skipOrClearButton =
layout.getMixin(FooterBarMixin.class).getSecondaryButtonView(); layout.getMixin(FooterBarMixin.class).getSecondaryButtonView();
assertThat(skipOrClearButton).isNotNull(); assertThat(skipOrClearButton).isNotNull();
assertThat(skipOrClearButton.getVisibility()).isEqualTo(View.VISIBLE); assertThat(skipOrClearButton.getVisibility()).isEqualTo(View.VISIBLE);
@@ -164,29 +169,31 @@ public class SetupChooseLockPatternTest {
public void clearButton_shouldBeVisible_duringRetryStage() { public void clearButton_shouldBeVisible_duringRetryStage() {
enterPattern(); enterPattern();
PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout); final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final Button skipOrClearButton = final Button skipOrClearButton =
layout.getMixin(FooterBarMixin.class).getSecondaryButtonView(); layout.getMixin(FooterBarMixin.class).getSecondaryButtonView();
assertThat(skipOrClearButton.getVisibility()).isEqualTo(View.VISIBLE); assertThat(skipOrClearButton.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(skipOrClearButton.isEnabled()).isTrue(); assertThat(skipOrClearButton.isEnabled()).isTrue();
skipOrClearButton.performClick(); skipOrClearButton.performClick();
assertThat(findFragment(mActivity).mChosenPattern).isNull(); assertThat(findFragment(mActivity).mChosenPattern).isNull();
} }
@Test @Test
public void createActivity_enterPattern_clearButtonShouldBeShown() { public void createActivity_enterPattern_clearButtonShouldBeShown() {
ChooseLockPatternFragment fragment = findFragment(mActivity); final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final Button skipOrClearButton = final Button skipOrClearButton =
layout.getMixin(FooterBarMixin.class).getSecondaryButtonView(); layout.getMixin(FooterBarMixin.class).getSecondaryButtonView();
assertThat(skipOrClearButton.isEnabled()).isTrue(); assertThat(skipOrClearButton.isEnabled()).isTrue();
assertThat(skipOrClearButton.getVisibility()).isEqualTo(View.VISIBLE); assertThat(skipOrClearButton.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(skipOrClearButton.getText()) assertThat(skipOrClearButton.getText())
.isEqualTo(application.getString(R.string.skip_label)); .isEqualTo(application.getString(R.string.skip_label));
enterPattern(); enterPattern();
assertThat(skipOrClearButton.isEnabled()).isTrue(); assertThat(skipOrClearButton.isEnabled()).isTrue();
assertThat(skipOrClearButton.getVisibility()).isEqualTo(View.VISIBLE); assertThat(skipOrClearButton.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(skipOrClearButton.getText()) assertThat(skipOrClearButton.getText())
@@ -195,8 +202,7 @@ public class SetupChooseLockPatternTest {
@Test @Test
public void createActivity_patternDescription_shouldBeShown() { public void createActivity_patternDescription_shouldBeShown() {
PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout); final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final TextView patternDescription = final TextView patternDescription =
layout.findViewById(R.id.sud_layout_subtitle); layout.findViewById(R.id.sud_layout_subtitle);
@@ -205,6 +211,140 @@ public class SetupChooseLockPatternTest {
application.getString(R.string.lockpassword_choose_your_pattern_description)); application.getString(R.string.lockpassword_choose_your_pattern_description));
} }
@Test
public void inIntroductionStage_theHeaderHeight_shouldSetMinLinesTwoToPreventFlicker() {
final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final TextView headerView = layout.findViewById(R.id.sud_layout_subtitle);
assertThat(headerView.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(headerView.getText().toString()).isEqualTo(
application.getString(R.string.lockpassword_choose_your_pattern_description));
}
@Test
public void createActivity_enterPattern_shouldGoToFirstChoiceValidStage() {
final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final TextView headerView = layout.findViewById(R.id.sud_layout_subtitle);
assertThat(headerView.getVisibility()).isEqualTo(View.VISIBLE);
enterPattern();
assertThat(headerView.getText().toString()).isEqualTo(
application.getString(R.string.lockpattern_pattern_entered_header));
}
@Test
public void createActivity_enterShortPattern_shouldGoToChoiceTooShortStage() {
final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final TextView headerView = layout.findViewById(R.id.sud_layout_subtitle);
enterShortPattern();
assertThat(headerView.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(headerView.getText().toString()).isEqualTo(
application.getResources().getString(
R.string.lockpattern_recording_incorrect_too_short,
LockPatternUtils.MIN_LOCK_PATTERN_SIZE));
}
@Test
public void inChoiceTooShortStage_theHeaderColor_shouldTintOnErrorColor() {
final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final TextView headerView = layout.findViewById(R.id.sud_layout_subtitle);
final TypedValue typedValue = new TypedValue();
final Resources.Theme theme = mActivity.getTheme();
theme.resolveAttribute(R.attr.colorError, typedValue, true);
final int errorColor = typedValue.data;
enterShortPattern();
assertThat(headerView.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(headerView.getTextColors().getDefaultColor()).isEqualTo(errorColor);
}
@Test
public void inFirstChoiceValidStage_nextButtonState_shouldEnabled() {
final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final FooterBarMixin footerBarMixin = layout.getMixin(FooterBarMixin.class);
final FooterButton nextButton = footerBarMixin.getPrimaryButton();
assertThat(nextButton.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(nextButton.isEnabled()).isFalse();
enterPattern();
assertThat(nextButton.isEnabled()).isTrue();
}
@Test
public void inFirstChoiceValidStage_clickNextButton_shouldGoToNeedToConfirmStage() {
final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final TextView headerView = layout.findViewById(R.id.sud_layout_subtitle);
final FooterBarMixin footerBarMixin = layout.getMixin(FooterBarMixin.class);
final Button nextButton = footerBarMixin.getPrimaryButtonView();
assertThat(headerView.getVisibility()).isEqualTo(View.VISIBLE);
enterPattern();
nextButton.performClick();
assertThat(headerView.getText().toString()).isEqualTo(
application.getString(R.string.lockpattern_need_to_confirm));
}
@Test
public void inNeedToConfirmStage_enterWrongPattern_shouldGoToConfirmWrongStage() {
final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final TextView headerView = layout.findViewById(R.id.sud_layout_subtitle);
final FooterBarMixin footerBarMixin = layout.getMixin(FooterBarMixin.class);
final Button nextButton = footerBarMixin.getPrimaryButtonView();
// IntroductionStage
assertThat(headerView.getVisibility()).isEqualTo(View.VISIBLE);
enterPattern();
nextButton.performClick();
// NeedToConfirmStage
assertThat(headerView.getText().toString()).isEqualTo(
application.getString(R.string.lockpattern_need_to_confirm));
enterShortPattern();
// ConfirmWrongStage
assertThat(headerView.getText().toString()).isEqualTo(
application.getString(R.string.lockpattern_need_to_unlock_wrong));
assertThat(nextButton.getText().toString()).isEqualTo(
application.getString(R.string.lockpattern_confirm_button_text));
assertThat(nextButton.isEnabled()).isFalse();
}
@Test
public void inNeedToConfirmStage_enterCorrectPattern_shouldGoToChoiceConfirmedStage() {
final PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
final TextView headerView = layout.findViewById(R.id.sud_layout_subtitle);
final FooterBarMixin footerBarMixin = layout.getMixin(FooterBarMixin.class);
final Button nextButton = footerBarMixin.getPrimaryButtonView();
// IntroductionStage
assertThat(headerView.getVisibility()).isEqualTo(View.VISIBLE);
enterPattern();
nextButton.performClick();
// NeedToConfirmStage
assertThat(headerView.getText().toString()).isEqualTo(
application.getString(R.string.lockpattern_need_to_confirm));
enterPattern();
// ChoiceConfirmedStage
assertThat(headerView.getText().toString()).isEqualTo(
application.getString(R.string.lockpattern_pattern_confirmed_header));
assertThat(nextButton.getText().toString()).isEqualTo(
application.getString(R.string.lockpattern_confirm_button_text));
assertThat(nextButton.isEnabled()).isTrue();
}
private ChooseLockPatternFragment findFragment(FragmentActivity activity) { private ChooseLockPatternFragment findFragment(FragmentActivity activity) {
return (ChooseLockPatternFragment) return (ChooseLockPatternFragment)
activity.getSupportFragmentManager().findFragmentById(R.id.main_content); activity.getSupportFragmentManager().findFragmentById(R.id.main_content);
@@ -222,6 +362,17 @@ public class SetupChooseLockPatternTest {
ReflectionHelpers.callInstanceMethod(lockPatternView, "notifyPatternDetected"); ReflectionHelpers.callInstanceMethod(lockPatternView, "notifyPatternDetected");
} }
private void enterShortPattern() {
LockPatternView lockPatternView = mActivity.findViewById(R.id.lockPattern);
lockPatternView.setPattern(
DisplayMode.Animate,
Arrays.asList(
createCell(0, 0),
createCell(0, 1),
createCell(1, 1)));
ReflectionHelpers.callInstanceMethod(lockPatternView, "notifyPatternDetected");
}
private Cell createCell(int row, int column) { private Cell createCell(int row, int column) {
return ReflectionHelpers.callConstructor( return ReflectionHelpers.callConstructor(
Cell.class, Cell.class,