English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Final Version of Android Custom UI Gesture Password

I have written before3This is a demo of gesture password, but it is not integrated into a real enterprise project. These days, I just received a gesture password project. Yesterday, I just finished it, and today I took some time to organize it. It is not yet perfect, and there are some places that need to be changed. However, the basic process can run smoothly.

Source code download address:http://download.jb51.net/201610/source code/AndroidGestureLock(jb51.net.rar

First look at the entry on the main interface, where there is2There are two buttons (one for setting the gesture password and one for verifying the gesture password)
activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android 
 xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 tools:context="com.example.gesturelock.MainActivity" > 
 <Button 
 android:id="@"+id/setting" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:layout_alignParentLeft="true" 
 android:layout_alignParentTop="true" 
 android:text="设置" /> 
 <Button 
 android:id="@"+id/verify" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:layout_alignParentTop="true" 
 android:layout_toRightOf="@"+id/setting" 
 android:text="校验" /> 
</RelativeLayout> 

Look at the code on the main interface.
MainActivity

package com.example.gesturelock; 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
public class MainActivity extends Activity implements OnClickListener { 
 private Button setting, verify; 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.activity_main); 
 setting = (Button) findViewById(R.id.setting); 
 verify = (Button) findViewById(R.id.verify); 
 setting.setOnClickListener(this); 
 verify.setOnClickListener(this); 
 } 
 @Override 
 public void onClick(View v) { 
 switch (v.getId()) { 
 case R.id.setting: 
  startActivity(new Intent(this, GestureEditActivity.class)); 
  break; 
 case R.id.verify: 
  startActivity(new Intent(this, GestureVerifyActivity.class)); 
  break; 
 default: 
  break; 
 } 
 } 
} 

Thought for a while and decided to post the database first.---This is the storage for the gesture password and the number of times the gesture password can still be entered.
publicSQLiteOpenHelper

package com.example.gesturelock; 
import android.content.ContentValues; 
import android.content.Context; 
import android.database.Cursor; 
import android.database.SQLException; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 
public class publicSQLiteOpenHelper extends SQLiteOpenHelper{ 
 private static String name = "publicsqlite"; 
 private static String GESTURE_PASSWORD = "gesture_password"; 
 private static final int version = 1; 
 public SQLiteDatabase db; 
 public publicSQLiteOpenHelper(Context context) 
 { 
  super(context, name, null, version); 
 } 
 @Override 
 public void onCreate(SQLiteDatabase db) 
 { 
  String sqlpass = "create table " + "gesture_password"+ "(" 
   + GesturePassword.WXID + " text not null," 
   + GesturePassword.PASSWORD + " text not null," 
   + GesturePassword.REMAINOPPORTUNITY + " text not null)"; 
  db.execSQL(sqlpass); 
 } 
 @Override 
 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
 { 
  db.execSQL("DROP TABLE IF EXISTS password"); 
  onCreate(db); 
 } 
 public class GesturePassword 
 { 
  public static final String WXID = "wxid"; 
  public static final String PASSWORD = "password"; 
  public static final String REMAINOPPORTUNITY = "remainopportunity"; 
 } 
 /** 
  * Insert into the gesture password table 
  */ 
 public void insertGestureInfo(SQLiteDatabase database ,String password,String times){ 
  ContentValues values = null; 
  try { 
  values = new ContentValues(); 
  values.put(GesturePassword.WXID, "001"); 
  values.put(GesturePassword.PASSWORD, password); 
  values.put(GesturePassword.REMAINOPPORTUNITY, ""+times); 
  database.insert(publicSQLiteOpenHelper.GESTURE_PASSWORD, null, 
   values); 
  } 
  e.printStackTrace(); 
  throw new SQLException(e.getMessage()); 
  } 
  if (values != null) { 
   values.clear(); 
   values = null; 
  } 
  } 
 } 
 /** 
  * Modify the gesture password table---Initialize the number of times to8times 
  * 
  * 
  */ 
  public void updateGestureInfo(SQLiteDatabase database,String password,String times) { 
  ContentValues values = null; 
  try { 
   if (password == null) { 
   values = new ContentValues(); 
   values.put(GesturePassword.WXID, "001"); 
   values.put(GesturePassword.REMAINOPPORTUNITY, ""+times); 
   database.update(publicSQLiteOpenHelper.GESTURE_PASSWORD, 
    values, "WXID=?", 
    new String[] { "001" }); 
   } 
   values = new ContentValues(); 
   values.put(GesturePassword.WXID, "001"); 
   values.put(GesturePassword.PASSWORD, password); 
   values.put(GesturePassword.REMAINOPPORTUNITY, ""+times); 
   database.update(publicSQLiteOpenHelper.GESTURE_PASSWORD, 
    values, "WXID=?", 
    new String[] { "001" }); 
   } 
  } 
  } 
   if (values != null) { 
   values.clear(); 
   values = null; 
   } 
  } 
  } 
  /** 
  * Inquire if there are any records in the gesture password table 
  * @return 
  */ 
  public boolean queryGestureTableCount(SQLiteDatabase database){ 
  Cursor cursor = null; 
  try { 
   cursor = database.query(publicSQLiteOpenHelper.GESTURE_PASSWORD, null, null, null, null, null, null); 
   if (cursor != null && cursor.getCount()>0) { 
   return true; 
   } 
   return false; 
   } 
  } 
  } 
  finally{ 
   if (cursor != null) { 
   cursor.close(); 
   cursor = null; 
   } 
  } 
  return false; 
  } 
  /** 
  * Query gesture password table--View remaining times 
  * 
  */ 
  public String queryGestureTime(SQLiteDatabase database) { 
  Cursor cursor = null; 
  try { 
   cursor = database.query(publicSQLiteOpenHelper.GESTURE_PASSWORD, null, null, null, null, null, null); 
   if ((cursor != null) && (cursor.getCount() > 0)) { 
   if (cursor.moveToFirst()) { 
    int columnIndex = cursor 
     .getColumnIndex(GesturePassword.REMAINOPPORTUNITY); 
    return cursor.getString(columnIndex); 
   } 
   } 
  } 
  } 
   if (cursor != null) { 
   cursor.close(); 
   cursor = null; 
   } 
  } 
  return ""; 
  } 
  /** 
  * Query gesture password table--View password 
  * 
  */ 
  public String queryGesturePassword(SQLiteDatabase database) { 
  Cursor cursor = null; 
  try { 
   cursor = database.query(publicSQLiteOpenHelper.GESTURE_PASSWORD, null, null, null, null, null, null); 
   if ((cursor != null) && (cursor.getCount() > 0)) { 
   if (cursor.moveToFirst()) { 
    int columnIndex = cursor 
     .getColumnIndex(GesturePassword.PASSWORD); 
    return cursor.getString(columnIndex); 
   } 
   } 
  } 
  } 
   if (cursor != null) { 
   cursor.close(); 
   cursor = null; 
   } 
  } 
  return ""; 
  } 
} 

