Android Launcher研究之桌面图标重命名
2011-12-28 11:44
357 查看
闲话少叙,目前原生的Launcher,只有桌面上的文件夹支持重命名。第三方软件如ADW,GOLauncher等长按桌面图标之后在弹出的popup框中也有了重命名选项。本文意在给出此功能实现的demo,如果你有不同的观点,也请多多指教。
1.获取桌面图标的信息。
当我们长按桌面图标时,会执行Workspace.java中的方法 startDrag(CellLayout.CellInfo cellInfo),其参数cellInfo即为操作对象。
过程分析:添加到桌面上的app图标,数组会保存其相应信息CellInfo。长按时会响应手指移动的onInterceptTouchEvent事件,并根据移动时的坐标来与数组中的app的信息比较,若手指移动到app的桌面有效区域,app长按事件响应。
View child = cellInfo.cell;
ItemInfo info = (ItemInfo)child.getTag(); //Get the app Info
2.创建能够重命名的对话框。
对话框的作用是为了记录输入,并将其作为该图标新的名字。
EidtName = mEditInput.getText().toString();
//Get the new name
3.修改桌面图标
桌面上的app,即快捷方式,从安装包获取得Icon和Title并将其显示于桌面。
修改信息:
ShortcutInfo mShortcutInfo = (ShortcutInfo)info;
mShortcutInfo.setTitle(EidtName); //Set ShortcutInfo Title
修改名字:
View v = mWorkspace.getViewForTag(mShortcutInfo);
//Get View for ShortcutInfo
mShortcutInfo.title = EidtName;
((BubbleTextView)v).setText(EidtName); //Set View Title
补充:google提供了修改桌面快捷方式图标以及名字的接口,本文只做修改名字的分析。
4.保存数据库
LauncherModel.updateItemInDatabase(Launcher.this,mShortcutInfo);
5.重新加载
在加载桌面布局时,调用方法LauncherModel.loadWorkspace()中获取app信息getShortcutInfo();
其默认是先从包管理器中获得,而非从数据库中加载。这里要改变其加载顺序。
// from the db
if (c != null) {
info.title = c.getString(titleIndex);
}
// from the resource
if (info.title == null) {
if (resolveInfo != null) {
info.title = resolveInfo.activityInfo.loadLabel(manager);
}
}
关键代码已全部贴出,欢迎各位多多指教!转载请注明作者和出处,谢谢!
1.获取桌面图标的信息。
当我们长按桌面图标时,会执行Workspace.java中的方法 startDrag(CellLayout.CellInfo cellInfo),其参数cellInfo即为操作对象。
过程分析:添加到桌面上的app图标,数组会保存其相应信息CellInfo。长按时会响应手指移动的onInterceptTouchEvent事件,并根据移动时的坐标来与数组中的app的信息比较,若手指移动到app的桌面有效区域,app长按事件响应。
View child = cellInfo.cell;
ItemInfo info = (ItemInfo)child.getTag(); //Get the app Info
2.创建能够重命名的对话框。
对话框的作用是为了记录输入,并将其作为该图标新的名字。
EidtName = mEditInput.getText().toString();
//Get the new name
3.修改桌面图标
桌面上的app,即快捷方式,从安装包获取得Icon和Title并将其显示于桌面。
修改信息:
ShortcutInfo mShortcutInfo = (ShortcutInfo)info;
mShortcutInfo.setTitle(EidtName); //Set ShortcutInfo Title
修改名字:
View v = mWorkspace.getViewForTag(mShortcutInfo);
//Get View for ShortcutInfo
mShortcutInfo.title = EidtName;
((BubbleTextView)v).setText(EidtName); //Set View Title
补充:google提供了修改桌面快捷方式图标以及名字的接口,本文只做修改名字的分析。
4.保存数据库
LauncherModel.updateItemInDatabase(Launcher.this,mShortcutInfo);
5.重新加载
在加载桌面布局时,调用方法LauncherModel.loadWorkspace()中获取app信息getShortcutInfo();
其默认是先从包管理器中获得,而非从数据库中加载。这里要改变其加载顺序。
// from the db
if (c != null) {
info.title = c.getString(titleIndex);
}
// from the resource
if (info.title == null) {
if (resolveInfo != null) {
info.title = resolveInfo.activityInfo.loadLabel(manager);
}
}
关键代码已全部贴出,欢迎各位多多指教!转载请注明作者和出处,谢谢!
相关文章推荐
- Launcher研究之桌面图标重命名
- Android桌面快捷方式图标生成与删除,使用Intent与launcher交互
- Android 4.0 Launcher2源码分析——桌面快捷图标的拖拽
- Android桌面快捷方式图标生成与删除,使用Intent与launcher交互
- Android 4.0 Launcher2源码分析——桌面快捷图标的拖拽
- android 6.0,为何Launcher3桌面和主菜单图标字体大小不跟随系统发生变化?
- Android Launcher桌面图标显示数字
- 说说Android桌面(Launcher应用)背后的故事(六)——研究Launcher而实现的附属品(可以拖拽的ListView)
- Android 4.0 Launcher2源码分析——桌面快捷图标的拖拽
- 关于Android类似qq和微信那种在桌面图标右上角更新数字的研究
- android 6.0,为何Launcher3桌面和主菜单图标字体大小不跟随系统发生变化?
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- 一步步客制化Android桌面(Launcher3)图标
- [高级]Android Launcher研究(一)-----------图文详解手把手教你在Windows环境下下载Android源码(Launcher为例)Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- 说说Android桌面(Launcher应用)背后的故事(六)——研究Launcher而实现的附属品(可以拖拽的ListView)
- Android 3d TOS Launcher 之桌面图标主题加框规格化
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!
- Android 4.0 Launcher2源码分析——桌面快捷图标的拖拽
- Android Launcher研究(四)-----------桌面应用快捷方式的开发!