android launcher开发之图标背景以及默认配置

1:然后我自己看了一下桌面图标的载入过程:
桌面第一次载入时是默认读取一个xml配置文件,完毕配置工作。这个配置文件在Launcher文件夹下,
路径是:\Launcher\res\xml\default_workspace.xml 。这个XML文件就是刚升级,Launcher第
一次显示的时候,会读取的配置文件。default_workspace。xml里面能够配置APP快捷方式、Widget、Search搜索栏等




launcher里面负责解析default_workspace.xml文件的方法是 LauncherProvider.java里面的loadFavorites方法
LauncherProvider.java里面有loadFavorites()这种方法:
     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;
        }


事实上就是一个分析XML和写入数据库的过程,LauncherProvider.java是整个Launcher的数据来源,
知道这些图标怎样载入出来之后对做屏幕是坏 改动背景大小  行列等都有优点。










2:Launcher 图标增加默认背景。是主题功能的一个小部分也是必不可少的一部分,以下是我今天整理的一些逻辑和代码,Launcher图标的获取处理是在Utilities.java类里面,
我们能够从里面找到Bitmap createIconBitmap(Drawable icon, Context context) 方法。这种方法就是返回应用图标的。
     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);
        }
    }
  能够在这里改动图标的背景 能够增加  
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);
                }
            }


直接指定一个图片为图标背景 R.drawable.apical_icon_bg;












   
posted @ 2014-08-07 09:50  mengfanrong  阅读(949)  评论(0编辑  收藏  举报