Next, let's take a look at the utility class--That is the simple MD of the input gesture password5Encryption and screen size utility class

/** 
 * 
 */ 
package com.example.gesturelock; 
import android.content.Context; 
import android.view.WindowManager; 
public class AppUtil { 
 /** 
 * Obtain screen resolution65533;63; 
 * @param context 
 * @return 
 */ 
 public static int[] getScreenDispaly(Context context) { 
 WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 
 @SuppressWarnings("deprecation") 
 int width = windowManager.getDefaultDisplay().getWidth(); 
 @SuppressWarnings("deprecation") 
 int height = windowManager.getDefaultDisplay().getHeight(); 
 int result[] = { width, height }; 
 return result; 
 } 
} 
package com.example.gesturelock; 
import java.security.MessageDigest; 
import java.security.NoSuchAlgorithmException; 
import android.util.Log; 
public class MD5EncodeUtil { 
 public static String MD5Ecode(String gesture){ 
 Log.i("GYL","gesture---"+gesture.toString()); 
 byte[] toencode=gesture.toString().getBytes(); 
 Log.i("GYL","byte[]----"+toencode.toString()); 
 try{ 
  MessageDigest md5=MessageDigest.getInstance("MD5"); 
  md5.reset(); 
  md5.update(toencode); 
  return HexEncode(md5.digest()); 
 }catch(NoSuchAlgorithmException e){ 
  e.printStackTrace(); 
 } 
 return ""; 
 } 
 public static String HexEncode(byte[] toencode){ 
 StringBuilder sb=new StringBuilder(toencode.length*2); 
 for(byte b:toencode){ 
  sb.append(Integer.toHexString((b&0xf0)>>>4)); 
  sb.append(Integer.toHexString(b&0x0f));  
 } 
 return sb.toString().toUpperCase(); 
 } 
} 

Step by step, let's look at the bean class, which is the properties of each circle point
Constants

package com.example.gesturelock; 
public class Constants { 
 public static final int POINT_STATE_NORMAL = 0; // Normal state 
 public static final int POINT_STATE_SELECTED = 1; // Press state 
 public static final int POINT_STATE_WRONG = 2; // Error state 
} 

GesturePoint

package com.example.gesturelock; 
import android.widget.ImageView; 
public class GesturePoint { 
 /** 
 * Left x-value 
 */ 
 private int leftX; 
 /** 
 * Right x-value 
 */ 
 private int rightX; 
 /** 
 * Upper y-value 
 */ 
 private int topY; 
 /** 
 * Lower y-value 
 */ 
 private int bottomY; 
 /** 
 * This point corresponds to the ImageView control 
 */ 
 private ImageView image; 
 /** 
 * Central x-value 
 */ 
 private int centerX; 
 /** 
 * Central y-value 
 */ 
 private int centerY; 
 /** 
 * State value 
 */ 
 private int pointState; 
 /** 
 * represents the number represented by this Point object, from1Start (directly feeling from1Start) 
 */ 
 private int num; 
 public GesturePoint(int leftX, int rightX, int topY, int bottomY, 
  ImageView image, int num) { 
 super(); 
 this.leftX = leftX; 
 this.rightX = rightX; 
 this.topY = topY; 
 this.bottomY = bottomY; 
 this.image = image; 
 this.centerX = (leftX + rightX) / 2; 
 this.centerY = (topY + bottomY) / 2; 
 this.num = num; 
 } 
 public int getLeftX() { 
 return leftX; 
 } 
 public void setLeftX(int leftX) { 
 this.leftX = leftX; 
 } 
 public int getRightX() { 
 return rightX; 
 } 
 public void setRightX(int rightX) { 
 this.rightX = rightX; 
 } 
 public int getTopY() { 
 return topY; 
 } 
 public void setTopY(int topY) { 
 this.topY = topY; 
 } 
 public int getBottomY() { 
 return bottomY; 
 } 
 public void setBottomY(int bottomY) { 
 this.bottomY = bottomY; 
 } 
 public ImageView getImage() { 
 return image; 
 } 
 public void setImage(ImageView image) { 
 this.image = image; 
 } 
 public int getCenterX() { 
 return centerX; 
 } 
 public void setCenterX(int centerX) { 
 this.centerX = centerX; 
 } 
 public int getCenterY() { 
 return centerY; 
 } 
 public void setCenterY(int centerY) { 
 this.centerY = centerY; 
 } 
 public int getPointState() { 
 return pointState; 
 } 
 public void setPointState(int state, int x, int y) { 
 pointState = state; 
 switch (state) { 
 case Constants.POINT_STATE_NORMAL: 
  this.image.setBackgroundResource(R.drawable.gesturewhite); 
  break; 
 case Constants.POINT_STATE_SELECTED: 
  // Taking the origin as the center, the right bottom is positive and the left top is negative 
  if (y == 0 && x > 0) { 
  this.image.setBackgroundResource(R.drawable.blueright); 
  } else if (y == 0 && x < 0) { 
  this.image.setBackgroundResource(R.drawable.blueleft); 
  } else if (x == 0 && y > 0) { 
  this.image.setBackgroundResource(R.drawable.bluedown); 
  } else if (x == 0 && y < 0) { 
  this.image.setBackgroundResource(R.drawable.blueup); 
  } else if (x > 0 && y > 0) { 
  this.image.setBackgroundResource(R.drawable.bluerightdown); 
  } else if (x < 0 && y < 0) { 
  this.image.setBackgroundResource(R.drawable.blueleftup); 
  } else if (x < 0 && y > 0) { 
  this.image.setBackgroundResource(R.drawable.blueleftdown); 
  } else if (x > 0 && y < 0) { 
  this.image.setBackgroundResource(R.drawable.bluerightup); 
  } else if (x == 0 && y == 0) {}} 
  this.image.setBackgroundResource(R.drawable.bluedot); 
  } 
  break; 
 case Constants.POINT_STATE_WRONG: 
  if (y == 0 && x > 0) { 
  this.image.setBackgroundResource(R.drawable.redright); 
  } else if (y == 0 && x < 0) { 
  this.image.setBackgroundResource(R.drawable.redleft); 
  } else if (x == 0 && y > 0) { 
  this.image.setBackgroundResource(R.drawable.reddown); 
  } else if (x == 0 && y < 0) { 
  this.image.setBackgroundResource(R.drawable.redup); 
  } else if (x > 0 && y > 0) { 
  this.image.setBackgroundResource(R.drawable.redrightdown); 
  } else if (x < 0 && y < 0) { 
  this.image.setBackgroundResource(R.drawable.redleftup); 
  } else if (x < 0 && y > 0) { 
  this.image.setBackgroundResource(R.drawable.redleftdown); 
  } else if (x > 0 && y < 0) { 
  this.image.setBackgroundResource(R.drawable.redrightup); 
  } else if (x == 0 && y == 0) {}} 
  this.image.setBackgroundResource(R.drawable.reddot); 
  } 
  break; 
 default: 
  break; 
 } 
 } 
 public int getNum() { 
 return num; 
 } 
 public void setNum(int num) { 
 this.num = num; 
 } 
 @Override 
 public int hashCode() { 
 final int prime = 31; 
 int result = 1; 
 result = prime * result + bottomY; 
 result = prime * result + ((image == null) ? 0 : image.hashCode()); 
 result = prime * result + leftX; 
 result = prime * result + rightX; 
 result = prime * result + topY; 
 return result; 
 } 
 @Override 
 public boolean equals(Object obj) { 
 if (this == obj) 
  return true; 
 if (obj == null) 
  return false; 
 if (getClass() != obj.getClass()) 
  return false; 
 GesturePoint other = (GesturePoint) obj; 
 if (bottomY != other.bottomY) 
  return false; 
 if (image == null) { 
  if (other.image != null) 
  return false; 
 } else if (!image.equals(other.image)) 
  return false; 
 if (leftX != other.leftX) 
  return false; 
 if (rightX != other.rightX) 
  return false; 
 if (topY != other.topY) 
  return false; 
 return true; 
 } 
 @Override 
 public String toString() { 
 return "Point [leftX=" + leftX + ", rightX=" + rightX + ", topY=" 
  + topY + ", bottomY=" + bottomY + "]"; 
 } 
} 

