launcher3图标icon背景及文字处理

来源:互联网 发布:php 装饰者模式 编辑:程序博客网 时间:2024/06/06 06:46

   图标聚焦背景

packages\apps\Launcher3\res\drawable\focusable_view_bg.xml


   图标文字背景

packages\apps\Launcher3\src\com\android\launcher3\BubbleTextView.java



packages\apps\Launcher3\src\com\android\launcher3\Utilities.java


    static final int[] APP_ICON_BG = {  
        R.drawable.appsiconbg,  
        R.drawable.appsiconbg,  
        R.drawable.appsiconbg,  
        R.drawable.appsiconbg,  
        R.drawable.appsiconbg  
    };

 static Bitmap createIconBitmap(Drawable icon, Context context) {

        synchronized (sCanvas) { 

...

            if (debug) {
                // draw a big box for the icon for debugging
                canvas.drawColor(sColors[sColorIndex]);
                if (++sColorIndex >= sColors.length) sColorIndex = 0;
                Paint debugPaint = new Paint();
                debugPaint.setColor(0xffcccc00);
                canvas.drawRect(left, top, left+width, top+height, debugPaint);
            }


            
            if (true) 
            {
                int index = new Random(System.currentTimeMillis()).nextInt(5);

//Bitmap backBitmap = BitmapFactory.decodeResource(context.getResources(),APP_ICON_BG[index]);
                Bitmap backBitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.appsiconbg);
                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),0.0f, 0.0f, null);
                }else
                {
                    canvas.drawBitmap(backBitmap, 0.0f, 0.0f, null);
                }
            }     

...

// 如果原图标太大,看不到背景,可以把原图标缩小

            //icon.setBounds(left, top, left+width, top+height);
            icon.setBounds(left+15, top+15, left+width-15, top+height-15);

}

参考http://blog.csdn.net/xuhui_7810/article/details/36901815


0 0