Detailed explanation of Android simple gesture password open source library
brief introduction
This paper introduces the use and implementation of an Android gesture password open source library, which mainly realizes the following functions:
Recently, I need to use the gesture password unlocking function. I found some demos and felt it was a little troublesome to use. Therefore, I made the wheel by referring to some articles and encapsulated some relevant methods, which is more convenient to use.
The GitHub link is as follows. I think it's OK. Please help with star support~
GitHub link personal blog
Use effect
First, let's look at the use effect:
usage method
Use this control in an XML layout file
Some parameters that can be set are described as follows:
initialization
Set gesture password listening event
If the password has been set, you will enter the callback and process the result here. In the above example, a password reset process is added.
Gesture password setting
If the password has not been set, the callback will be entered when drawing the gesture. The return value is the number of touch points drawn. If true is returned in onfirstinputcomplete, the drawing of the second gesture password will be entered. After two inputs are consistent, the password will be automatically saved.
The number of retries exceeds the limit
If the listening event is set, the number of input errors is limited. After exceeding the upper limit, enter the callback and handle it in the callback.
Clear the logic of the password and add a judgment. For details, see the demo on GitHub
Other APIs
Import the library in the project
Just add two lines of code:
In the project build Add to gradle:
Module build Add dependencies to gradle:
The total use is like this, isn't it very simple!
Specific implementation process
Let's talk about the implementation process. If you just use it directly, you can skip this part.
Circular view of custom gesture password
This part mainly refers to Hongyang dada's blog and has been slightly modified
Initialize incoming parameters
Draw circles of different colors according to different touch states
Draw arrow
ViewGroup for custom gesture password
Add custom view properties
Get parameters and initialization
Draw the circle according to the parameters
After onMeasure, the method is called and the circular matrix is drawn.
Handling different events in touch monitoring
Set password processing:
Check whether the gesture password is correct:
Reset:
Some methods of public disclosure
Defines the preference for the password store
It's simply saving and reading