Gray out confirm button on pattern/pin/password set dialog

Setting a pin/pattern/password can take a second. Gray out the confirm
button to avoid multiple submissions.

Note that this requires async tasks so that the button is shown as gray
in a timely way.

Also don't add another stage - this causes a11y to repeat the title.

Bug: 22882174
Change-Id: Ib8047fde9e12afa25e82ebfa3a1e799a4b7043f2
This commit is contained in:
Paul Lawrence
2015-08-03 09:44:23 -07:00
parent 18d8682802
commit cff37ecbdd
2 changed files with 76 additions and 49 deletions

View File

@@ -128,6 +128,7 @@ public class ChooseLockPassword extends SettingsActivity {
private static final String KEY_CURRENT_PASSWORD = "current_password"; private static final String KEY_CURRENT_PASSWORD = "current_password";
private String mCurrentPassword; private String mCurrentPassword;
private String mChosenPassword;
private boolean mHasChallenge; private boolean mHasChallenge;
private long mChallenge; private long mChallenge;
private TextView mPasswordEntry; private TextView mPasswordEntry;
@@ -145,7 +146,6 @@ public class ChooseLockPassword extends SettingsActivity {
private int mRequestedQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC; private int mRequestedQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
private ChooseLockSettingsHelper mChooseLockSettingsHelper; private ChooseLockSettingsHelper mChooseLockSettingsHelper;
private Stage mUiStage = Stage.Introduction; private Stage mUiStage = Stage.Introduction;
private boolean mDone = false;
private TextView mHeaderText; private TextView mHeaderText;
private String mFirstPin; private String mFirstPin;
private KeyboardView mKeyboardView; private KeyboardView mKeyboardView;
@@ -302,7 +302,6 @@ public class ChooseLockPassword extends SettingsActivity {
mCurrentPassword = savedInstanceState.getString(KEY_CURRENT_PASSWORD); mCurrentPassword = savedInstanceState.getString(KEY_CURRENT_PASSWORD);
} }
} }
mDone = false;
if (activity instanceof SettingsActivity) { if (activity instanceof SettingsActivity) {
final SettingsActivity sa = (SettingsActivity) activity; final SettingsActivity sa = (SettingsActivity) activity;
int id = mIsAlphaMode ? R.string.lockpassword_choose_your_password_header int id = mIsAlphaMode ? R.string.lockpassword_choose_your_password_header
@@ -478,37 +477,54 @@ public class ChooseLockPassword extends SettingsActivity {
return null; return null;
} }
public void handleNext() { private class SaveChosenPasswordAndFinish extends AsyncTask<Void, Void, Void> {
if (mDone) return; boolean mWasSecureBefore;
final String pin = mPasswordEntry.getText().toString(); @Override
if (TextUtils.isEmpty(pin)) { public void onPreExecute() {
return; mWasSecureBefore = mLockPatternUtils.isSecure(UserHandle.myUserId());
}
String errorMsg = null;
if (mUiStage == Stage.Introduction) {
errorMsg = validatePassword(pin);
if (errorMsg == null) {
mFirstPin = pin;
mPasswordEntry.setText("");
updateStage(Stage.NeedToConfirm);
}
} else if (mUiStage == Stage.NeedToConfirm) {
if (mFirstPin.equals(pin)) {
boolean wasSecureBefore = mLockPatternUtils.isSecure(UserHandle.myUserId());
final boolean required = getActivity().getIntent().getBooleanExtra( final boolean required = getActivity().getIntent().getBooleanExtra(
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true); EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
mLockPatternUtils.setCredentialRequiredToDecrypt(required); mLockPatternUtils.setCredentialRequiredToDecrypt(required);
mLockPatternUtils.saveLockPassword(pin, mCurrentPassword, mRequestedQuality, }
UserHandle.myUserId());
@Override
public Void doInBackground(Void... v) {
mLockPatternUtils.saveLockPassword(mChosenPassword, mCurrentPassword, mRequestedQuality,
UserHandle.myUserId());
return null;
}
@Override
public void onPostExecute(Void v) {
if (mHasChallenge) { if (mHasChallenge) {
startVerifyPassword(pin, wasSecureBefore); startVerifyPassword(mChosenPassword, mWasSecureBefore);
return; return;
} else { } else {
getActivity().setResult(RESULT_FINISHED); getActivity().setResult(RESULT_FINISHED);
} }
finishConfirmStage(wasSecureBefore); finishConfirmStage(mWasSecureBefore);
}
}
public void handleNext() {
mChosenPassword = mPasswordEntry.getText().toString();
if (TextUtils.isEmpty(mChosenPassword)) {
return;
}
String errorMsg = null;
if (mUiStage == Stage.Introduction) {
errorMsg = validatePassword(mChosenPassword);
if (errorMsg == null) {
mFirstPin = mChosenPassword;
mPasswordEntry.setText("");
updateStage(Stage.NeedToConfirm);
}
} else if (mUiStage == Stage.NeedToConfirm) {
if (mFirstPin.equals(mChosenPassword)) {
setNextEnabled(false);
new SaveChosenPasswordAndFinish().execute();
} else { } else {
CharSequence tmp = mPasswordEntry.getText(); CharSequence tmp = mPasswordEntry.getText();
if (tmp != null) { if (tmp != null) {
@@ -557,7 +573,6 @@ public class ChooseLockPassword extends SettingsActivity {
private void finishConfirmStage(boolean wasSecureBefore) { private void finishConfirmStage(boolean wasSecureBefore) {
getActivity().finish(); getActivity().finish();
mDone = true;
if (!wasSecureBefore) { if (!wasSecureBefore) {
Intent intent = getRedactionInterstitialIntent(getActivity()); Intent intent = getRedactionInterstitialIntent(getActivity());
if (intent != null) { if (intent != null) {

View File

@@ -346,7 +346,6 @@ public class ChooseLockPattern extends SettingsActivity {
} }
private Stage mUiStage = Stage.Introduction; private Stage mUiStage = Stage.Introduction;
private boolean mDone = false;
private Runnable mClearPatternRunnable = new Runnable() { private Runnable mClearPatternRunnable = new Runnable() {
public void run() { public void run() {
@@ -435,7 +434,6 @@ public class ChooseLockPattern extends SettingsActivity {
} }
updateStage(Stage.values()[savedInstanceState.getInt(KEY_UI_STAGE)]); updateStage(Stage.values()[savedInstanceState.getInt(KEY_UI_STAGE)]);
} }
mDone = false;
} }
@Override @Override
@@ -483,7 +481,7 @@ public class ChooseLockPattern extends SettingsActivity {
throw new IllegalStateException("expected ui stage " + Stage.ChoiceConfirmed throw new IllegalStateException("expected ui stage " + Stage.ChoiceConfirmed
+ " when button is " + RightButtonMode.Confirm); + " when button is " + RightButtonMode.Confirm);
} }
saveChosenPatternAndFinish(); new SaveChosenPatternAndFinish().execute();
} else if (mUiStage.rightMode == RightButtonMode.Ok) { } else if (mUiStage.rightMode == RightButtonMode.Ok) {
if (mUiStage != Stage.HelpScreen) { if (mUiStage != Stage.HelpScreen) {
throw new IllegalStateException("Help screen is only mode with ok button, " throw new IllegalStateException("Help screen is only mode with ok button, "
@@ -623,27 +621,41 @@ public class ChooseLockPattern extends SettingsActivity {
mLockPatternView.postDelayed(mClearPatternRunnable, WRONG_PATTERN_CLEAR_TIMEOUT_MS); mLockPatternView.postDelayed(mClearPatternRunnable, WRONG_PATTERN_CLEAR_TIMEOUT_MS);
} }
private void saveChosenPatternAndFinish() { private class SaveChosenPatternAndFinish extends AsyncTask<Void,Void,Void> {
if (mDone) return; boolean mLockVirgin;
LockPatternUtils utils = mChooseLockSettingsHelper.utils(); LockPatternUtils mUtils;
final boolean lockVirgin = !utils.isPatternEverChosen(UserHandle.myUserId()); boolean mWasSecureBefore;
boolean wasSecureBefore = utils.isSecure(UserHandle.myUserId()); @Override
protected void onPreExecute(){
setRightButtonEnabled(false);
mUtils = mChooseLockSettingsHelper.utils();
mLockVirgin = !mUtils.isPatternEverChosen(UserHandle.myUserId());
mWasSecureBefore = mUtils.isSecure(UserHandle.myUserId());
final boolean required = getActivity().getIntent().getBooleanExtra( final boolean required = getActivity().getIntent().getBooleanExtra(
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true); EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
utils.setCredentialRequiredToDecrypt(required); mUtils.setCredentialRequiredToDecrypt(required);
utils.saveLockPattern(mChosenPattern, mCurrentPattern, UserHandle.myUserId()); }
if (lockVirgin) { @Override
utils.setVisiblePatternEnabled(true, UserHandle.myUserId()); protected Void doInBackground(Void... params){
mUtils.saveLockPattern(mChosenPattern, mCurrentPattern, UserHandle.myUserId());
return null;
}
@Override
protected void onPostExecute(Void param) {
if (mLockVirgin) {
mUtils.setVisiblePatternEnabled(true, UserHandle.myUserId());
} }
if (mHasChallenge) { if (mHasChallenge) {
startVerifyPattern(utils, wasSecureBefore); startVerifyPattern(mUtils, mWasSecureBefore);
} else { } else {
if (!wasSecureBefore) { if (!mWasSecureBefore) {
Intent intent = getRedactionInterstitialIntent(getActivity()); Intent intent = getRedactionInterstitialIntent(getActivity());
if (intent != null) { if (intent != null) {
startActivity(intent); startActivity(intent);
@@ -653,6 +665,7 @@ public class ChooseLockPattern extends SettingsActivity {
doFinish(); doFinish();
} }
} }
}
private void startVerifyPattern(LockPatternUtils utils, final boolean wasSecureBefore) { private void startVerifyPattern(LockPatternUtils utils, final boolean wasSecureBefore) {
mLockPatternView.disableInput(); mLockPatternView.disableInput();
@@ -693,7 +706,6 @@ public class ChooseLockPattern extends SettingsActivity {
private void doFinish() { private void doFinish() {
getActivity().finish(); getActivity().finish();
mDone = true;
} }
} }
} }