Android imitation mobile phone QQ pattern unlocking function

This example shares the specific code of Android imitation mobile phone QQ pattern unlocking for your reference. The specific contents are as follows

PS: please don't ask me again why there is garbled code after importing. In fact, the code is basically extracted from the native system: lockpatternview, encryption tool class, unlocking logic, etc. I just made some modifications. As we all know, the native system interface is ugly. Therefore, I specially decompressed the APK of QQ and took some pictures of pattern unlocking. A simple example was born.

Well, no more nonsense, let's see the effect (the last two are the latest 4.4 system, dazzle, ha ha):

1. The most important thing is the user-defined Jiugong grid view. The code comes from the framework: lockpatternview. The native system uses a lot of picture resources, like 7 or 8, and the drawing is relatively complex. After looking for it for a long time, I was blind. I found that there are only three pictures, one circle and two points in the decompressed QQ. I can't help but modify the code, In the process of modification, it was found that the original lockpatternview can be simplified and fewer pictures can be drawn to achieve better results. The total optimization is as follows: ① the arrow of the connection is removed; ② the original connection is only white, and the yellow and red colors are displayed according to different states; ③ the original view is to draw points first and then lines, so that the lines cover the points and affect the beauty. Instead, draw lines first and then points.

Key part code OnDraw function:

2. The second thing worth learning is (the code comes from the setting application): enumeration is used when creating unlocking patterns. Many enumerations are used in the native code to closely connect the status when drawing patterns, the status of the two buttons at the bottom and the prompt text displayed in a textview at the top. Therefore, only by monitoring the dynamic changes of lockpatternview and correspondingly changing the status of the bottom button and the top textview, the linkage can be realized. A simple method can realize the logic that can be realized by a lot of code. I like it very much.

① Global status:

② . status enumeration of the bottom two buttons:

In this way, as soon as the state of lockpatternview changes, the text and state of the bottom two buttons will be changed dynamically. Very concise and logical.

3. The third thing that I think is more useful is encryption. For future convenience, I divide pattern encryption and character encryption into two tool classes: lockpatternutils and lockpasswordutils. Lockpatternutils is used in this paper. In fact, the so-called pattern encryption is to convert it into binary numbers through SHA-1 encryption, and then save it to the file (the native system is saved in the / system / directory, and I don't have permission here, so I save it to the application directory). During decryption, the user's input is encrypted in the same way, and then compared with that saved in the file, the password is correct, Different passwords are incorrect. The key codes are the following four functions:

Well, that's all for the code analysis. Thank you very much for seeing the end of the article.

Source code of this article (UTF-8 code): Android imitation mobile phone QQ pattern unlocking

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
分享
二维码
< <上一篇
下一篇>>