Android手势密码解锁 Android仿支付宝手势密码解锁功能
人气:0想了解Android仿支付宝手势密码解锁功能的相关内容吗,在本文为您仔细讲解Android手势密码解锁的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android手势密码解锁,Android仿支付宝手势密码,Android支付宝手势密码解锁,Android仿支付宝手势解锁,下面大家一起来学习吧。
Starting
创建手势密码可以查看 CreateGestureActivity.java 文件.
登陆验证手势密码可以看 GestureLoginActivity.java 文件.
Features
使用了 JakeWharton/butterknife butterknife
使用了 ACache 来存储手势密码
/** * 保存手势密码 */ private void saveChosenPattern(List<LockPatternView.Cell> cells) { byte[] bytes = LockPatternUtil.patternToHash(cells); aCache.put(Constant.GESTURE_PASSWORD, bytes); }
Warning: 使用 ACache 类保存密码并不是无限期的. 具体期限可以查看 ACache 类.
使用了 SHA 算法保存手势密码
/** * Generate an SHA-1 hash for the pattern. * Not the most secure, but it is at * least a second level of protection. First level is that the file is in a * location only readable by the system process.* * @param pattern * @return the hash of the pattern in a byte array. */ public static byte[] patternToHash(List<LockPatternView.Cell> pattern) { if (pattern == null) { return null; } else { int size = pattern.size(); byte[] res = new byte[size]; for (int i = 0; i < size; i++) { LockPatternView.Cell cell = pattern.get(i); res[i] = (byte) cell.getIndex(); } MessageDigest md = null; try { md = MessageDigest.getInstance("SHA-1"); return md.digest(res); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return res; } } }
可以开启震动模式,当选中一个圈的时候,手机会震动
/** * Set whether the view will use tactile feedback. *If true, there will be * tactile feedback as the user enters the pattern. * @param tactileFeedbackEnabled Whether tactile feedback is enabled */ public void setTactileFeedbackEnabled(boolean tactileFeedbackEnabled) { mEnableHapticFeedback = tactileFeedbackEnabled; }
可以开启绘制路径隐藏模式
/** * Set whether the view is in stealth mode. If true, there will be no * visible feedback as the user enters the pattern. * @param inStealthMode Whether in stealth mode. */public void setInStealthMode(boolean inStealthMode) { mInStealthMode = inStealthMode; }
Example
加载全部内容