Android源码下载:我的手势锁

移动开发 Android
我的手势锁方便用户的登录,第一次登入时候输入用户名和密码,设置手势密码;再次登录时,只需要手势密码正确,即可登录成功。

功能分类:工具

支持平台:Android

运行环境:Eclipse

开发语言:Java

开发工具:Eclipse

源码大小:1.06MB

源码下载:http://down.51cto.com/data/1976924

源码简介

我的手势锁方便用户的登录,第一次登入时候输入用户名和密码,设置手势密码;再次登录时,只需要手势密码正确,即可登录成功。

源码运行截图

登录界面

提示创建手势密码

演示创建手势密码

创建手势密码

手势密码解锁

源码片段

  1. package com.zhangyx.MyGestureLock.gesture; 
  2.   
  3. import java.util.List; 
  4.   
  5. import com.lidroid.xutils.ViewUtils; 
  6. import com.lidroid.xutils.view.annotation.ViewInject; 
  7. import com.zhangyx.MyGestureLock.BaseActivity; 
  8. import com.zhangyx.MyGestureLock.LoginActivity; 
  9. import com.zhangyx.MyGestureLock.MainActivity; 
  10. import com.zhangyx.MyGestureLock.R; 
  11. import com.zhangyx.MyGestureLock.app.MyApplication; 
  12. import com.zhangyx.MyGestureLock.util.AnimationUtil; 
  13. import com.zhangyx.MyGestureLock.view.LockPatternUtils; 
  14. import com.zhangyx.MyGestureLock.view.LockPatternView; 
  15. import com.zhangyx.MyGestureLock.view.LockPatternView.Cell; 
  16.   
  17.   
  18. import android.annotation.SuppressLint; 
  19. import android.content.Intent; 
  20. import android.graphics.Color; 
  21. import android.os.Bundle; 
  22. import android.os.CountDownTimer; 
  23. import android.view.View; 
  24. import android.view.View.OnClickListener; 
  25. import android.view.animation.Animation; 
  26. import android.view.animation.AnimationUtils; 
  27. import android.widget.Button; 
  28. import android.widget.LinearLayout; 
  29. import android.widget.TextView; 
  30.   
  31. /*** 
  32.  * 解锁登录 
  33.  *com.zhangyx.MyGestureLock.gesture.UnlockGesturePasswordActivity 
  34.  * @author Admin-zhangyx 
  35.  * 
  36.  * create at 2015-1-16 下午3:09:47 
  37.  */ 
  38. @SuppressLint("ResourceAsColor"
  39. public class UnlockGesturePasswordActivity extends BaseActivity { 
  40.     private LockPatternView mLockPatternView; 
  41.     private int mFailedPatternAttemptsSinceLastTimeout = 0
  42.     private CountDownTimer mCountdownTimer = null
  43.     // private Handler mHandler = new Handler(); 
  44.   
  45.     private Animation mShakeAnim; 
  46.   
  47.     @ViewInject(R.id.gesturepwd_unlock_text) 
  48.     private TextView mHeadTextView; 
  49.     @ViewInject(R.id.rootView) 
  50.     private LinearLayout rootView; 
  51.     @ViewInject(R.id.changeUser) 
  52.     private Button changeUser;// 切换用户、清除手势锁 
  53.   
  54.     private MyApplication app; 
  55.     @Override 
  56.     public void onCreate(Bundle savedInstanceState) { 
  57.         super.onCreate(savedInstanceState); 
  58.         setContentView(R.layout.gesturepassword_unlock); 
  59.         ViewUtils.inject(this); 
  60.         app=(MyApplication) getApplication(); 
  61.         mLockPatternView = (LockPatternView) findViewById(R.id.gesturepwd_unlock_lockview); 
  62.         mLockPatternView.setOnPatternListener(mChooseNewLockPatternListener); 
  63.         mLockPatternView.setTactileFeedbackEnabled(true); 
  64.         mShakeAnim = AnimationUtils.loadAnimation(this, R.anim.shake_x); 
  65.   
  66.         changeUser.setOnClickListener(new OnClickListener() { 
  67.   
  68.             @Override 
  69.             public void onClick(View v) { 
  70.                 // TODO Auto-generated method stub 
  71.                 // 清除 手势文件 
  72.                 app.getLockPatternUtils().clearLock(); 
  73.                 toLoginActivity(); 
  74.             } 
  75.         }); 
  76.     } 
  77.   
  78.     @Override 
  79.     protected void onResume() { 
  80.         super.onResume(); 
  81.         // 从未创建过手势时,开始创建---没有记住密码 
  82.         if (!app.getLockPatternUtils().savedPatternExists()) { 
  83.             toLoginActivity(); 
  84.         } 
  85.     } 
  86.   
  87.     private void toLoginActivity() { 
  88.         startActivity(new Intent(UnlockGesturePasswordActivity.this
  89.                 LoginActivity.class)); 
  90.         AnimationUtil 
  91.                 .finishActivityAnimation(UnlockGesturePasswordActivity.this); 
  92.     } 
  93.   
  94.     @Override 
  95.     protected void onDestroy() { 
  96.         super.onDestroy(); 
  97.         if (mCountdownTimer != null
  98.             mCountdownTimer.cancel(); 
  99.     } 
  100.   
  101.     private Runnable mClearPatternRunnable = new Runnable() { 
  102.         public void run() { 
  103.             mLockPatternView.clearPattern(); 
  104.         } 
  105.     }; 
  106.   
  107.     protected LockPatternView.OnPatternListener mChooseNewLockPatternListener = new LockPatternView.OnPatternListener() { 
  108.   
  109.         @Override 
  110.         public void onPatternStart() { 
  111.             // TODO Auto-generated method stub 
  112.             mLockPatternView.removeCallbacks(mClearPatternRunnable); 
  113.             patternInProgress(); 
  114.         } 
  115.   
  116.         public void onPatternDetected(List<cell> pattern) { 
  117.             // TODO Auto-generated method stub 
  118.             if (pattern == null
  119.                 return
  120.             if (app.getLockPatternUtils() 
  121.                     .checkPattern(pattern)) {// 解锁成功 
  122.                 mLockPatternView 
  123.                         .setDisplayMode(LockPatternView.DisplayMode.Correct); 
  124.   
  125.                 // 解锁成功返回需要用户信息的页面---- 
  126.                 loginSuccessToMainAcrtivity() ; 
  127.             } else {// 解锁失败-----重新登录 
  128.                 mLockPatternView 
  129.                         .setDisplayMode(LockPatternView.DisplayMode.Wrong); 
  130.   
  131.                 if (pattern.size() >= LockPatternUtils.MIN_PATTERN_REGISTER_FAIL) { 
  132.   
  133.                     mFailedPatternAttemptsSinceLastTimeout++; 
  134.                     int retry = LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT 
  135.                             - mFailedPatternAttemptsSinceLastTimeout; 
  136.                     if (retry > 0) { 
  137.                         changeUser.setVisibility(View.VISIBLE); 
  138.                         if (retry == 0
  139.                             showToast(UnlockGesturePasswordActivity.this 
  140.                                     .getString(R.string.toastlock)); 
  141.                         mHeadTextView.setText("密码错误,还可以再输入" + retry + "次"); 
  142.                         mHeadTextView.setTextColor(Color.RED); 
  143.                         mHeadTextView.startAnimation(mShakeAnim); 
  144.                     } else { 
  145.                         // 打开新的Activity 
  146.                         // 清除 手势文件 
  147.                         app.getLockPatternUtils().clearLock(); 
  148.                         toLoginActivity(); 
  149.                     } 
  150.                 } else { 
  151.                     showToast("输入长度不够,请重试"); 
  152.                 } 
  153.                 mLockPatternView.clearPattern(); 
  154.             } 
  155.         } 
  156.   
  157.         @Override 
  158.         public void onPatternCleared() { 
  159.             // TODO Auto-generated method stub 
  160.             mLockPatternView.removeCallbacks(mClearPatternRunnable); 
  161.         } 
  162.   
  163.         private void patternInProgress() { 
  164.         } 
  165.   
  166.         @Override 
  167.         public void onPatternCellAdded(List<cell> pattern) { 
  168.             // TODO Auto-generated method stub 
  169.   
  170.         } 
  171.   
  172.           
  173.     }; 
  174.   
  175.     Runnable attemptLockout = new Runnable() { 
  176.   
  177.         @Override 
  178.         public void run() { 
  179.             mLockPatternView.clearPattern(); 
  180.             mLockPatternView.setEnabled(false); 
  181.             mCountdownTimer = new CountDownTimer( 
  182.                     LockPatternUtils.FAILED_ATTEMPT_TIMEOUT_MS + 11000) { 
  183.   
  184.                 @Override 
  185.                 public void onTick(long millisUntilFinished) { 
  186.                     int secondsRemaining = (int) (millisUntilFinished / 1000) - 1
  187.                     if (secondsRemaining > 0) { 
  188.                         mHeadTextView.setText(secondsRemaining + " 秒后重试"); 
  189.                     } else { 
  190.                         mHeadTextView 
  191.                                 .setText(UnlockGesturePasswordActivity.this 
  192.                                         .getString(R.string.gesture_drawPwd)); 
  193.                         mHeadTextView.setTextColor(Color.WHITE); 
  194.                     } 
  195.   
  196.                 } 
  197.   
  198.                 @Override 
  199.                 public void onFinish() { 
  200.                     mLockPatternView.setEnabled(true); 
  201.                     mFailedPatternAttemptsSinceLastTimeout = 0
  202.                 } 
  203.             }.start(); 
  204.         } 
  205.     }; 
  206.       
  207.     // 登录成功 
  208.     private void loginSuccessToMainAcrtivity() { 
  209.         startActivity(new Intent(UnlockGesturePasswordActivity.this
  210.                 MainActivity.class)); 
  211.         AnimationUtil 
  212.                 .finishActivityAnimation(UnlockGesturePasswordActivity.this); 
  213.     } 
  214.   
  215. </cell></cell> 

源码下载:http://down.51cto.com/data/1976924

责任编辑:闫佳明 来源: 网络整理
相关推荐

2013-08-06 15:13:57

Android 4.3源码

2015-02-27 15:46:09

Android源码桌面APP

2015-01-15 16:25:23

Android源码Socket通信

2015-01-21 15:28:16

Android源码新浪微博

2015-02-27 16:36:21

Android源码屏幕画笔Demo

2015-01-22 14:12:40

Android源码APP启动引导

2013-05-14 11:18:24

AIR AndroidSwipe手势

2013-05-14 11:16:26

AIR Android旋转手势

2015-01-22 15:44:55

Android源码音乐播放器

2015-01-14 14:22:30

Android源码游戏

2010-11-01 09:46:21

ViewAndroid

2021-10-19 08:33:10

Android手势检测

2015-02-27 16:03:26

Android源码Bluetooth_4BLE蓝牙通信

2015-01-21 16:07:57

Android源码验证码倒计时

2013-05-28 10:39:44

Android开发移动开发

2021-02-20 06:09:46

libtask协程锁机制

2013-05-14 11:13:02

AIR Android放大缩小手势

2010-01-28 14:57:36

Android滑动手势

2021-07-06 08:37:29

Redisson分布式

2014-12-17 15:23:03

Android网络阅读器源码
点赞
收藏

51CTO技术栈公众号