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();
      }
  • 相关阅读:
    [hdu5400 Arithmetic Sequence]预处理,容斥
    [hdu5399 Too Simple]YY
    [hdu5396 Expression]区间DP
    [hdu5392 Infoplane in Tina Town]置换的最小循环长度,最小公倍数取模,输入挂
    [bzoj2038 [2009国家集训队]小Z的袜子(hose)] 莫队算法
    [hdu1506 Largest Rectangle in a Histogram]笛卡尔树
    hdu5381 The sum of gcd]莫队算法
    [hdu5389 Zero Escape]数根的性质,DP
    [hdu5387 Clock]时钟夹角问题
    [CodeForces 300D Painting Square]DP
  • 原文地址:https://www.cnblogs.com/xjmm/p/13060770.html
Copyright © 2011-2022 走看看