Android realizes Jiugongge gesture unlocking

  • 2021-09-20 21:35:50
  • OfStack

This article shares the specific code of Android9 grid gesture unlocking for your reference. The specific contents are as follows

Here is the open source library GestureLibray used

There is an introduction and access method about this thing, so it is not burdensome here. I just say that there is nothing in it.

About the use of this library:


protected void initViews() {
    // Setting Mode 
    LockMode lockMode = (LockMode) getIntent().getSerializableExtra(Config.INTENT_SECONDACTIVITY_KEY);
    // Whether to display the direction arrow of gesture 
    lv_lock.setShow(false);
    // Number of Entry Errors Allowed 
    lv_lock.setErrorNumber(Config.GESTURE_ERROR_COUNT);
    // Set the minimum length of gesture password 
    lv_lock.setPasswordMinLength(Config.GESTURE_LENGTH);
    // Save the password locally as soon as it is set 
    lv_lock.setSavePin(true);
    // Set the key of the gesture password saved locally 
    lv_lock.setSaveLockKey(Config.ZHCS_GESTURE_PWD_KEY);
    // Set password :LockMode.SETTING_PASSWORD
    // Change password :LockMode.EDIT_PASSWORD
    // Verify password :LockMode.VERIFY_PASSWORD
    // Clear password :LockMode.CLEAR_PASSWORD
    switch (lockMode)
    {
      case CLEAR_PASSWORD:
        lable = " Clear password ";
        break;
      case EDIT_PASSWORD:
        lable = " Change password ";
        setOldPassword();
        break;
      case SETTING_PASSWORD:
        lable = " Set password ";
        break;
      case VERIFY_PASSWORD:
        lable = " Verify password ";
        // Set the old password 
        setOldPassword();
        break;
    }
    lv_lock.setMode(lockMode);
    // Setting password input interface callback 
    lv_lock.setOnCompleteListener(onCompleteListener);
  }
 
  /**
   * s Set the old password 
   */
  private void setOldPassword() {
    String oldPwd = ConfigUtil.getInstance(this).getString(Config.ZHCS_GESTURE_PWD_KEY);
    lv_lock.setOldPassword(oldPwd);
  }
 
  CustomLockView.OnCompleteListener onCompleteListener = new CustomLockView.OnCompleteListener() {
    @Override
    public void onComplete(String password, int[] indexs) {
      ToastUtil.showShortToast(lable+" Success ");
      //finish();
    }
    @Override
    public void onError(String errorTimes) {
      ToastUtil.showShortToast(" Wrong password, you can also enter " + errorTimes + " Times ");
    }
    @Override
    public void onPasswordIsShort(int passwordMinLength) {
      ToastUtil.showShortToast(" Password cannot be less than " + passwordMinLength + " Point ");
    }
    @Override
    public void onAginInputPassword(LockMode mode, String password, int[] indexs) {
      ToastUtil.showShortToast(" Please enter your password again ");
    }
    @Override
    public void onInputNewPassword() {
      ToastUtil.showShortToast(" Please enter a new password ");
    }
    @Override
    public void onEnteredPasswordsDiffer() {
      ToastUtil.showShortToast(" The password entered twice does not 1 To ");
    }
    @Override
    public void onErrorNumberMany() {
      ToastUtil.showShortToast(" The number of password errors exceeds the limit and cannot be entered again ");
    }
  };

It is worth noting that the old password is needed when verifying the gesture password and modifying the gesture password, but this old password is found to be empty in the breakpoint source code, and it is not actively obtained. We need to set it manually, that is, we use the class ConfigUtil.


Related articles: