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

Commit be2246be authored by Ajay Nadathur's avatar Ajay Nadathur
Browse files

Add 'clear' button to pin/password lock screen

bug: 62904466
Test: Manually tested, added functional tests
Change-Id: I5f5555d99b47550a8fef6995222d12155b4072a9
parent ce056636
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -28,6 +28,15 @@
        android:layout_height="wrap_content"
        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
        android:layout_width="0dp"
        android:layout_height="0dp"
+3 −0
Original line number Diff line number Diff line
@@ -1375,6 +1375,9 @@
    <!-- Label for ChoosePassword/PIN OK button -->
    <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 -->
    <string name="lockpattern_tutorial_cancel_label">Cancel</string>
+16 −0
Original line number Diff line number Diff line
@@ -211,6 +211,7 @@ public class ChooseLockPassword extends SettingsActivity {
        private RecyclerView mPasswordRestrictionView;
        protected boolean mIsAlphaMode;
        protected Button mCancelButton;
        private Button mClearButton;
        private Button mNextButton;

        private TextChangedHandler mTextChangedHandler;
@@ -347,6 +348,8 @@ public class ChooseLockPassword extends SettingsActivity {
            mCancelButton.setOnClickListener(this);
            mNextButton = (Button) view.findViewById(R.id.next_button);
            mNextButton.setOnClickListener(this);
            mClearButton = view.findViewById(R.id.clear_button);
            mClearButton.setOnClickListener(this);

            if (mForFingerprint) {
                TextView fingerprintBackupMessage =
@@ -735,6 +738,10 @@ public class ChooseLockPassword extends SettingsActivity {
                case R.id.cancel_button:
                    getActivity().finish();
                    break;

                case R.id.clear_button:
                    mPasswordEntry.setText("");
                    break;
            }
        }

@@ -839,11 +846,20 @@ public class ChooseLockPassword extends SettingsActivity {
                mPasswordRestrictionView.setVisibility(View.GONE);
                setHeaderText(getString(mUiStage.getHint(mIsAlphaMode, mForFingerprint)));
                setNextEnabled(canInput && length > 0);
                mClearButton.setEnabled(canInput && length > 0);
            }

            mClearButton.setVisibility(toVisibility(mUiStage != Stage.Introduction));
            mCancelButton.setVisibility(toVisibility(mUiStage == Stage.Introduction));

            setNextText(mUiStage.buttonText);
            mPasswordEntryInputDisabler.setInputEnabled(canInput);
        }

        private int toVisibility(boolean visibleOrGone) {
            return visibleOrGone ? View.VISIBLE : View.GONE;
        }

        private void setHeaderText(String text) {
            // Only set the text if it is different than the existing one to avoid announcing again.
            if (!TextUtils.isEmpty(mLayout.getHeaderText())
+6 −7
Original line number Diff line number Diff line
@@ -84,13 +84,6 @@ public class SetupChooseLockPassword extends ChooseLockPassword {
        @Override
        public void onViewCreated(View view, Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);

            if (mForFingerprint) {
                mCancelButton.setVisibility(View.GONE);
            } else {
                mCancelButton.setText(R.string.skip_label);
            }

            final Activity activity = getActivity();
            ChooseLockGenericController chooseLockGenericController =
                    new ChooseLockGenericController(activity, mUserId);
@@ -190,6 +183,12 @@ public class SetupChooseLockPassword extends ChooseLockPassword {
        @Override
        protected void updateUi() {
            super.updateUi();
            if (mForFingerprint) {
                mCancelButton.setVisibility(View.GONE);
            } else {
                mCancelButton.setText(R.string.skip_label);
            }

            if (mOptionsButton != null) {
                mOptionsButton.setVisibility(
                        mUiStage == Stage.Introduction ? View.VISIBLE : View.GONE);
+81 −0
Original line number Diff line number Diff line
/*
 * 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()));
    }
}
Loading