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;
桌面第一次加载时是默认读取一个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;
相关文章推荐
- android launcher开发之图标背景以及默认配置
- Android Launcher分析和修改——Launcher默认界面配置以及其他的事项
- Android开发中Launcher3常见默认配置修改方法总结
- andriod开发 1:android在Linux下的环境配置以及编译设置介绍
- Android Launcher分析和修改1——Launcher默认界面配置(default_workspace)
- Android开发环境配置以及开发相关资料和工具准备
- Android Launcher分析和修改1——Launcher默认界面配置(default_workspace)
- iOS开发UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
- 开发Android应用程序时改变了图标,但是重新启动依旧是默认的图标
- java Android SDK安装与环境变量配置以及开发第一个Android程序
- 【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
- Android Launcher分析和修改1——Launcher默认界面配置(default_workspace)
- Android源码开发----usb调试的开关以及系统配置信息
- MAC下配置android开发环境以及运行cocos2dx项目
- Android背景介绍以及开发环境搭
- 配置基于MyEclipse 8的Android 2.1开发环境(详细)以及Hello World
- Android开发SDK配置以及相关问题的解决
- 如何安装Android开发工具以及配置
- Android 开发,应用的图标已经换了,运行的时候还是默认的安卓机器人
- Android Launcher分析和修改1——Launcher默认界面配置(default_workspace)