Android launcher analysis and Modification 1 -- default Interface Configuration of launcher (default_workspace)

Source: Internet
Author: User

I have been modifying launcher recently, so I plan to record the process of analyzing and modifying the source code. Recently I will write some blog posts about launcher analysis and modification. Because I modified the launcher of 4.0.3ArticleThe launcher is based on the launcher2 modification of android4.0.3. Launcher has a lot of source code, and many design patterns are applied in it. It takes a lot of effort to analyze it clearly. There are also some fragmented analysis articles on the Internet, but there are not many articles on modification. So I plan to write some articles that combine analysis and modification of launcher.

For original blog posts, indicate the source:Http://www.cnblogs.com/mythou/p/3153880.html

Today, we mainly analyze how to configure and modify the default Interface of launcher. The launcher modification started only recently. The following two images are the results of the latest modification. BecauseProgramIt is used for car navigation devices, so the interface is very different from the general mobile phone interface. The changes are also relatively large, but the modifications to the launcher analysis are common.

This is based on the launcher interface modified by android4.0.3. Because the program is used in vehicle navigation, the icon is enlarged. Deleted unnecessary things.

The following is an analysis of the page modifications.

 

1. default configuration file on the Interface

When the machine is upgraded, the launcher interface reads an xml configuration file by default to complete the configuration. The configuration file is in the launcher directory,

Path: \ launcher \ res \ XML \ default_workspace.xml. This XML file is the configuration file that will be read when launcher displays it for the first time.

Default_workspace. You can configure app shortcuts, widgets, and search bar in XML. The following describes the commonly used attributes:

 

 
 
 
// Edited by mythou
//Http://www.cnblogs.com/mythou/
 Shortcuts <Favorite //  Program shortcut key property tag Launcher: classname ="  Com. apical. Radio. radiomainactivity  "  //  Class of the application. The class to be started when you click the icon Launcher: packagename = "  Com. apical. Radio  "  //  Package name of the application Launcher: screen = "  1  "  // 1st screens and 5 0-4 screens Launcher: x = "  0  "  //  Position X of the icon. The first value in the upper left corner is 0, which increments to the left. Five values are displayed in total: 0-4. L0auncher: Y = "  0  "  //  The Y position of the icon. The first one in the upper left corner is 0, which increments downward. There are 3 in total: 0-2.
/>

Launcher has five split screens by default, but this can be configured. Similarly, you can configure the number of icons in each column of each row. This will be explained later on where the icons can be modified. Here, I modified the page layout of three rows and five columns (corresponding to the above ). Generally, you can configure the app shortcut by using the property tag above.

 

 
// Edited by mythou
//Http://www.cnblogs.com/mythou/
 
// Desktop widget label
<Appwidget //  Plug-ins Launcher: classname = "De. dnsproject. clock_widget_main.clock1appwidgetprovider  "    // Application class Launcher: packagename = "De. dnsproject. clock_widget_main  "  //  Package name of the application Launcher: screen = "  1  "  //  1st screens and 5 0-4 screens Launcher: x = "  2  "  //  Position X of the icon. The first value in the upper left corner is 0, which increments to the left. Five values are displayed in total: 0-4. Launcher: Y = "  1  "                                                   //  The Y position of the icon. The first one in the upper left corner is 0, which increments downward. There are 3 in total: 0-2. Launcher: Spanx = "3  "                                               //  Number of cells in the X direction Launcher: spany = "  2  " />//  Number of cells in the Y direction 

The desktop widget and the desktop shortcut property type. However, you must note that the attributes Launcher: Spanx and Launcher: spany indicate the size of the widget, which is related to the minimum width and height configuration of the widget. When writing a desktop widget, We need to specify the minimum width and height of the widget in the XML configuration file. The general formula for calculating the minimum width and height is (minwidth = 72 * Number of occupied cells-2) the minimum height is also the same. (The above analog clock is the miui clock)

Minwidth = 72 * Number of occupied cells-the number of occupied cells in 2 is the number configured by Launcher: Spanx and Launcher: spany. For the above, three horizontal grids and two vertical grids are occupied. Minwidth must be 214.

 

<Search//Search barLauncher: screen ="1"//2nd screensLauncher: x ="0"//Icon X positionLauncher: 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 I removed it. If you need to configure it, you can use the above attribute label.

 

 

As for folders, they are supported in launcher 4.0. In the analysis and loading function, you can find the method for parsing folder labels.

The default configuration on the Interface above is to modify the default_workspace.xml configuration by using the above label.

The following lists the labels and attributes supported by default_workspace:

 
 
 
// Edited by mythou
//Http://www.cnblogs.com/mythou/
// In default_workspace.xml, the supported labels are:Favorite: Application shortcut. Shortcut cut: links, such as URLs and local disk paths. Search: search box. Clock: clock widget on the desktop// Supported attributes include:Launcher: Title: The text under the icon. Currently, only references are supported. Strings cannot be written directly. Launcher: icon reference; Launcher: URI: link address, URL used.The shortcut label defines a hyperlink to open a URL.Launcher: packagename: package name of the application; Launcher: classname: startup Class Name of the application; Launcher: screen number of the icon; Launcher: X: serial number of the icon in the horizontal arrangement; Launcher: Y: Serial number of the icon in the vertical arrangement;

The method for parsing the default_workspace.xml file in launcher is the loadfavorites method in launcherprovider. java.

 

2. loadfavorites Analysis of launcherprovider. Java:

// Edited by mythou
//Http://www.cnblogs.com/mythou/
// Input the resource ID and database strength of the default_workspace file, parse the data in the XML file, 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 = Mcontext. obtainstyledattributes (attrs, R. styleable. Favorite ); Long Container =Launchersettings. favorites. container_desktop; If (A. hasvalue (R. styleable. favorite_container) {container = Long. valueof (A. getstring (R. styleable. 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 screen is used as the position in // Hotseat. This screen can't be at position 0 because allapps is in // Zeroth position. If (Container = Launchersettings. favorites. container_hotseat & Amp; 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 labels in XML. The supported tag types and related attribute parameters can be found here. 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, packagemanager );} Else If (Tag_shortcut.equals (name )){ Long Id = Addurishortcut (dB, values, a); added = ID> = 0 ;} Else If (Tag_folder.equals (name ))
{//.........
// Folder can be formed only when there are more than two parameters in the folder attribute. If (Folderitems. Size () < 2 & Amp; folderid & gt; = 0 ){ // We just delete the folder and any 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, it is a process of analyzing XML and writing data into the database. launcherprovider. Java is the data source of the entire launcher and is very important. I will analyze the data loading and configuration display logic later.

There is another question to be added, that is, the android issue, because the machines I developed cannot use USB debugging and there is no shaking or other sensors. Many mobile phones cannot use the above method. I checked it, you can use the screencap command. For details, refer to my other article:Http://www.cnblogs.com/mythou/p/3152627.html

 

Add the icon to the default background or forcibly convert the app shortcut icon, modify the Icon size and number of rows and columns, configure the Default background, and write another article tomorrow.

If a friend finds out what is wrong, leave a message to point out. Thank you!

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.