@Override
    public boolean onPreferenceChange(Preference preference, Object value) {

      if (preference.getKey().equals("lock_pattern_on")) {
        SwitchPreference service = (SwitchPreference) preference;
        service.setChecked((Boolean) value);

        // 由未开启状态转为开启状态
        if ((Boolean) value) {
          // 默认没有创建成功,手势密码不存在
          PreferenceManager.getDefaultSharedPreferences(this.getActivity().getApplicationContext())
              .edit()
              .putBoolean("lock_pattern_on", false)
              .commit();

          this.getFragmentManager()
              .beginTransaction()
              .replace(R.id.settings_container, new CreatePasswordFragment())
              .commit();

        } else {
          // 默认没有取消成功,手势密码依旧存在
          PreferenceManager.getDefaultSharedPreferences(this.getActivity().getApplicationContext())
              .edit()
              .putBoolean("lock_pattern_on", true)
              .commit();

          // 取消手势密码,要先验证
          LockPatternActivity.IntentBuilder.newPatternComparator(
                  getActivity().getApplicationContext())
              .startForResult(this, REQ_ENTER_PATTERN);
        }
      }

      return true;
    }
 // 正式开启第三方的dialog
 public void startCreateDialog() {
   LockPatternActivity.IntentBuilder.newPatternCreator(getActivity().getApplicationContext())
       .startForResult(this, REQ_CREATE_PATTERN);
 }