Android launcher Analyze and modify 1--launcher default interface configuration (Default_workspace)

Source: Internet
Author: User

Recently work has been modified launcher, so intends to analyze the source code and modify the source of the process of recording down, recently will write some analysis of launcher and modify blog post. Because I was modified 4.0.3 launcher, so the launcher in the later articles are based on Android4.0.3 Launcher2 modification. Launcher source more, and the application of a lot of design patterns, to analyze it clearly to spend a lot of energy, there are some fragmentary analysis on the internet, but there are not many articles on the revision. So I'm going to write some analysis and modify launcher combined articles.

Original blog, reproduced please indicate the source: http://www.cnblogs.com/mythou/p/3153880.html

Today is primarily an analysis of how the default interface for modifying launcher is configured and modified. Launcher modification is only recently started, the following two images are the results of the most recent changes. Because the program is used for vehicle navigation, so the interface and the general phone interface is very different. The changes are also large, but the analysis and modification of launcher are common.

This is based on the Android4.0.3 Modified Launcher interface, because the program is used in the car navigation, so the icon has been enlarged operation. Removed something that was not needed.

The following is an analysis of where the interface is modified.

1. Interface default configuration file

When the machine was just upgraded, the interface of launcher is to read an XML configuration file by default and complete the configuration work. This configuration file is in the Launcher directory,

The path is: \launcher\res\xml\default_workspace.xml. This XML file is the configuration file that was just upgraded, launcher the first time it was displayed.

Default_workspace. In XML, you can configure app shortcuts, widgets, search fields, and more. Here are some of the commonly used properties to parse:

Edited by Mythou
http://www.cnblogs.com/mythou/
Shortcut description <favorite  //Program shortcut key property label    Launcher:classname= "Com.apical.radio.radioMainActiv ity "    //The app's class, click on the icon when you need to launch the class    launcher:packagename=" Com.apical.radio "   //The app's package name    Launcher: screen= "1"           //1th screen, 0-4 screen total 5 screen    launcher:x= "0"                   //icon x position, upper left corner first 0, right increment, 0-4 total 5    l 0auncher:y= "0"            //Icon y position, upper left corner first is 0, down increments, 0-2 total 3   
/>

Launcher default is 5 sub-screen, but this can be configured. Similarly, the number of icons per row per column is configurable, and this will say where you can modify it later. Here, I modified the interface arrangement for 3 rows and 5 columns (corresponding to the above). A shortcut to the General Configuration app, using the Properties tab above.

Edited by Mythou
http://www.cnblogs.com/mythou/
Tags for desktop widgets
<appwidget//Plugin    launcher:classname= "De.dnsproject.clock_widget_main. Clock1appwidgetprovider "  //class of the application    launcher:packagename=" De.dnsproject.clock_widget_main "      // The app's package name    launcher:screen= "1"             //1th screen, 0-4 screen total 5 screen    launcher:x= "2"                      //icon x position, the upper left corner of the first 0, left increment, 0-4 total 5    launcher:y= "1"                                                 //Icon y position, upper left corner first is 0, downward increment, 0-2 total 3    launcher:spanx= "3"                                             //the number of cells in the x direction    launcher:spany= "2"/>                                          //number of cells in the Y direction        

Desktop widgets and desktop shortcut property types, but it is important to note that the two properties of Launcher:spanx and Launcher:spany are the size of the widget, which is related to the widget's minimum width-height configuration. When we write a desktop widget, we need to specify the minimum width and height of the widget in the XML configuration file, the general minimum width and height calculation formula (MinWidth = 72* of the number of cells-2) calculated, the minimum height is the same. (The analog clock above is MIUI's clock)

MinWidth = 72* occupies 2 The number of cells in the grid is the amount of Launcher:spanx and Launcher:spany configured above. For the above, is occupied 3 horizontal lattice, 2 vertical lattice. MinWidth should be equal to 214.

<search                //Search bar launcher:screen= "1"  //2nd screen launcher:x= "0"                    //icon x position launcher:y= "1"/>                  // Icon y position 

This is the configuration of the search bar, because I do not need to use the search bar here, so remove it, if you need to configure the above attribute tag can be used.

As for the folder, in the 4.0 launcher is supported, analysis of the load function inside, you can find a way to resolve the folder label.

The default configuration for the above interface is to modify the Default_workspace.xml configuration by using the tabs above.

