在前面我的blog中,我已经说过了,Launcher所有的桌面项数据是存储在launcher.db/favorites表中
在Launcher启动时loadeworkspace函数中会从数据库中查询所有的数据并显示出来,这个桌面项数据加载过程在我的blog Launcher——启动过程详解中有比较详细的描述,这篇blog,我着重讲述Launcher桌面项的添加,变更和删除,下面就进入主题
1.Launcher桌面项的添加:从用户操作的角度来看,我们有两种方式来添加桌面项
--1.从all app view中拖到桌面,从下面的调用堆栈知道最后通过LauncherProvider.insert把拖过来的桌面项添加到了桌面,在拖放结束时执行(launcher2.Workspace.onDrop).
at com.android.launcher2.LauncherProvider.insert(LauncherProvider.java:129)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:174)
at android.content.ContentResolver.insert(ContentResolver.java:587)
at com.android.launcher2.LauncherModel.addItemToDatabase(LauncherModel.java:242)
at com.android.launcher2.LauncherModel.addOrMoveItemInDatabase(LauncherModel.java:133)
at com.android.launcher2.Workspace.onDropExternal(Workspace.java:1203)
at com.android.launcher2.Workspace.onDropExternal(Workspace.java:1165)
at com.android.launcher2.Workspace.onDrop(Workspace.java:1125)
--2.通过长按桌面打开一个dialog来添加桌面项,通过对象框添加最后调用同样的方法LauncherProvider.insert去实现操作,只是前面的发起动作不同,它是在选择应用的activity结束后回到Launcher.onActivityResult发起调用的。
at com.android.launcher2.LauncherProvider.insert(LauncherProvider.java:129)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:174)
at android.content.ContentResolver.insert(ContentResolver.java:587)
at com.android.launcher2.LauncherModel.addItemToDatabase(LauncherModel.java:242)
at com.android.launcher2.LauncherModel.addOrMoveItemInDatabase(LauncherModel.java:133)
at com.android.launcher2.Workspace.onDropExternal(Workspace.java:1203)
at com.android.launcher2.Workspace.addApplicationShortcut(Workspace.java:1117)
at com.android.launcher2.Launcher.completeAddApplication(Launcher.java:931)
at com.android.launcher2.Launcher.onActivityResult(Launcher.java:579)
2.Launcher桌面项的变更:Launcher桌面项的变更只有我们拖动桌面项,改变桌面项的位置,当结束拖放时,会通过调用LauncherProvider.update函数来修改launcher.db/favorites表中的记录来变更桌面项的位置信息。
at com.android.launcher2.LauncherProvider.update(LauncherProvider.java:185)
at android.content.ContentProvider$Transport.update(ContentProvider.java:204)
at android.content.ContentResolver.update(ContentResolver.java:707)
at com.android.launcher2.LauncherModel.moveItemInDatabase(LauncherModel.java:159)
at com.android.launcher2.Workspace.onDrop(Workspace.java:1144)
3.Launcher桌面项的删除:把桌面项拖动到垃圾箱时执行,不多说什么了,给个调用堆栈一看就明白,DeleteZone就是垃圾箱对象对应的构造类
at com.android.launcher2.LauncherProvider.delete(LauncherProvider.java:168)
at android.content.ContentProvider$Transport.delete(ContentProvider.java:198)
at android.content.ContentResolver.delete(ContentResolver.java:675)
at com.android.launcher2.LauncherModel.deleteItemFromDatabase(LauncherModel.java:271)
at com.android.launcher2.DeleteZone.onDrop(DeleteZone.java:123)