Icon background and default configuration for android launcher development

Source: Internet
Author: User

Icon background and default configuration for android launcher development
1: Then I checked the desktop icon loading process myself:
When the desktop is loaded for the first time, an xml configuration file is read 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 just upgraded, Launcher
The configuration file that will be read when a display is performed. Default_workspace. You can configure APP shortcuts, widgets, and Search bar in xml.




The method for parsing the default_workspace.xml file in launcher is the loadFavorites method in LauncherProvider. java.
LauncherProvider. java contains the loadFavorites () 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 Occupied = new HashMap ();
LauncherModel model = LauncherAppState. getInstance (). getModel ();
.
.
.
.


Return I;
}


It is actually a process of XML analysis and database writing. LauncherProvider. java is the data source of the entire Launcher,
Knowing how these icons are loaded is good for modifying the background size and columns on the screen.










2: add the Default background to the Launcher icon. It is a small part of theme functions and an indispensable part. Below are some logic and code I have compiled today. The obtaining and processing of Launcher icons is in the Utilities. java class,
We can find the Bitmap createIconBitmap (Drawable icon, Context context) method. This method returns the application 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 shoshould 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 modify the background of the icon here.
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 an image as 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.