Android Launcher development icon background and default configuration

Source: Internet
Author: User

1: And I looked at it myself. The loading process of the desktop icon:
When the desktop first loads, it reads an XML configuration file by default and completes the configuration work. This configuration file is in the Launcher directory,
The path is: \launcher\res\xml\default_workspace.xml. This XML file is just upgraded, launcher
The configuration file that will be read when it is displayed at once. Default_workspace. XML can be configured with app shortcuts, widgets, search bar, etc.




The method of parsing the Default_workspace.xml file inside the launcher is the Loadfavorites method inside the Launcherprovider.java.
Launcherprovider.java there is loadfavorites () This method:
private int loadfavorites (sqlitedatabase db, int workspaceresourceid) {
Intent Intent = new Intent (intent.action_main, NULL);
Intent.addcategory (Intent.category_launcher);
Contentvalues values = new Contentvalues ();


if (LOGD) log.v (TAG, String.Format ("Loading favorites from resid=0x%08x", Workspaceresourceid));


Packagemanager Packagemanager = Mcontext.getpackagemanager ();
int i = 0;
try {
Xmlresourceparser parser = Mcontext.getresources (). GETXML (Workspaceresourceid);
AttributeSet attrs = xml.asattributeset (parser);
Begindocument (parser, tag_favorites);


Final int depth = parser.getdepth ();


Final Hashmap<long, iteminfo[][]> occupied = new Hashmap<long, iteminfo[][]> ();
Launchermodel model = Launcherappstate.getinstance (). Getmodel ();






return i;
}


is actually a process of parsing XML and writing to a database, Launcherprovider.java is the data source for the entire launcher,
Knowing how these icons are loaded is good for making the screen bad for changing the size of the background.










The 2:launcher icon is added to the default background. is a small part of the theme function is also an indispensable portion of the following are some of the logic and code I have compiled today, the launcher icon gets processed in the Utilities.java class,
We can find bitmap createiconbitmap (drawable icon, context context) method from inside. This method returns the app icon.
Static Bitmap Createiconbitmap (Bitmap icon, context context) {
int texturewidth = Sicontexturewidth;
int textureheight = Sicontextureheight;
int sourcewidth = Icon.getwidth ();
int sourceheight = Icon.getheight ();
if (Sourcewidth > Texturewidth && sourceheight > Textureheight) {
Icon is bigger than it should be; Clip it (solves the gb->ics migration case)
Return Bitmap.createbitmap (icon,
(sourcewidth-texturewidth)/2,
(sourceheight-textureheight)/2,
Texturewidth, Textureheight);
} else if (sourcewidth = = Texturewidth && sourceheight = = textureheight) {
Icon is the right size, no need to change it
return icon;
} else {
Icon is too small, render to a larger bitmap
Final Resources resources = context.getresources ();
Return Createiconbitmap (New bitmapdrawable (resources, icon), context);
}
}
You can change the background of the icon here to join
if (tru{
Bitmap Backbitmap = Bitmapfactory.decoderesource (Context.getresources (),
R.DRAWABLE.APICAL_ICON_BG);
int backwidth = Backbitmap.getwidth ();
int backheight = Backbitmap.getheight ();
if (backwidth! = Siconwidth | | backheight! = siconheight)
{
Matrix matrix = new Matrix ();
Matrix.postscale (float) siconwidth/backwidth, (float) siconheight/backheight);
Canvas.drawbitmap (Bitmap.createbitmap (backbitmap, 0, 0, backwidth, Backheight, Matrix, True),
.0f, 0.0f, NULL);
}else
{
Canvas.drawbitmap (Backbitmap, 0.0f, 0.0f, NULL);
}
}


Directly specify a picture for the icon background R.DRAWABLE.APICAL_ICON_BG;












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.