团队冲刺07
作者:互联网
添加密码、修改、删除密码的具体操作相关内容
代码:
public static void requestPassword (final Activity mActivity, final PasswordValidator mPasswordValidator) { LayoutInflater inflater = mActivity.getLayoutInflater(); final View v = inflater.inflate(R.layout.password_request_dialog_layout, null); final EditText passwordEditText = v.findViewById(R.id.password_request); MaterialDialog dialog = new MaterialDialog.Builder(mActivity) .autoDismiss(false) .title(R.string.insert_security_password) .customView(v, false) .positiveText(R.string.ok) .positiveColorRes(R.color.colorPrimary) .onPositive((dialog12, which) -> { String oldPassword = mActivity.getSharedPreferences(PREFS_NAME, MODE_MULTI_PROCESS).getString(PREF_PASSWORD, ""); String password = passwordEditText.getText().toString(); boolean result = Security.md5(password).equals(oldPassword); if (result) { KeyboardUtils.hideKeyboard(passwordEditText); dialog12.dismiss(); mPasswordValidator.onPasswordValidated(PasswordValidator.Result.SUCCEED); } else { passwordEditText.setError(mActivity.getString(R.string.wrong_password)); } }) .neutralText(mActivity.getResources().getString(R.string.password_forgot)) .onNeutral((dialog13, which) -> { PasswordHelper.resetPassword(mActivity); mPasswordValidator.onPasswordValidated(PasswordValidator.Result.RESTORE); dialog13.dismiss(); }) .build(); dialog.setOnCancelListener(dialog1 -> { KeyboardUtils.hideKeyboard(passwordEditText); dialog1.dismiss(); mPasswordValidator.onPasswordValidated(PasswordValidator.Result.FAIL); }); passwordEditText.setOnEditorActionListener((textView, actionId, keyEvent) -> { if (actionId == EditorInfo.IME_ACTION_DONE) { dialog.getActionButton(DialogAction.POSITIVE).callOnClick(); return true; } return false; }); dialog.show(); new Handler().postDelayed(() -> KeyboardUtils.showKeyboard(passwordEditText), 100); } public static void resetPassword (final Activity mActivity) { View layout = mActivity.getLayoutInflater().inflate(R.layout.password_reset_dialog_layout, null); final EditText answerEditText = layout.findViewById(R.id.reset_password_answer); MaterialDialog dialog = new MaterialDialog.Builder(mActivity) .title(OmniNotes.getSharedPreferences().getString(PREF_PASSWORD_QUESTION, "")) .customView(layout, false) .autoDismiss(false) .contentColorRes(R.color.text_color) .positiveText(R.string.ok) .onPositive((dialogElement, which) -> { String oldAnswer = OmniNotes.getSharedPreferences().getString(PREF_PASSWORD_ANSWER, ""); String answer1 = answerEditText.getText().toString(); boolean result = Security.md5(answer1).equals(oldAnswer); if (result) { dialogElement.dismiss(); removePassword(); } else { answerEditText.setError(mActivity.getString(R.string.wrong_answer)); } }).build(); dialog.show(); answerEditText.setOnEditorActionListener((textView, actionId, keyEvent) -> { if (actionId == EditorInfo.IME_ACTION_DONE) { dialog.getActionButton(DialogAction.POSITIVE).callOnClick(); return true; } return false; }); new Handler().postDelayed(() -> KeyboardUtils.showKeyboard(answerEditText), 100); } public static void removePassword () { Observable .from(DbHelper.getInstance().getNotesWithLock(true)) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .doOnNext(note -> { note.setLocked(false); DbHelper.getInstance().updateNote(note, false); }) .doOnCompleted(() -> { OmniNotes.getSharedPreferences().edit() .remove(PREF_PASSWORD) .remove(PREF_PASSWORD_QUESTION) .remove(PREF_PASSWORD_ANSWER) .remove("settings_password_access") .apply(); EventBus.getDefault().post(new PasswordRemovedEvent()); }) .subscribe(); }
标签:passwordEditText,password,false,07,冲刺,团队,dialog,layout,mActivity 来源: https://www.cnblogs.com/9d629/p/16373007.html