Android source code download: My Gesture Lock

Android source code download: My Gesture Lock

Functional classification: Tools

Supported platforms: Android

Operating environment: Eclipse

Development language: Java

Development tool: Eclipse

Source code size: 1.06MB

Source code download: http://download..com/data/1976924

Source code introduction

My gesture lock makes it easy for users to log in. When logging in for the first time, enter your username and password and set a gesture password. When logging in again, you only need to enter the correct gesture password to log in successfully.

Source code running screenshot

Login screen

Tips to create a gesture password

Demonstrate the creation of gesture password

Create a gesture password

Gesture password unlock

Source code snippet

  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. * Unlock login
  33. *com.zhangyx.MyGestureLock.gesture.UnlockGesturePasswordActivity
  34. * @author Admin-zhangyx
  35. *
  36. * created at 2015-1-16 3:09:47 PM
  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; // Switch user, clear gesture lock  
  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. // Clear gesture file  
  72. app.getLockPatternUtils().clearLock();
  73. toLoginActivity();
  74. }
  75. });
  76. }
  77.   
  78. @Override  
  79. protected   void onResume() {
  80. super .onResume();
  81. // If the gesture has never been created, start creating it --- no password is remembered  
  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)) { // Unlock successfully  
  122. mLockPatternView
  123. .setDisplayMode(LockPatternView.DisplayMode.Correct);
  124.   
  125. // Unlock successfully and return to the page that requires user information----  
  126. loginSuccessToMainAcrtivity();
  127. } else { // Unlock failed-----Log in again  
  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( "Wrong password, you can enter it again" + retry + "times" );
  142. mHeadTextView.setTextColor(Color.RED);
  143. mHeadTextView.startAnimation(mShakeAnim);
  144. } else {
  145. // Open a new Activity  
  146. // Clear gesture file  
  147. app.getLockPatternUtils().clearLock();
  148. toLoginActivity();
  149. }
  150. } else {
  151. showToast( "The input length is not enough, please try again" );
  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 + 1 , 1000 ) {
  183.   
  184. @Override  
  185. public   void onTick( long millisUntilFinished) {
  186. int secondsRemaining = ( int ) (millisUntilFinished / 1000 ) - 1 ;
  187. if (secondsRemaining > 0 ) {
  188. mHeadTextView.setText(secondsRemaining + "Retry after seconds" );
  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. // Login successful  
  208. private   void loginSuccessToMainAcrtivity() {
  209. startActivity( new Intent(UnlockGesturePasswordActivity. this ,
  210. MainActivity. class ));
  211. AnimationUtil
  212. .finishActivityAnimation(UnlockGesturePasswordActivity. this );
  213. }
  214.   
  215. }
  216. </cell></cell>

Source code download: http://download..com/data/1976924

<<:  Android source code download: QQ third-party login demo

>>:  iOS source code download: scroll view of text + pictures

Recommend

How to activate ringback tone for 400 phone?

Although 400 telephones are widely used, there ar...

Overview of open source software update tools based on the Omaha protocol

[[134368]] Once a piece of software is installed ...

How many books have you read?

© Book Riot Leviathan Press: In 2006, a study on ...

Get the App information you want through PackageManager!

[[207610]] 1. Introduction Let's get straight...

Is it okay to lie down all the time during the holidays? Not necessarily

Produced by: Science Popularization China Produce...

Although cloud disks have fallen, mobile cloud storage is still the trend

On March 2, 2016, the National Office for Combatin...

Methodology in the Internet Age: Where is the trend?

Many people say that we should stand on the wind,...

Poor traffic conversion recently? Share 8 high conversion techniques!

If you were asked to choose between the following...