1 private void setGesturePassword() { 2 toggleMore.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 3 @Override 4 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 5 if (isChecked) { 6 // UIUtils.toast("开启了手势密码", false); 7 // sp.edit().putBoolean("isOpen", true).commit(); 8 String inputCode = sp.getString("inputCode", ""); 9 if (TextUtils.isEmpty(inputCode)) {//之前没有设置过10 new AlertDialog.Builder(MoreFragment.this.getActivity())11 .setTitle("设置手势密码")12 .setMessage("是否现在设置手势密码")13 .setPositiveButton("确定", new DialogInterface.OnClickListener() {14 @Override15 public void onClick(DialogInterface dialog, int which) {16 UIUtils.toast("现在设置手势密码", false);17 sp.edit().putBoolean("isOpen", true).commit();18 // toggleMore.setChecked(true);19 //开启新的activity:20 ((BaseActivity) MoreFragment.this.getActivity()).goToActivity(GestureEditActivity.class, null);21 }22 })23 .setNegativeButton("取消", new DialogInterface.OnClickListener() {24 @Override25 public void onClick(DialogInterface dialog, int which) {26 UIUtils.toast("取消了现在设置手势密码", false);27 sp.edit().putBoolean("isOpen", false).commit();28 toggleMore.setChecked(false);29 30 }31 })32 .show();33 } else {34 UIUtils.toast("开启手势密码", false);35 sp.edit().putBoolean("isOpen", true).commit();36 // toggleMore.setChecked(true);37 }38 } else {39 UIUtils.toast("关闭了手势密码", false);40 sp.edit().putBoolean("isOpen", false).commit();41 // toggleMore.setChecked(false);42 43 }44 }45 });46 }47 48 private void resetGesture() {49 tvMoreReset.setOnClickListener(new View.OnClickListener() {50 @Override51 public void onClick(View v) {52 boolean checked = toggleMore.isChecked();53 if (checked) {54 ((BaseActivity) MoreFragment.this.getActivity()).goToActivity(GestureEditActivity.class, null);55 } else {56 UIUtils.toast("手势密码操作已关闭,请开启后再设置", false);57 }58 }59 });60 }
GestureEditActivity:
View Code
我的界面中:
//判断一下,是否开启了手势密码。如果开启:先输入手势密码
SharedPreferences sp = this.getActivity().getSharedPreferences("secret_protect", Context.MODE_PRIVATE);
boolean isOpen = sp.getBoolean("isOpen", false);if(isOpen){
((BaseActivity)this.getActivity()).goToActivity(GestureVerifyActivity.class,null);
return;
}
GestureVerifyActivity:
View Code
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Android频道!