zoukankan      html  css  js  c++  java
  • 第二阶段冲刺02

    添加密码、修改、删除密码的具体操作相关内容

    代码:

     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();
      }
  • 相关阅读:
    解决PKIX:unable to find valid certification path to requested target 的问题
    Linux 上的常用文件传输方式介绍与比较
    用VNC远程图形化连接Linux桌面的配置方法
    红帽中出现”This system is not registered with RHN”的解决方案
    linux安装时出现your cpu does not support long mode的解决方法
    CentOS SSH配置
    es6扩展运算符及rest运算符总结
    es6解构赋值总结
    tortoisegit安装、clon、推送
    es6环境搭建
  • 原文地址:https://www.cnblogs.com/xjmm/p/13060770.html
Copyright © 2011-2022 走看看