Tell me the story behind Android desktop (launcher APP) (I)-Unveil her secret

Source: Internet
Author: User

 Blog migration-I have migrated my blog to www.ijavaboy.com to better manage it. We are sorry for the inconvenience caused by no updates! New address of this article: Click me


Recently, due to the project's need to customize a management system, I thought of the android starter and came down with the source code. A compilation error was found everywhere. I checked the cause and it turned out to be a reference to my own members, they developed convenience for direct use. So I downloaded a package and finally got half of the errors. However, there are still some errors, mainly because some nonexistent resources are referenced. So we changed it and basically we can run it.

However, the problem arises. At a glance, the Red Cross is gone, but the revolution is still not optimistic. One person I know, but suddenly hundreds of people appear in front of me, I am not dizzy, but dizzy. However, even if the army is dizzy, the revolution must be carried out with a strong scalp, because one thing is certain, the revolution must be successful and cannot be failed!

The next series of articles will record my journey to the revolution! It was originally intended to be modified on the basis of the original launcher, but later it was found that features do not need to be so complicated and there were many changes. Therefore, I analyzed the source code and re-wrote it myself, re-writing is actually a copy, but it has the advantage of copying. When the teacher assigns homework and the homework is not correct, the teacher will always say that this letter is copied three hundred times, that word is copied one hundred times... it can be seen that there are more copies, so remember. However, the premise is to carefully copy the words, so you cannot read the scriptures and have no intention. Here, of course, you can't copy a hundred times. If you copy one time, it will consume hundreds of millions of brain cells. We can better think about what functions I want to implement, how each function is implemented, and how the system launcher is implemented. In this way, it is easy to classify the functions with problems, clear your mind and avoid getting lost in the vast amount of code.

Let's get down to the truth. If we want to write the same launcher ourselves, we have to look at the simulator or the Android system first, so that we can look at this simple but hidden starter that starts the first one each time. Through some tossing, You can roughly divide the functions implemented by launcher into the following:

1. Long-pressed in an empty position, with the ability to add applications, shortcuts, folders, and widgets

2. Sliding Screen between left and right

3. You can change the wallpaper.

4. Long press an item on the desktop (the four items mentioned above can be added to the desktop), and you can drag them as needed. At the same time, the position of sldingdrawer below will become a garbage bin, when you place the dragged item in the bin, its color turns red, it means that the item will be deleted as soon as you let it go.

5. There is a slidingdrawer under the desktop. You can play it up at one point and all applications are in it. You can drag it to the desktop with a long press.

 

With the classification of these features, our task is very clear. Let's analyze and think about how to implement each function, and finally integrate the effect you see now.

First, let's look at the first question.

After a simple thought, I think it should be very simple, that is, listening to the long-press event in the lower bound. In this event, a pop-up Application List will be OK, if the pop-up Application List can also be called by the system, it is easier.

Second question:

Sliding Screen, I didn't know how to implement it at the beginning. When I got off work at night, I got down on the bus and stood at the window. A pair of gloomy eyes were filled with hesitation, this problem is always in mind. When the bus started, when everything outside the window was slowly retreating in front of my eyes, I woke up and cried out, so it turned out! Fortunately, the voice is not big, otherwise it will be ugly again. In the past, the mobile phone screen is equivalent to a bus window, and there is a big landscape behind it, but when we hold the mobile phone, the window is still, but when we slide, the landscape is moving. As for how to move the data and other details, we will analyze it later.

Third question:

Because I have done one before, I don't have to think too much about changing the wallpaper. I directly call the system wallpaper to select an application, and then implement a broadcastreciever to listen for the wallpaper changes, obtain a bitmap type.

However, the key here is how to display bitmap and move the wallpaper accordingly as the screen slides. Here the wallpaper is equivalent to the landscape described above, currently, we think of setting it as the background directly, but it is not feasible between multiple screens.

Fourth question:

Drag itself is not difficult, but it is difficult to drag between multiple screens. There is no specific idea. after implementing the second problem, we can integrate the multi-screen and drag-and-drop functions.

Fifth question:

This is very simple. The content of slidingdrawer is a gridview. Each item in the gridview is an application. The key is to drag an item to the desktop by pressing it for a long time, think about it later.

 

At this point, the general idea of each function is available. However, when we start, we find that there is no clue about this, but we still have to fight the first battle to understand the "enemy. Therefore, I have a rough view of the launcher source code, mainly looking at the use of each of its classes and identifying its design ideas. Here, you don't need to worry about the specific functions of a specific method of a class. You just need to know what each class is doing, and then divide the primary-secondary relationship to see which is the key, what are secondary and what are ancillary products...

After the first battle, we achieved the following results:

I. Each type of item on the desktop is encapsulated by class. The main hierarchies are as follows:

-- Iteminfo

-- Applicationinfo

-- Folderinfo

-- Livefolderinfo

-- Userfolderinfo

-- Widget

 

II. The overall layout level is as follows:

-- Draglayer

-- Workspace

-- Celllayout

-- Cellinfo (application, shortcut, folder, widget)

-- Celllayout

-- Celllayout

-----------------------------------------

3. Several important key classes: celllayout, workspace, launcher, and draglayer. The desktop layout is clear when you grasp these several basics. The outermost layer is draglayer, which controls the drag of items on the desktop. The draglayer is a workspace, And the workspace is the entire desktop. It consists of several celllayout horizontal pasters, which mainly controls the sliding of multiple screens and the drawing of wallpapers; celllayout is a custom Layout control. Its function is similar to a gridview, which consists of M * n cells (cells). It is mainly responsible for processing the desktop long-press event and obtaining the area information of Long-press, it is mainly necessary to determine whether the current region is empty or occupied, and control the drag of items. In celllayout, items of the preceding types are put. The drag function of items is completed by the collaboration of draglayer, workspace, and celllayout.

 

Now, the basic application is ready. First, do not pay attention to the specific usage of other classes. First, complete all la s!

In the next article, we will solve the first function in detail. At the same time, we will go deep into the background of celllayout to find out exactly what celllayout is...

 

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.