您的位置:首页 > 移动开发 > Android开发

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

2014-07-25 15:51 281 查看
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;

   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