zoukankan      html  css  js  c++  java
  • android launcher开发之图标背景以及默认配置

    1:然后我自己看了一下桌面图标的载入过程:
    桌面第一次载入时是默认读取一个xml配置文件,完毕配置工作。这个配置文件在Launcher文件夹下,
    路径是:Launcher esxmldefault_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;












       
  • 相关阅读:
    php与js 编码解码交互
    计算每页个数算法
    线程合并
    Sql调试
    并发问题
    context.Request方法总结
    元字符
    PHP留言小练习
    Git Shell Warning
    loading bar
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/3896359.html
Copyright © 2011-2022 走看看