Next, let's see that9the drawing interface of a point
GestureContentView

package com.example.gesturelock; 
import java.util.ArrayList; 
import java.util.List; 
import com.example.gesturelock.GestureDrawline.GestureCallBack; 
import android.content.Context; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ImageView; 
/** 
 * Gesture password container class 
 * 
 */ 
public class GestureContentView extends ViewGroup { 
 /** 
 * Width of each point area 
 */ 
 private int blockWidth; 
 private int spacing ; 
 /** 
 * Declare a collection to encapsulate the coordinate collection 
 */ 
 private List<GesturePoint> list; 
 private Context context; 
 private GestureDrawline gestureDrawline; 
 /** 
 * contains9container of a number of ImageView, initialization 
 * @param context 
 * @param isVerify Whether it is a verification gesture password 
 * @param passWord Password entered by the user 
 * @param callBack Callback after gesture drawing is completed 
 */ 
 public GestureContentView(Context context, boolean isVerify,String passWord, GestureCallBack callBack) { 
 super(context); 
 this.blockWidth = dip2px(context,66f); //dp value of the diameter of the circles 
 this.spacing = dip2px(context, 30f); //dp value between circles 
 this.list = new ArrayList<GesturePoint>(); 
 this.context = context; 
 // Add9number of icons 
 addChild(); 
 // Initialize a view that can draw lines 
 gestureDrawline = new GestureDrawline(context, list, isVerify,passWord, callBack); 
 } 
 public static int dip2px(Context context, float dpValue) { 
 // TODO Auto-generated method stub 
 final float scale = context.getResources().getDisplayMetrics().density; 
 return (int) (dpValue * scale + 0.5f); 
 } 
 private void addChild(){ 
 for (int i = 0; i < 9; i++) { 
  ImageView image = new ImageView(context); 
  image.setBackgroundResource(R.drawable.gesturewhite);  
  this.addView(image,new LayoutParams(blockWidth, blockWidth)); 
  invalidate(); 
  // which row 
  int row = i / 3; 
  // which column 
  int col = i % 3; 
  // Define each attribute of the point 
  int leftX = col * blockWidth + col * spacing; 
  int topY = row * blockWidth + row * spacing; 
  int rightX = leftX + blockWidth; 
  int bottomY = topY + blockWidth; 
  //position of the line between circles 
  GesturePoint p = new GesturePoint(leftX, rightX, topY, bottomY, image,i+1); 
  this.list.add(p); 
 } 
 } 
 public void setParentView(ViewGroup parent){ 
 // get the screen width 
 LayoutParams layoutParams = 
  new LayoutParams(blockWidth * 3 + spacing * 2, blockWidth * 3 + spacing * 2); 
 parent.addView(gestureDrawline,layoutParams); 
 parent.addView(this,layoutParams); 
 } 
 @Override 
 protected void onLayout(boolean changed, int l, int t, int r, int b) { 
 for (int i = 0; i < getChildCount(); i++) { 
  //which row 
  int row = i/3; 
  //which column 
  int col = i%3; 
  View v = getChildAt(i); 
  //The position for drawing circles, d represents the offset in the X-axis direction; if you want to move the entire hand-drawn area up or down, increase or decrease the top and bottom parameters by an appropriate offset 
  int leftX = col * blockWidth + col * spacing; 
  int topY = row * blockWidth + row * spacing; 
  int rightX = leftX + blockWidth; 
  int bottomY = topY + blockWidth; 
  v.layout(leftX, topY, rightX, bottomY) ; 
 } 
 } 
 @Override 
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
 } 
 /** 
 * retain path delayTime duration 
 * @param delayTime 
 */ 
 public void clearDrawlineState(long delayTime) { 
 gestureDrawline.clearDrawlineState(delayTime); 
 } 
} 

Then continue to see the code for drawing the middle line when the finger is connected.
GestureDrawline

package com.example.gesturelock; 
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 
import android.annotation.SuppressLint; 
import android.content.Context; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.graphics.Canvas; 
import android.graphics.Color; 
import android.graphics.Paint; 
import android.graphics.Paint.Style; 
import android.graphics.PorterDuff; 
import android.os.Handler; 
import android.util.Log; 
import android.util.Pair; 
import android.view.MotionEvent; 
import android.view.View; 
/** 
 * Drawing the path of the gesture password 
 * 
 */ 
