Android lock screen principle (I)

Source: Internet
Author: User

Recently, I was busy with job hopping. The first project after I came to mobile was to create a custom Android lock screen module. At present, there are almost no images from UI engineers. Here we will share with you what I have done. Draw a picture first

 

I don't know if you have read this picture. It's disgusting. Back to the question

First, let's look at it on the left, from top to bottom. 1. The first screenreceiver is used as the screen lock entry. Enable broadcasting when the system is turned on and off. Enable the screen lock service based on whether the screen can be locked or not.

2. Use screenservice as the screen lockProgramThe core class in, register and receive the screen on/off broadcast after startup, and process the corresponding tasks respectively. The second is the monitoring of the mobile phone status, that is, the three statuses of the phone, idle, ringing, pending (answering), and processing respectively. The same is true for processing alarms and other things. Well, I will not elaborate on it. The last step is to process some initialization data for the lock screen.

3. screenactiviy. The class name is somewhat 2, which may mislead others. The function is very simple. After the screen lock service is called, it starts and then processes the screen lock of the topic to be displayed in this activity, that is, the lockscreenactivity to be called. It is equivalent to a controller.

4. lockscreenactivity is the screen that our mobile phone sees after the screen lock. It depends on how you handle it. It is to deal with some unlocking actions, such as time, date, and power. This classCodeThere are many. I will paste it later. The last figure shows you. Don't joke. There are no pictures at present. Just pull them online.

Bad, haha.

5. locktamplateactivity. This class is the base class (Template Class) of lockscreenactivity ). Nothing, just a few wow things, but some public methods are also provided for sub-classes. The Home Key, Return key, search key, menu, and status bar are blocked.

6. lockconstants: What should I do when I look at the name? A constant class, some data storage, initialization or something. The storage method is sharedpreferences.

7. locksettingactivity: Set Some lock screen functions, and save the settings as sharedpreferences.

Basic Idea: There is no doubt that every time we need to display the lockscreen-lock screen interface, we do not actually lock the screen, but simply provide an empty method to call the system, let the system feel that we have "locked the screen", and do not really hide the "locked screen" interface, providing an empty shell for the system to call. Other problems may be involved, such as: Can you pull down the status bar, press the power key, and the screen will soon sleep. Come on, we need to handle it in a unified manner. ------ Reference the words of a senior

Now, I will talk about the implementation of each block in the next article.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.