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

The North American Auto Show released a preview of the new generation Lexus LS

Recently, Lexus officially released a preview ima...

The marketing logic followed by Apple and Huawei (focus on 3 key points)

The topic I will share today is "Cognitive M...

Three major trends in new media operations in 2017

On November 16, 2017, Penguin Think Tank and Tenc...

Another national treasure! China's first space telescope - CSST is here

Not long ago, at around 22:30 on July 12, 2022, B...

Are there really no penguins in the Northern Hemisphere?

Penguins, small animals that walk in a wobbly man...

The next wave of entertainment: Changhong naked-eye 3D TV mobile phone

With the development of mobile Internet and the c...

How much does Cordyceps sinensis cost per gram?

How much does Cordyceps sinensis cost per gram? T...

iOS grabs HTML, CSS XPath parses data

In the past, we used AFN to get JSON data. For ex...