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:
@@ -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() {
|
||||||
|
mWasSecureBefore = mLockPatternUtils.isSecure(UserHandle.myUserId());
|
||||||
|
final boolean required = getActivity().getIntent().getBooleanExtra(
|
||||||
|
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
|
||||||
|
mLockPatternUtils.setCredentialRequiredToDecrypt(required);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doInBackground(Void... v) {
|
||||||
|
mLockPatternUtils.saveLockPassword(mChosenPassword, mCurrentPassword, mRequestedQuality,
|
||||||
|
UserHandle.myUserId());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPostExecute(Void v) {
|
||||||
|
if (mHasChallenge) {
|
||||||
|
startVerifyPassword(mChosenPassword, mWasSecureBefore);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
getActivity().setResult(RESULT_FINISHED);
|
||||||
|
}
|
||||||
|
finishConfirmStage(mWasSecureBefore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void handleNext() {
|
||||||
|
mChosenPassword = mPasswordEntry.getText().toString();
|
||||||
|
if (TextUtils.isEmpty(mChosenPassword)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String errorMsg = null;
|
String errorMsg = null;
|
||||||
if (mUiStage == Stage.Introduction) {
|
if (mUiStage == Stage.Introduction) {
|
||||||
errorMsg = validatePassword(pin);
|
errorMsg = validatePassword(mChosenPassword);
|
||||||
if (errorMsg == null) {
|
if (errorMsg == null) {
|
||||||
mFirstPin = pin;
|
mFirstPin = mChosenPassword;
|
||||||
mPasswordEntry.setText("");
|
mPasswordEntry.setText("");
|
||||||
updateStage(Stage.NeedToConfirm);
|
updateStage(Stage.NeedToConfirm);
|
||||||
}
|
}
|
||||||
} else if (mUiStage == Stage.NeedToConfirm) {
|
} else if (mUiStage == Stage.NeedToConfirm) {
|
||||||
if (mFirstPin.equals(pin)) {
|
if (mFirstPin.equals(mChosenPassword)) {
|
||||||
boolean wasSecureBefore = mLockPatternUtils.isSecure(UserHandle.myUserId());
|
setNextEnabled(false);
|
||||||
final boolean required = getActivity().getIntent().getBooleanExtra(
|
new SaveChosenPasswordAndFinish().execute();
|
||||||
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
|
|
||||||
mLockPatternUtils.setCredentialRequiredToDecrypt(required);
|
|
||||||
mLockPatternUtils.saveLockPassword(pin, mCurrentPassword, mRequestedQuality,
|
|
||||||
UserHandle.myUserId());
|
|
||||||
|
|
||||||
if (mHasChallenge) {
|
|
||||||
startVerifyPassword(pin, wasSecureBefore);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
getActivity().setResult(RESULT_FINISHED);
|
|
||||||
}
|
|
||||||
finishConfirmStage(wasSecureBefore);
|
|
||||||
} 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) {
|
||||||
|
@@ -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,34 +621,49 @@ 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());
|
||||||
|
|
||||||
final boolean required = getActivity().getIntent().getBooleanExtra(
|
mWasSecureBefore = mUtils.isSecure(UserHandle.myUserId());
|
||||||
|
|
||||||
|
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) {
|
|
||||||
utils.setVisiblePatternEnabled(true, UserHandle.myUserId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHasChallenge) {
|
@Override
|
||||||
startVerifyPattern(utils, wasSecureBefore);
|
protected Void doInBackground(Void... params){
|
||||||
} else {
|
mUtils.saveLockPattern(mChosenPattern, mCurrentPattern, UserHandle.myUserId());
|
||||||
if (!wasSecureBefore) {
|
return null;
|
||||||
Intent intent = getRedactionInterstitialIntent(getActivity());
|
}
|
||||||
if (intent != null) {
|
|
||||||
startActivity(intent);
|
@Override
|
||||||
}
|
protected void onPostExecute(Void param) {
|
||||||
|
if (mLockVirgin) {
|
||||||
|
mUtils.setVisiblePatternEnabled(true, UserHandle.myUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mHasChallenge) {
|
||||||
|
startVerifyPattern(mUtils, mWasSecureBefore);
|
||||||
|
} else {
|
||||||
|
if (!mWasSecureBefore) {
|
||||||
|
Intent intent = getRedactionInterstitialIntent(getActivity());
|
||||||
|
if (intent != null) {
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getActivity().setResult(RESULT_FINISHED);
|
||||||
|
doFinish();
|
||||||
}
|
}
|
||||||
getActivity().setResult(RESULT_FINISHED);
|
|
||||||
doFinish();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -693,7 +706,6 @@ public class ChooseLockPattern extends SettingsActivity {
|
|||||||
|
|
||||||
private void doFinish() {
|
private void doFinish() {
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
mDone = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user