Add 'clear' button to pin/password lock screen
bug: 62904466 Test: Manually tested, added functional tests Change-Id: I5f5555d99b47550a8fef6995222d12155b4072a9
This commit is contained in:
@@ -28,6 +28,15 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/lockpassword_cancel_label" />
|
android:text="@string/lockpassword_cancel_label" />
|
||||||
|
|
||||||
|
|
||||||
|
<!-- left : clear -->
|
||||||
|
<Button android:id="@+id/clear_button"
|
||||||
|
style="@style/SuwGlifButton.Secondary"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:text="@string/lockpassword_clear_label" />
|
||||||
|
|
||||||
<Space
|
<Space
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
|
@@ -1375,6 +1375,9 @@
|
|||||||
<!-- Label for ChoosePassword/PIN OK button -->
|
<!-- Label for ChoosePassword/PIN OK button -->
|
||||||
<string name="lockpassword_cancel_label">Cancel</string>
|
<string name="lockpassword_cancel_label">Cancel</string>
|
||||||
|
|
||||||
|
<!-- Label for ChoosePassword/PIN OK button -->
|
||||||
|
<string name="lockpassword_clear_label">Clear</string>
|
||||||
|
|
||||||
<!-- Label for LockPatternTutorial Cancel button -->
|
<!-- Label for LockPatternTutorial Cancel button -->
|
||||||
<string name="lockpattern_tutorial_cancel_label">Cancel</string>
|
<string name="lockpattern_tutorial_cancel_label">Cancel</string>
|
||||||
|
|
||||||
|
@@ -211,6 +211,7 @@ public class ChooseLockPassword extends SettingsActivity {
|
|||||||
private RecyclerView mPasswordRestrictionView;
|
private RecyclerView mPasswordRestrictionView;
|
||||||
protected boolean mIsAlphaMode;
|
protected boolean mIsAlphaMode;
|
||||||
protected Button mCancelButton;
|
protected Button mCancelButton;
|
||||||
|
private Button mClearButton;
|
||||||
private Button mNextButton;
|
private Button mNextButton;
|
||||||
|
|
||||||
private TextChangedHandler mTextChangedHandler;
|
private TextChangedHandler mTextChangedHandler;
|
||||||
@@ -347,6 +348,8 @@ public class ChooseLockPassword extends SettingsActivity {
|
|||||||
mCancelButton.setOnClickListener(this);
|
mCancelButton.setOnClickListener(this);
|
||||||
mNextButton = (Button) view.findViewById(R.id.next_button);
|
mNextButton = (Button) view.findViewById(R.id.next_button);
|
||||||
mNextButton.setOnClickListener(this);
|
mNextButton.setOnClickListener(this);
|
||||||
|
mClearButton = view.findViewById(R.id.clear_button);
|
||||||
|
mClearButton.setOnClickListener(this);
|
||||||
|
|
||||||
if (mForFingerprint) {
|
if (mForFingerprint) {
|
||||||
TextView fingerprintBackupMessage =
|
TextView fingerprintBackupMessage =
|
||||||
@@ -735,6 +738,10 @@ public class ChooseLockPassword extends SettingsActivity {
|
|||||||
case R.id.cancel_button:
|
case R.id.cancel_button:
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case R.id.clear_button:
|
||||||
|
mPasswordEntry.setText("");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -839,11 +846,20 @@ public class ChooseLockPassword extends SettingsActivity {
|
|||||||
mPasswordRestrictionView.setVisibility(View.GONE);
|
mPasswordRestrictionView.setVisibility(View.GONE);
|
||||||
setHeaderText(getString(mUiStage.getHint(mIsAlphaMode, mForFingerprint)));
|
setHeaderText(getString(mUiStage.getHint(mIsAlphaMode, mForFingerprint)));
|
||||||
setNextEnabled(canInput && length > 0);
|
setNextEnabled(canInput && length > 0);
|
||||||
|
mClearButton.setEnabled(canInput && length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mClearButton.setVisibility(toVisibility(mUiStage != Stage.Introduction));
|
||||||
|
mCancelButton.setVisibility(toVisibility(mUiStage == Stage.Introduction));
|
||||||
|
|
||||||
setNextText(mUiStage.buttonText);
|
setNextText(mUiStage.buttonText);
|
||||||
mPasswordEntryInputDisabler.setInputEnabled(canInput);
|
mPasswordEntryInputDisabler.setInputEnabled(canInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int toVisibility(boolean visibleOrGone) {
|
||||||
|
return visibleOrGone ? View.VISIBLE : View.GONE;
|
||||||
|
}
|
||||||
|
|
||||||
private void setHeaderText(String text) {
|
private void setHeaderText(String text) {
|
||||||
// Only set the text if it is different than the existing one to avoid announcing again.
|
// Only set the text if it is different than the existing one to avoid announcing again.
|
||||||
if (!TextUtils.isEmpty(mLayout.getHeaderText())
|
if (!TextUtils.isEmpty(mLayout.getHeaderText())
|
||||||
|
@@ -84,13 +84,6 @@ public class SetupChooseLockPassword extends ChooseLockPassword {
|
|||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
if (mForFingerprint) {
|
|
||||||
mCancelButton.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
mCancelButton.setText(R.string.skip_label);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
ChooseLockGenericController chooseLockGenericController =
|
ChooseLockGenericController chooseLockGenericController =
|
||||||
new ChooseLockGenericController(activity, mUserId);
|
new ChooseLockGenericController(activity, mUserId);
|
||||||
@@ -190,6 +183,12 @@ public class SetupChooseLockPassword extends ChooseLockPassword {
|
|||||||
@Override
|
@Override
|
||||||
protected void updateUi() {
|
protected void updateUi() {
|
||||||
super.updateUi();
|
super.updateUi();
|
||||||
|
if (mForFingerprint) {
|
||||||
|
mCancelButton.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
mCancelButton.setText(R.string.skip_label);
|
||||||
|
}
|
||||||
|
|
||||||
if (mOptionsButton != null) {
|
if (mOptionsButton != null) {
|
||||||
mOptionsButton.setVisibility(
|
mOptionsButton.setVisibility(
|
||||||
mUiStage == Stage.Introduction ? View.VISIBLE : View.GONE);
|
mUiStage == Stage.Introduction ? View.VISIBLE : View.GONE);
|
||||||
|
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Google Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.password;
|
||||||
|
|
||||||
|
import static android.support.test.espresso.Espresso.onView;
|
||||||
|
import static android.support.test.espresso.action.ViewActions.pressKey;
|
||||||
|
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
|
|
||||||
|
import android.app.Instrumentation;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
import android.support.test.InstrumentationRegistry;
|
||||||
|
import android.support.test.espresso.action.ViewActions;
|
||||||
|
import android.support.test.espresso.matcher.ViewMatchers;
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class ChooseLockPasswordTest {
|
||||||
|
private Instrumentation mInstrumentation;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||||
|
mContext = mInstrumentation.getTargetContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void clearNotVisible_when_activityLaunchedInitially() {
|
||||||
|
mInstrumentation.startActivitySync(new Intent(mContext, ChooseLockPassword.class));
|
||||||
|
onView(withId(R.id.clear_button)).check(matches(
|
||||||
|
withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void clearNotEnabled_when_nothingEntered() {
|
||||||
|
mInstrumentation.startActivitySync(new Intent(mContext, ChooseLockPassword.class));
|
||||||
|
onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234"))
|
||||||
|
.perform(pressKey(KeyEvent.KEYCODE_ENTER));
|
||||||
|
onView(withId(R.id.clear_button)).check(matches(isDisplayed()))
|
||||||
|
.check(matches(not(isEnabled())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void clearEnabled_when_somethingEnteredToConfirm() {
|
||||||
|
mInstrumentation.startActivitySync(new Intent(mContext, ChooseLockPassword.class));
|
||||||
|
onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234"))
|
||||||
|
.perform(pressKey(KeyEvent.KEYCODE_ENTER))
|
||||||
|
.perform(ViewActions.typeText("1"));
|
||||||
|
// clear should be present if text field contains content
|
||||||
|
onView(withId(R.id.clear_button)).check(matches(isDisplayed()));
|
||||||
|
}
|
||||||
|
}
|
@@ -18,16 +18,24 @@ package com.android.settings.password;
|
|||||||
|
|
||||||
import static android.support.test.espresso.Espresso.onView;
|
import static android.support.test.espresso.Espresso.onView;
|
||||||
import static android.support.test.espresso.action.ViewActions.click;
|
import static android.support.test.espresso.action.ViewActions.click;
|
||||||
|
import static android.support.test.espresso.action.ViewActions.pressKey;
|
||||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
|
|
||||||
|
import android.support.test.espresso.action.ViewActions;
|
||||||
|
import android.support.test.espresso.matcher.ViewMatchers;
|
||||||
import android.support.test.filters.MediumTest;
|
import android.support.test.filters.MediumTest;
|
||||||
import android.support.test.rule.ActivityTestRule;
|
import android.support.test.rule.ActivityTestRule;
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
@@ -58,4 +66,30 @@ public class SetupChooseLockPasswordAppTest {
|
|||||||
|
|
||||||
assertThat(activity.isFinishing()).named("Is finishing").isTrue();
|
assertThat(activity.isFinishing()).named("Is finishing").isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void clearNotVisible_when_activityLaunchedInitially() {
|
||||||
|
mActivityTestRule.launchActivity(null);
|
||||||
|
onView(withId(R.id.clear_button)).check(matches(
|
||||||
|
withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void clearNotEnabled_when_nothingEntered() throws Throwable {
|
||||||
|
mActivityTestRule.launchActivity(null);
|
||||||
|
onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234"))
|
||||||
|
.perform(pressKey(KeyEvent.KEYCODE_ENTER));
|
||||||
|
onView(withId(R.id.clear_button)).check(matches(isDisplayed()))
|
||||||
|
.check(matches(not(isEnabled())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void clearEnabled_when_somethingEnteredToConfirm() {
|
||||||
|
mActivityTestRule.launchActivity(null);
|
||||||
|
onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234"))
|
||||||
|
.perform(pressKey(KeyEvent.KEYCODE_ENTER))
|
||||||
|
.perform(ViewActions.typeText("1"));
|
||||||
|
// clear should be present if text field contains content
|
||||||
|
onView(withId(R.id.clear_button)).check(matches(isDisplayed()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user