public class GestureDrawline extends View { 
 private int mov_x;// Declare the starting coordinate 
 private int mov_y; 
 private Paint paint;// Declare the pen 
 private Canvas canvas;// Canvas 
 private Bitmap bitmap;// Bitmap 
 private List<GesturePoint> list;// 
 private List<Pair<GesturePoint, GesturePoint>> lineList;// Record the lines drawn 
 private Map<String, GesturePoint> autoCheckPointMap;// The point automatically selected 
 private boolean isDrawEnable = true; // Whether to allow drawing 
 /** 
 * The width and height of the screen 
 */ 
 private int[] screenDisplay; 
 private GesturePoint currentPoint; 
 private GestureCallBack callBack; 
 private StringBuilder passWordSb; 
 private boolean isVerify; 
 private String passWord; 
 public GestureDrawline(Context context, List<GesturePoint> list, 
  boolean isVerify, String passWord, GestureCallBack callBack) { 
 super(context); 
 //Screen parameters 
 screenDispaly = AppUtil.getScreenDispaly(context); 
 //Pen 
 paint = new Paint(Paint.DITHER_FLAG);// 
 //Initialize the canvas--Width and height 
 bitmap = Bitmap.createBitmap(screenDispaly[0], screenDispaly[0], Bitmap.Config.ARGB_8888); // 
 canvas = new Canvas(); 
 canvas.setBitmap(bitmap); 
 //Set pen parameters 
 paint.setStyle(Style.STROKE); 
 paint.setStrokeWidth(15);// 
 paint.setColor(getResources().getColor(R.color.gestureline_green));// Set default line color 
 paint.setAntiAlias(true); 
 //9Set of points 
 this.list = list; 
 //Set of lines drawn 
 this.lineList = new ArrayList<Pair<GesturePoint, GesturePoint>>(); 
 initAutoCheckPointMap(); 
 this.callBack = callBack; 
 this.isVerify = isVerify; 
 this.passWord = passWord; 
 //Password Set 
 this.passWordSb = new StringBuilder(); 
 } 
 private void initAutoCheckPointMap() { 
 autoCheckPointMap = new HashMap<String, GesturePoint>(); 
 autoCheckPointMap.put("1,3"getGesturePointByNum("2)); 
 autoCheckPointMap.put("1,7"getGesturePointByNum("4)); 
 autoCheckPointMap.put("1,9"getGesturePointByNum("5)); 
 autoCheckPointMap.put("2,8"getGesturePointByNum("5)); 
 autoCheckPointMap.put("3,7"getGesturePointByNum("5)); 
 autoCheckPointMap.put("3,9"getGesturePointByNum("6)); 
 autoCheckPointMap.put("4,6"getGesturePointByNum("5)); 
 autoCheckPointMap.put("7,9"getGesturePointByNum("8)); 
 } 
 /**Get the corresponding point*/ 
 private GesturePoint getGesturePointByNum(int num) { 
 for (GesturePoint point : list) { 
  if (point.getNum() == num) { 
  return point; 
  } 
 } 
 return null; 
 } 
 /**Draw the bitmap onto the canvas*/ 
 @Override 
 protected void onDraw(Canvas canvas) { 
 canvas.drawBitmap(bitmap, 0, 0, null); 
 } 
 // Touch event 
 @SuppressLint("ClickableViewAccessibility") 
 @Override 
 public boolean onTouchEvent(MotionEvent event) { 
 if (isDrawEnable == false) { 
  return true; 
 } 
 // Set default line color 
 paint.setColor(getResources().getColor(R.color.gestureline_green)); 
 switch (event.getAction()) { 
 case MotionEvent.ACTION_DOWN: 
  mov_x = (int) event.getX(); 
  mov_y = (int) event.getY(); 
  /**Get the pressed point*/ 
  currentPoint = getPointAt(mov_x, mov_y); 
  if (currentPoint != null) { 
  /**Set the status of the pressed point and save the password*/ 
  currentPoint.setPointState(Constants.POINT_STATE_SELECTED, 0, 0); 
  passWordSb.append(currentPoint.getNum()); 
  } 
  invalidate(); 
  //Callback method 
  callBack.onPointDown() ; 
  break; 
 case MotionEvent.ACTION_MOVE: 
  //Clear the trace 
  clearScreenAndDrawList(); 
  //Move callback 
  callBack.onGestureLineMove(); 
  //Get the point at the position moved to 
  GesturePoint pointAt = getPointAt((int) event.getX(), 
   (int) event.getY()); 
  if (currentPoint == null && pointAt == null) { 
  return true; 
  } else { 
  //Slide from the interval to the original point 
  if (currentPoint == null && pointAt != null) { 
   // If it is empty, assign the point where the finger is moved to currentPoint 
   currentPoint = pointAt; 
   /**Set the status of the pressed point and save the password*/ 
   currentPoint.setPointState(Constants.POINT_STATE_SELECTED, 
    0, 0); 
   passWordSb.append(currentPoint.getNum()); 
  } 
  } 
  /***/ 
  if (pointAt == null 
   || currentPoint.equals(pointAt) 
   || Constants.POINT_STATE_SELECTED == pointAt 
    .getPointState()) { 
   canvas.drawLine(currentPoint.getCenterX(), 
   currentPoint.getCenterY(), event.getX(), event.getY(), 
   paint); 
  } else { 
  int x = pointAt.getCenterX() - currentPoint.getCenterX(); 
  int y = pointAt.getCenterY() - currentPoint.getCenterY(); 
  currentPoint 
   .setPointState(Constants.POINT_STATE_SELECTED, x, y); 
  if (pointAt.equals(list.get(list.size() - 1)) { 
   pointAt 
   .setPointState(Constants.POINT_STATE_SELECTED, 0, 0); 
  } 
  GesturePoint betweenPoint = getBetweenCheckPoint(currentPoint, 
   pointAt); 
  if (betweenPoint != null 
   && Constants.POINT_STATE_SELECTED != betweenPoint 
    .getPointState()) { 
   // There is an intermediate point that has not been selected 
   Pair<GesturePoint, GesturePoint> pair1 = new Pair<GesturePoint, GesturePoint> ( 
    currentPoint, betweenPoint); 
   lineList.add(pair1); 
   passWordSb.append(betweenPoint.getNum()); 
   Pair<GesturePoint, GesturePoint> pair2 = new Pair<GesturePoint, GesturePoint> ( 
    betweenPoint, pointAt); 
   lineList.add(pair2); 
   passWordSb.append(pointAt.getNum()); 
   betweenPoint.setPointState(Constants.POINT_STATE_SELECTED, 0, 0); 
   currentPoint = pointAt; 
  } else { 
   Pair<GesturePoint, GesturePoint> pair = new Pair<GesturePoint, GesturePoint>( 
    currentPoint, pointAt); 
   lineList.add(pair); 
   passWordSb.append(pointAt.getNum()); 
   currentPoint = pointAt; 
  } 
  } 
  invalidate(); 
  break; 
 case MotionEvent.ACTION_UP: 
  isDrawEnable = false; 
  if (isVerify) { 
  // Fingerprint password verification 
  String encodeString=MD5EncodeUtil.MD5Ecode(String.valueOf( passWordSb)); 
  String passwordMd5Ecode = MD5EncodeUtil.MD5Ecode(passWord); 
  if (passwordMd5Ecode.equals(encodeString)) { 
   callBack.checkedSuccess(); 
  } else { 
   Log.e("TAG", "encode String fali"); 
   callBack.checkedFail(); 
  } 
  } else { 
  //Redraw the interface 
  clearScreenAndDrawList(); 
  GesturePoint pointAtUp = getPointAt((int) event.getX(), 
   (int) event.getY()); 
  if (pointAtUp != null 
   && currentPoint.equals(pointAtUp) 
   && Constants.POINT_STATE_SELECTED == pointAtUp 
    .getPointState() && passWordSb.length() ==1) { 
   currentPoint.setPointState(Constants.POINT_STATE_WRONG, 
    0, 0); 
  } 
  invalidate(); 
  callBack.onGestureCodeInput(passWordSb.toString()); 
  } 
  break; 
 default: 
  break; 
 } 
 return true; 
 } 
 /** 
 * 
 * @param delayTime 
 *  The execution delay time 
 */ 
 public void clearDrawlineState(long delayTime) { 
 if (delayTime > 0) { 
  // Draw the red提示 route 
  isDrawEnable = false; 
  drawErrorPathTip(); 
 } 
 new Handler().postDelayed(new clearStateRunnable(), delayTime); 
 } 
 /** 
 */ 
 final class clearStateRunnable implements Runnable { 
 public void run() { 
  // Reset passWordSb 
  passWordSb = new StringBuilder(); 
  // Clear the set of saved points 
  lineList.clear(); 
  // Redraw the interface 
  clearScreenAndDrawList(); 
  for (GesturePoint p : list) { 
  p.setPointState(Constants.POINT_STATE_NORMAL, 0, 0); 
  } 
  invalidate(); 
  isDrawEnable = true; 
 } 
 } 
 /** 
 * 
 * @param x 
 * @param y 
 */ 
 private GesturePoint getPointAt(int x, int y) { 
 for (GesturePoint point : list) { 
  // Firstly judge x 
  int leftX = point.getLeftX(); 
  int rightX = point.getRightX(); 
  if (!(x >= leftX && x < rightX)) { 
  continue; 
  } 
  int topY = point.getTopY(); 
  int bottomY = point.getBottomY(); 
  if (!(y >= topY && y < bottomY)) { 
  continue; 
  } 
  // If the execution reaches here, it means that the position of the current clicked point is at this position where the point is traversed 
  return point; 
 } 
 return null; 
 } 
 private GesturePoint getBetweenCheckPoint(GesturePoint pointStart, 
  GesturePoint pointEnd) { 
 int startNum = pointStart.getNum(); 
 int endNum = pointEnd.getNum(); 
 String key = null; 
 if (startNum < endNum) { 
  key = startNum + " + endNum; 
 } else { 
  key = endNum + " + startNum; 
 } 
 return autoCheckPointMap.get(key); 
 } 
 /** 
 * Clear all lines on the screen and then draw the lines in the collection 
 */ 
 private void clearScreenAndDrawList() { 
 canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); 
 for (int i = 0; i < lineList.size(); i++) 
 { 
  int r = 0, x, y; 
  if ((lineList.get(i).first.getTopY() - lineList.get(i).first.getBottomY()) / 2 < 0) 
  r = -(lineList.get(i).first.getTopY() - lineList.get(i).first.getBottomY()) / 2; 
  else { 
  r = (lineList.get(i).first.getTopY() - lineList.get(i).first.getBottomY()) / 2; 
  } 
  float d = (float) 0.707 * r; 
  x = lineList.get(i).second.getCenterX() -lineList.get(i).first.getCenterX(); 
  y = lineList.get(i).second.getCenterY(); -lineList.get(i).first.getCenterY(); 
  if (i == lineList.size() - 1) { 
  lineList.get(i).second.setPointState(Constants.POINT_STATE_SELECTED, 0, 0); 
  lineList.get(i).first.setPointState(Constants.POINT_STATE_SELECTED, x, y); 
  } 
  else { 
   lineList.get(i).first.setPointState(Constants.POINT_STATE_SELECTED, x, y); 
   lineList.get(i).second.setPointState(Constants.POINT_STATE_SELECTED, x, y); 
  } 
  if (y == 0 && x > 0) { 
  canvas.drawLine(lineList.get(i).first.getCenterX(), + r, 
   lineList.get(i).first.getCenterY(), lineList.get(i).second.getCenterX(), - r, 
   lineList.get(i).second.getCenterY(), paint);// Draw line 
  } 
  else if (y == 0 && x < 0 ) { 
  canvas.drawLine(lineList.get(i).first.getCenterX(), - r, 
   lineList.get(i).first.getCenterY(), lineList.get(i).second.getCenterX(), + r, 
   lineList.get(i).second.getCenterY(), paint);// Draw line 
  }else if (x == 0 && y > 0){ 
  canvas.drawLine(lineList.get(i).first.getCenterX(), 
   lineList.get(i).first.getCenterY() + r, lineList.get(i).second.getCenterX(), 
   lineList.get(i).second.getCenterY() - r, paint);// Draw line 
  }else if (x == 0 && y < 0 ) {   
  canvas.drawLine(lineList.get(i).first.getCenterX(), 
   lineList.get(i).first.getCenterY() - r, lineList.get(i).second.getCenterX() , 
   lineList.get(i).second.getCenterY() + r, paint);// Draw line 
  } 
  else if( x > 0 && y > 0 ){ 
  canvas.drawLine(lineList.get(i).first.getCenterX(), + d, 
   lineList.get(i).first.getCenterY() + d, lineList.get(i).second.getCenterX() - d , 
   lineList.get(i).second.getCenterY() - d, paint);// Draw line 
  }else if(x > 0 && y < 0 ) 
  { 
  canvas.drawLine(lineList.get(i).first.getCenterX(), + d, 
   lineList.get(i).first.getCenterY() - d, lineList.get(i).second.getCenterX()-d , 
   lineList.get(i).second.getCenterY() + d, paint);// Draw line   
  } 
  else if (x < 0 && y > 0){ 
  canvas.drawLine(lineList.get(i).first.getCenterX(), - d, 
   lineList.get(i).first.getCenterY() + d, lineList.get(i).second.getCenterX()+d , 
   lineList.get(i).second.getCenterY() - d, paint);// Draw line 
  } 
  else if(x < 0 && y < 0 ) 
  { 
  canvas.drawLine(lineList.get(i).first.getCenterX(), - d, 
   lineList.get(i).first.getCenterY() - d, lineList.get(i).second.getCenterX()+d , 
   lineList.get(i).second.getCenterY() + d, paint);// Draw line 
  } 
 } 
 } 
 private void drawErrorPathTip() { 
 canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); 
paint.setColor(getResources().getColor(R.color.gestureline_red));// Set default line color 
 if(lineList.size() == 0 && currentPoint != null){ 
  currentPoint.setPointState(Constants.POINT_STATE_WRONG, 0, 0); 
 } 
 for (int i = 0; i < lineList.size(); i++) {  
  int r = 0, x, y; 
  if ((lineList.get(i).first.getTopY() - lineList.get(i).first.getBottomY()) / 2 < 0) 
  r = -(lineList.get(i).first.getTopY() - lineList.get(i).first.getBottomY()) / 2; 
  else { 
  r = (lineList.get(i).first.getTopY() - lineList.get(i).first.getBottomY()) / 2; 
  } 
  float d = (float) 0.707 * r; 
  x = lineList.get(i).second.getCenterX() -lineList.get(i).first.getCenterX(); 
  y = lineList.get(i).second.getCenterY(); -lineList.get(i).first.getCenterY(); 
  if (i == lineList.size() - 1) { 
  lineList.get(i).second.setPointState(Constants.POINT_STATE_WRONG, 0, 0); 
  lineList.get(i).first.setPointState(Constants.POINT_STATE_WRONG, x, y); 
  } 
  else { 
   lineList.get(i).first.setPointState(Constants.POINT_STATE_WRONG, x, y); 
   lineList.get(i).second.setPointState(Constants.POINT_STATE_WRONG, x, y); 
  } 
  if (y == 0 && x > 0) { 
  canvas.drawLine(lineList.get(i).first.getCenterX(), + r, 
   lineList.get(i).first.getCenterY(), lineList.get(i).second.getCenterX(), - r, 
   lineList.get(i).second.getCenterY(), paint);// Draw line 
  } 
  else if (y == 0 && x < 0 ) { 
  canvas.drawLine(lineList.get(i).first.getCenterX(), - r, 
   lineList.get(i).first.getCenterY(), lineList.get(i).second.getCenterX(), + r, 
   lineList.get(i).second.getCenterY(), paint);// Draw line 
  }else if (x == 0 && y > 0){ 
  canvas.drawLine(lineList.get(i).first.getCenterX(), 
   lineList.get(i).first.getCenterY() + r, lineList.get(i).second.getCenterX(), 
   lineList.get(i).second.getCenterY() - r, paint);// Draw line 
  }else if (x == 0 && y < 0 ) {   
  canvas.drawLine(lineList.get(i).first.getCenterX(), 
   lineList.get(i).first.getCenterY() - r, lineList.get(i).second.getCenterX() , 
   lineList.get(i).second.getCenterY() + r, paint);// Draw line 
  } 
  else if( x > 0 && y > 0 ){ 
  canvas.drawLine(lineList.get(i).first.getCenterX(), + d, 
   lineList.get(i).first.getCenterY() + d, lineList.get(i).second.getCenterX() - d , 
   lineList.get(i).second.getCenterY() - d, paint);// Draw line 
  }else if(x > 0 && y < 0 ) 
  { 
  canvas.drawLine(lineList.get(i).first.getCenterX(), + d, 
   lineList.get(i).first.getCenterY() - d, lineList.get(i).second.getCenterX()-d , 
   lineList.get(i).second.getCenterY() + d, paint);// Draw line   
  } 
  else if (x < 0 && y > 0){ 
  canvas.drawLine(lineList.get(i).first.getCenterX(), - d, 
   lineList.get(i).first.getCenterY() + d, lineList.get(i).second.getCenterX()+d , 
   lineList.get(i).second.getCenterY() - d, paint);// Draw line 
  } 
  else if(x < 0 && y < 0 ) 
  { 
  canvas.drawLine(lineList.get(i).first.getCenterX(), - d, 
   lineList.get(i).first.getCenterY() - d, lineList.get(i).second.getCenterX()+d , 
   lineList.get(i).second.getCenterY() + d, paint);// Draw line 
  } 
 } 
 invalidate(); 
 } 
 public interface GestureCallBack { 
 public abstract void onGestureCodeInput(String inputCode); 
 public abstract void checkedSuccess(); 
 public abstract void checkedFail(); 
 public abstract void onGestureLineMove(); 
 public abstract void onPointDown() ; 
 } 
} 

ok Preparation work is completed, next is to see the setting of gesture password interface
gesture_edit.xml

<?xml version="1.0" encoding="utf"-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:orientation="vertical" 
 android:background="#f2f2f2" > 
 <LinearLayout 
 android:id="@"+id/ll_head" 
 android:layout_width="fill_parent" 
 android:layout_height="48dp" 
 android:background="@drawable/bg_head" 
 android:gravity="center_vertical" 
 android:orientation="horizontal" > 
 <LinearLayout 
  android:id="@"+id/ll_head_left" 
  android:layout_width="wrap_content" 
  android:layout_height="fill_parent" 
  android:layout_marginTop="1dp" 
  android:gravity="center_vertical" 
  android:background="@drawable/selector_head_back" 
  android:orientation="horizontal" > 
  <ImageView 
  android:id="@"+id/im_back" 
  android:layout_width="7dp" 
  android:layout_height="14dp" 
  android:layout_marginLeft="5dp" 
  android:background="@drawable/back" /> 
  <TextView 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:layout_marginLeft="5dp" 
  android:text="@string/set_gesture_code" 
  android:textColor="#fff" 
  android:textSize="17.33dp" /> 
 </LinearLayout> 
 <View 
  android:layout_width="0dp" 
  android:layout_height="fill_parent" 
  android:layout_weight="1" /> 
 </LinearLayout> 
 <LinearLayout 
 android:id="@"+id/gesture_tip_layout" 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="75.67dp" 
 android:orientation="vertical" > 
 <TextView 
  android:id="@"+id/tv_edit_texttip" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:gravity="center_horizontal" 
  android:text="@string/set_gesture_pattern" 
  android:textColor="@color/color_black" 
  android:textSize="@dimen/textsize_s3" /> 
 </LinearLayout> 
 <RelativeLayout 
 android:id="@"+id/fl_edit_gesture_container" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="48dp" 
 android:gravity="center_horizontal" > 
 </RelativeLayout> 
</LinearLayout> 

GestureEditActivity

package com.example.gesturelock; 
import android.app.Activity; 
import android.database.sqlite.SQLiteDatabase; 
import android.os.Bundle; 
import android.os.Handler; 
import android.text.TextUtils; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.LinearLayout; 
import android.widget.RelativeLayout; 
import android.widget.TextView; 
import com.example.gesturelock.GestureDrawline.GestureCallBack; 
public class GestureEditActivity extends Activity implements OnClickListener { 
 private LinearLayout im_back; 
 private TextView tv_texttip; 
 private RelativeLayout mGestureContainer; 
 private GestureContentView mGestureContentView; 
 // The password entered for the first time 
 private String mFirstPassword = null; 
 // Is it the first input 
 private boolean mIsFirstInput = true; 
 static final String TABLES_NAME_GESTURE = "gesture_password"; 
 public final static int GESTURE_TIME = 8; 
 private publicSQLiteOpenHelper sqliteInstance; 
 private SQLiteDatabase database; 
 public void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.gesture_edit); 
 // Error prompt 
 tv_texttip = (TextView) findViewById(R.id.tv_edit_texttip); 
 // 9Point area 
 mGestureContainer = (RelativeLayout) findViewById(R.id.fl_edit_gesture_container); 
 // Back 
 im_back = (LinearLayout) findViewById(R.id.ll_head_left); 
 // Initialization continues cannot be clicked 
 im_back.setOnClickListener(this);}} 
 mGestureContentView = new GestureContentView(this, false, "", 
  new GestureCallBack() { 
   @Override 
   public void onGestureCodeInput(String inputCode) { 
   if (mIsFirstInput) { // First input gesture password 
    if (!isInputPassValidate(inputCode)) { 
    // At least connect4points 
    tv_texttip.setText(getResources().getString(',')) 
     R.string.drawguesturewarning)); 
    // 2seconds later, the interface will be cleared 
    mGestureContentView.clearDrawlineState()}}2000L); 
    // 2seconds later, the prompt will be restored 
    mHandler.postDelayed(connect4Dot, 2000); 
    return; 
    } 
    mFirstPassword = inputCode; 
    tv_texttip.setText(getResources().getString(',')) 
     R.string.drawguestureagain)); 
    mHandler.postDelayed(clearGreenLine, 1000); 
    mIsFirstInput = false; 
    } 
   } else { 
    if (inputCode.equals(mFirstPassword)) { // The second input gesture password is consistent with the first 
    tv_texttip.setText(getResources().getString(',')) 
     R.string.your_gesture_code)); 
    sqliteInstance = new publicSQLiteOpenHelper(GestureEditActivity.this); 
    database = sqliteInstance.getWritableDatabase(); 
    boolean count = sqliteInstance.queryGestureTableCount(database); 
    If there is a record 
     //sqliteInstance.updateGestureInfo(database, mFirstPassword, " 
     else {8"); 
    } 
     //If there is no record 
     sqliteInstance.insertGestureInfo(database, mFirstPassword, "8"); 
    } 
    mHandler.postDelayed(setGestureOkFinish, 1000); 
    } else { 
    if (!isInputPassValidate(inputCode)) { 
     // At least connect4points 
     tv_texttip.setText(getResources().getString(',')) 
      R.string.drawguesturewarning)); 
     // 2seconds later, the interface will be cleared 
     mGestureContentView.clearDrawlineState()}}2000L); 
     // 2seconds later, the prompt will be restored 
     mHandler.postDelayed(connect4Dot, 2000); 
    } else { // The second input gesture password is inconsistent with the first 
     tv_texttip.setText(getResources() 
      .getString(R.string.drawagain)); 
     // Left and right moving animation 
//     Animation shakeAnimation = 
//     AnimationUtils.loadAnimation(GestureEditActivity.this, R.anim.shake); 
//     tv_texttip.startAnimation(shakeAnimation); 
     // Maintain the drawn line,1.5seconds later clear 
     mGestureContentView 
      .clearDrawlineState(2000L); 
     mHandler.postDelayed(changeText2again, 2000); 
    } 
    } 
   } 
   } 
   @Override 
   public void checkedFail() { 
   } 
   @Override 
   public void onGestureLineMove() { 
   tv_texttip.setText(getResources().getString(',')) 
    R.string.release_hande_when_finish)); 
   } 
   @Override 
   public void onPointDown() { 
   } 
   @Override 
   public void checkedSuccess() { 
   } 
  }); 
 // Set the gesture unlock display to which layout 
 mGestureContentView.setParentView(mGestureContainer); 
 } 
 @Override 
 protected void onResume() { 
 super.onResume(); 
 } 
 Handler mHandler = new Handler(); 
 Runnable clearGreenLine = new Runnable() { 
 public void run() { 
  mGestureContentView.clearDrawlineState(0L); 
 } 
 }; 
 Runnable connect4Dot = new Runnable() { 
 public void run() { 
  tv_texttip.setText(getResources().getString(',')) 
   R.string.set_gesture_pattern)); 
 } 
 }; 
 Runnable setGestureOkFinish = new Runnable() { 
 public void run() { 
  finish(); 
 } 
 }; 
 Runnable changeText2again = new Runnable() { 
 public void run() { 
  tv_texttip.setText(getResources().getString(',')) 
   R.string.drawguestureagain)); 
 } 
 }; 
 private boolean isInputPassValidate(String inputPassword) { 
 if (TextUtils.isEmpty(inputPassword) || inputPassword.length() < 4) { 
  return false; 
 } 
 return true; 
 } 
 protected void onDestroy() { 
 super.onDestroy(); 
 } 
 @Override 
 public void onClick(View v) { 
 switch (v.getId()) { 
 case R.id.ll_head_left: 
  finish(); 
  break; 
 } 
 } 
} 

