Android gesture password implementation example code

1、 Effect realization

2、 Implementation idea:

1. The prompt area directly above is implemented by a class (lockindicator. Java), and 9 prompt icons are drawn by user-defined view;

2. The gesture password drawing area is implemented by a class (gesturecontentview. Java), which inherits from ViewGroup, adds 9 imageviews to represent icons, and sets their positions in the onlayout () method;

3. Gesture path drawing is implemented by a class (gesturedrawline. Java). Copy the ontouchevent () method, and listen for the touchevent event: action in this method_ DOWN、ACTION_ MOVE、ACTION_ Up event to draw the path between different points of gesture connection;

4. An object with 9 points is implemented with a class (gesturepoint. Java) to save its location, state, background picture and other related information;

5. Obtain the gesture password, judge the current position of the finger, and save the order of drawn points in order according to the points passed by the sliding path (the order of points here is: 1,2,3,4,5,6,7,8,9 from top to bottom). There can be no duplicate points.

3、 Code implementation steps:

1. Use a class to represent the first of the nine points. There are properties such as the upper, lower, left and right positions of the current point

2. Custom groupview is used to install 9 points. The display of 9 points is through ImageView. Copy the onlayout method to arrange the points as needed

3. Define a view that can draw lines, copy the ontouchevent method, and draw lines in this method

4. Judge the current position of the user's finger, take out the current position and compare it with the position of each of the nine points. If the position of the user's point is within a certain point, when that point replaces the background picture.

The specific implementation code is as follows:

1. Lockindicator.java pattern prompt class

2. Gesturecontentview.java gesture password container class

It inherits the ViewGroup and adds a child view through the addview() method. The nine input points (gesturepoint) and gesturedrawline gesture password paths of the gesture password are placed in this container. The following is its specific implementation method:

3. Gesturedrawline.java gesture password path drawing class

According to different events of the ontouchevent method, action_ DOWN、ACTION_ MOVE、ACTION_ Up handles different logic separately.

4. Gestureeditactivity.java gesture password setting interface

Gesture password setting

The code is as follows:

5. Gestureverifyactivity.java gesture password verification interface

The code is as follows:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>