发布于 2017-03-18 08:57:56 | 214 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要为大家详细介绍了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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持PHPERZ。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务