Finally, look at the verification interface
gesture_verify.xml

<?xml version="1.0" encoding="utf"-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android 
 android:layout_width="match_parent" 
 android:orientation="vertical" 
 android:layout_height="match_parent" 
 android:background="@color"/color_main" > 
 <LinearLayout 
 android:id="@"+id/ll_head" 
 android:layout_width="fill_parent" 
 android:layout_height="48dp" 
 android:background="@drawable/bg_head" 
 android:gravity="center_vertical" 
 android:orientation="horizontal" > 
 <LinearLayout 
  android:id="@"+id/ll_head_left" 
  android:layout_width="wrap_content" 
  android:layout_height="fill_parent" 
  android:layout_marginTop="1dp" 
  android:gravity="center_vertical" 
  android:background="@drawable/selector_head_back" 
  android:orientation="horizontal" > 
  <ImageView 
  android:id="@"+id/im_back" 
  android:layout_width="7dp" 
  android:layout_height="14dp" 
  android:layout_marginLeft="5dp" 
  android:background="@drawable/back" /> 
  <TextView 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:layout_marginLeft="5dp" 
  android:text="@string/verify_gesture_code" 
  android:textColor="#fff" 
  android:textSize="17.33dp" /> 
 </LinearLayout> 
 <View 
  android:layout_width="0dp" 
  android:layout_height="fill_parent" 
  android:layout_weight="1" /> 
 </LinearLayout> 
 <LinearLayout 
 android:id="@"+id/gesture_tip_layout" 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="75.67dp" 
 android:orientation="vertical" > 
 <TextView 
  android:id="@"+id/tv_edit_texttip" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:gravity="center_horizontal" 
  android:text="@string/set_gesture_pattern" 
  android:textColor="@color/color_black" 
  android:textSize="@dimen/textsize_s3" /> 
 </LinearLayout> 
 <RelativeLayout 
 android:id="@"+id/fl_verify_gesture_container" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="48dp" 
 android:gravity="center_horizontal" > 
 </RelativeLayout> 
