Android4.0为all app图标加背景图
来源:互联网 发布:淘宝氛围图是什么样的 编辑:程序博客网 时间:2024/06/05 08:51
修改位置:Launcher2/src/com/android/launcher2/Utilities.java
/** * Returns a bitmap suitable for the all apps view. */ static Bitmap createIconBitmap(Drawable icon, Context context) { synchronized (sCanvas) { // we share the statics :-( if (sIconWidth == -1) { initStatics(context); } int width = sIconWidth; int height = sIconHeight; if (icon instanceof PaintDrawable) { PaintDrawable painter = (PaintDrawable) icon; painter.setIntrinsicWidth(width); painter.setIntrinsicHeight(height); } else if (icon instanceof BitmapDrawable) { // Ensure the bitmap has a density. BitmapDrawable bitmapDrawable = (BitmapDrawable) icon; Bitmap bitmap = bitmapDrawable.getBitmap(); if (bitmap.getDensity() == Bitmap.DENSITY_NONE) { bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics()); } } int sourceWidth = icon.getIntrinsicWidth(); int sourceHeight = icon.getIntrinsicHeight(); if (sourceWidth > 0 && sourceHeight > 0) { // There are intrinsic sizes. if (width < sourceWidth || height < sourceHeight) { // It's too big, scale it down. final float ratio = (float) sourceWidth / sourceHeight; if (sourceWidth > sourceHeight) { height = (int) (width / ratio); } else if (sourceHeight > sourceWidth) { width = (int) (height * ratio); } } else if (sourceWidth < width && sourceHeight < height) { // Don't scale up the icon width = sourceWidth; height = sourceHeight; } } // no intrinsic size --> use default size int textureWidth = sIconTextureWidth; int textureHeight = sIconTextureHeight; final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888); final Canvas canvas = sCanvas; canvas.setBitmap(bitmap); final int left = (textureWidth-width) / 2; final int top = (textureHeight-height) / 2; @SuppressWarnings("all") // suppress dead code warning final boolean debug = false; 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); } //增加背景图片int model = context.getSharedPreferences("models",Context.MODE_PRIVATE).getInt("MODEL", 0);if (model > 0) {TypedArray iconbacks = context.getResources().obtainTypedArray(R.array.iconbacks);Bitmap backBitmap = BitmapFactory.decodeResource(context.getResources(),iconbacks.getResourceId(model, R.drawable.app_back_1));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);}} sOldBounds.set(icon.getBounds()); icon.setBounds(left, top, left+width, top+height); icon.draw(canvas); icon.setBounds(sOldBounds); canvas.setBitmap(null); return bitmap; } }
- Android4.0为all app图标加背景图
- 加背景图
- ★既瑜★--为VC程序加背景图
- 为VC MDI主窗口程序加背景图
- 为控制台程序加个图标
- 为QT生成的应用程序加图标
- 为Qt程序加程序图标
- 在Listbox加背景图
- 给LISTVIEW加背景图
- 在Listbox加背景图
- 在Listbox加背景图
- 对话框加背景图
- android4.0隐藏状态栏电池图标
- android4.0隐藏状态栏电池图标
- Android4.0 修改个性化鼠标图标
- android4.0隐藏状态栏电池图标
- android4.0开机动画加音乐
- 为你的App增加托盘图标
- DWZ富客户端框架的搭建
- 浅谈C++虚基类
- 搭建ssh2框架出错---找不到class的错误ContextLoaderListener
- ARM与X86架构对比区别
- The Best Way to Learn Python-Python学习之路
- Android4.0为all app图标加背景图
- static_cast, dynamic_cast, reinterpret_cast, const_cast区别比较
- IOS开发(88)之动画之视图的移动
- 主要讨论Spring与Hibernate集成中的session问题
- 不改动已存在代码,程序退出时检测内存泄露 .
- 关于一个指针取值的问题
- 网页 折叠菜单代码
- bat实现IP切换
- 软件开发流程