The following lists the tags and attributes supported by Default_workspace:

Edited by Mythou
http://www.cnblogs.com/mythou/
In Default_workspace.xml, the supported tags are: favorite: Application Shortcuts. Shortcut: links, such as URLs, local disk paths, and so on. Search: Searching box. Clock: Clock on the table widget//supported properties are: Launcher:title: The text below the icon, currently only supports references, not directly write the string; Launcher:icon: Icon reference; Launcher:uri: Link Address, For a link URL, you can use the shortcut tag to define a hyperlink that opens a URL. Launcher:packagename: The application's package name; Launcher:classname: The application's startup class name; Launcher:screen: the screen number on which the icon is located; launcher:x: The sequence number of the icon in the horizontal arrangement; Launcher:y: The number of icons in the vertical arrangement;

The method of parsing the Default_workspace.xml file inside the launcher is the Loadfavorites method inside the Launcherprovider.java.

2, loadfavorites analysis of Launcherprovider.java:

Edited by Mythou
http://www.cnblogs.com/mythou/
The resource ID and database strength of the incoming Default_workspace file, parse the data inside the XML and save it to the launcher database. Returns the total number of tags parsed.
private int loadfavorites (sqlitedatabase db, int workspaceresourceid) {
//.........
int type; while ((type = Parser.next ())! = Xmlpullparser.end_tag | | Parser.getdepth () > Depth) && type! = xmlpullparser.end_document)
         {if (type! = Xmlpullparser.start_tag) {continue; } Boolean added = false; Final String name = Parser.getname (); TypedArray a = Mcontext.obtainstyledattributes (Attrs, r.styleable.favorite); Long container = LauncherSettings.Favorites.CONTAINER_DESKTOP; if (A.hasvalue (R.styleable.favorite_container)) {container = Long.valueof (a.getstring. Favorite_container)); } String screen = a.getstring (R.styleable.favorite_screen); String x = a.getstring (r.styleable.favorite_x); String y = a.getstring (r.styleable.favorite_y); If we are adding to the hotseat, the screens is used as the position in the//hotseat. This screen can ' t being at position 0 because AllApps are in the Zeroth position. if (container = = LauncherSettings.Favorites.CONTAINER_HOTSEAT && integer.valueof (screen ) = = Allappsbuttonrank) {throw new RuntimeException ("Invalid screen position for hotseat item"); } values.clear (); Values.put (LauncherSettings.Favorites.CONTAINER, CONTAINER); Values.put (LauncherSettings.Favorites.SCREEN, screen); Values.put (LauncherSettings.Favorites.CELLX, x); Values.put (LauncherSettings.Favorites.CELLY, y);
Parse the tags inside the XML, where you can find the supported tag types and related attribute parameters. if (tag_favorite.equals (name)) {Long id = addappshortcut (db, values, a, packagemanager, intent); Added = ID >= 0; } else if (tag_search.equals (name)) {added = Addsearchwidget (db, values); } else if (tag_clock.equals (name)) {added = Addclockwidget (db, values); } else if (tag_appwidget.equals (name)) {added = Addappwidget (parser, attrs, type, db, values, a, p Ackagemanager); } else if (tag_shortcut.equals (name)) {Long id = addurishortcut (db, values, a); Added = ID >= 0; } else if (tag_folder.equals (name))
{             //.........
The folder property has more than 2 parameters in order to form folders. if (Folderitems.size () < 2 && FolderID >= 0) {//We just delete the folder and a NY items that made it Deleteid (db, FolderID); if (folderitems.size () > 0) {deleteid (db, Folderitems.get (0)); } added = false; }} if (added) i++; A.recycle (); }
//.........
return i; }

In fact, is a process of parsing XML and writing to the database, Launcherprovider.java is the entire launcher data source, it is very important, I then specifically analyze the data loading and adaptation display logic.

There is also a question to add, is about the Android problem, because I developed the machine can not use USB debugging, and do not shake the sensor, a lot of mobile phone methods are not used, checked, you can use the Screencap command, Specific methods can refer to my other article: http://www.cnblogs.com/mythou/p/3152627.html

For the icon to add the default background or to cast the app shortcut icon, modify the icon size and number of rows, and how to configure the default background, and then write another article description tomorrow.

If a friend found out where the wrong write, please leave a message, thank you!

Android launcher Analyze and modify 1--launcher default interface configuration (Default_workspace)

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.