</LinearLayout> 

Final verification code

package com.example.gesturelock; 
import java.util.Timer; 
import java.util.TimerTask; 
import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.content.Intent; 
import android.database.sqlite.SQLiteDatabase; 
import android.os.Bundle; 
import android.os.Handler; 
import android.os.Message; 
import android.text.TextUtils; 
import android.util.Log; 
import android.view.View; 
import android.widget.LinearLayout; 
import android.widget.RelativeLayout; 
import android.widget.TextView; 
import com.example.gesturelock.GestureDrawline.GestureCallBack; 
public class GestureVerifyActivity extends Activity { 
 private static String TAG = "GestureVerifyActivity"; 
 private TextView tv_texttip; 
 private RelativeLayout mGestureContainer; 
 private LinearLayout ib_back; 
 private GestureContentView mGestureContentView; 
 private Timer timer = new Timer() ; 
 private TimerTask closeActivityTask = null; 
 static final String TABLES_NAME_GESTURE = "gesture_password"; 
 private int remainopportunity ; 
 private publicSQLiteOpenHelper sqliteInstance; 
 private SQLiteDatabase database; 
 private void resetCloseEvent(){ 
 clearCloseEvent() ; 
 closeActivityTask = new TimerTask() { 
  public void run() { 
  Message message = new Message(); 
  message.what = 1; 
  handler.sendMessage(message); 
  } 
 }; 
 timer.schedule(closeActivityTask, 30000); 
 } 
 private void clearCloseEvent(){ 
 if(closeActivityTask != null){ 
  closeActivityTask.cancel() ; 
  closeActivityTask = null ; 
  Log.i(TAG, "----------closeActivityTask----------"+closeActivityTask); 
 } 
 } 
 public void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.gesture_verify); 
 resetCloseEvent(); 
 tv_texttip = (TextView) findViewById(R.id.tv_edit_texttip); 
 ib_back = (LinearLayout) findViewById(R.id.ll_head_left); 
 mGestureContainer = (RelativeLayout) findViewById(R.id.fl_verify_gesture_container); 
 sqliteInstance = new publicSQLiteOpenHelper(GestureVerifyActivity.this); 
 database = sqliteInstance.getWritableDatabase(); 
 //Obtain gesture password and remaining times from the database 
 firstPassward = sqliteInstance.queryGesturePassword(database); 
 remainopportunityStr = sqliteInstance.queryGestureTime(database); 
 if (TextUtils.isEmpty(remainopportunityStr)) { 
  remainopportunity = 8; 
  //Initialization8times 
  sqliteInstance.updateGestureInfo(database,null, "8"); 
 } else { 
  remainopportunity = Integer.parseInt(remainopportunityStr); 
 } 
 if(remainopportunity == 0){ 
  tv_texttip.setTextColor(getResources().getColor(R.color.gestureline_red)); 
  tv_texttip.setText(getResources().getString(R.string.no_chance)); 
 } 
 ib_back.setOnClickListener(new View.OnClickListener() { 
  @Override 
  public void onClick(View v) { 
  finish(); 
  } 
 }); 
 mGestureContentView = new GestureContentView(this, true, firstPassward, 
  new GestureCallBack() { 
   @Override 
   public void onGestureCodeInput(String inputCode) { 
   } 
   @SuppressLint("ShowToast") 
   @Override 
   public void checkedSuccess() { 
   sqliteInstance.updateGestureInfo(database,null, "8"); 
   mGestureContentView.clearDrawlineState(0L); 
   resetCloseEvent(); 
   finish(); 
   //Send broadcast 
   sendBroadcast(new Intent("com.godinsec.seland.intent.CASIntent.INTENT_LOAD_SD")); 
   } 
   @Override 
   public void checkedFail() { 
   mGestureContentView.clearDrawlineState()}}2000L); 
   tv_texttip.setTextColor(getResources().getColor(R.color.gestureline_red)); 
   if(remainopportunity > 0){ 
    remainopportunity-- ; 
   } 
   sqliteInstance.updateGestureInfo(database,null,"")+remainopportunity) 
   resetCloseEvent(); 
   changeText(); 
   } 
   @Override 
   public void onGestureLineMove() { 
   if(remainopportunity > 0){ 
    tv_texttip.setTextColor(getResources().getColor(R.color.textcolor_black_bb)); 
    tv_texttip.setText(getResources().getString(R.string.release_hande_when_finish)); 
   } 
   } 
   @Override 
   public void onPointDown() { 
   clearCloseEvent() ; 
   } 
  }); 
 mGestureContentView.setParentView(mGestureContainer); 
 } 
 protected void changeText() { 
 Log.e("TAGG", "changeText"); 
 if (remainopportunity == 7) { 
  tv_texttip.setText(getResources().getString(',')) 
   R.string.wrong_answer_seven)); 
 } else if (remainopportunity == 6) { 
  tv_texttip.setText(getResources().getString(',')) 
   R.string.wrong_answer_six)); 
 } else if (remainopportunity == 5) { 
  tv_texttip.setText(getResources().getString(',')) 
   R.string.wrong_answer_five)); 
 } else if (remainopportunity == 4) { 
  tv_texttip.setText(getResources().getString(',')) 
   R.string.wrong_answer_four)); 
 } else if (remainopportunity == 3) { 
  tv_texttip.setText(getResources().getString(',')) 
   R.string.wrong_answer_three)); 
 } else if (remainopportunity == 2) { 
  tv_texttip.setText(getResources().getString(',')) 
   R.string.wrong_answer_two)); 
 } else if (remainopportunity == 1) { 
  tv_texttip.setText(getResources().getString(',')) 
   R.string.wrong_answer_one)); 
 } else { 
  tv_texttip.setText(getResources().getString(',')) 
    
  handler.postDelayed(errorFinish, 2000); 
 } 
 } 
 @Override 
 protected void onResume() { 
 super.onResume(); 
 } 
 Runnable errorFinish = new Runnable() { 
 public void run() { 
  finish(); 
 } 
 }; 
 @SuppressLint("HandlerLeak") 
 Handler handler = new Handler() { 
 @Override 
 public void handleMessage(Message msg) { 
  super.handleMessage(msg); 
  switch (msg.what) { 
  case 1: 
  finish(); 
  break; 
  } 
 } 
 }; 
 private String remainopportunityStr; 
 private String firstPassward; 
 protected void onDestroy() { 
 super.onDestroy(); 
 } 
 protected void onStop() { 
 super.onStop(); 
 } 
} 

That's all for this article, I hope it will be helpful to everyone's learning, and I also hope everyone will support the呐喊 tutorial more.

Statement: The content of this article is from the Internet, the copyright belongs to the original author, the content is contributed and uploaded by Internet users spontaneously, this website does not own the copyright, does not undergo manual editing, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report violations, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)

You May Also Like