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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Android控件之AnalogClock与DigitalClock用法实例分析
这篇文章主要介绍了Android控件之AnalogClock与DigitalClock用法,以实例形式分析了Android时钟控件AnalogClock和DigitalClock用于显示时间的具体使用技巧,需要的朋友可以参考下2015-09-09
Android使用setCustomTitle()方法自定义对话框标题
Android有自带的对话框标题,但是不太美观,如果要给弹出的对话框设置一个自定义的标题,使用AlertDialog.Builder的setCustomTitle()方法非常方便,接下来通过本文给大家介绍Android使用setCustomTitle()方法自定义对话框标题,感兴趣的朋友一起学习吧2016-02-02
Android基于ListView实现类似Market分页加载效果示例
这篇文章主要介绍了Android基于ListView实现类似Market分页加载效果,结合完整实例形式分析了ListView的OnScroll方法来实现分页与滚动加载的操作步骤与相关实现技巧,需要的朋友可以参考下2016-10-10


最新评论