Launcher3源码分析 — 将Workspace的数据与界面绑定
来源:互联网 发布:安卓慢动作拍摄软件 编辑:程序博客网 时间:2024/06/07 03:18
在数据从数据库加载到内存之后,接下来的工作就是把这些数据与launcher的UI视图绑定。绑定的过程在LauncherModel.bindWorkspace()方法中完成,在这个方法中会调用回调接口Callback里相应的回调方法。
Callback接口的定义如下:
public interface Callbacks { public boolean setLoadOnResume(); public int getCurrentWorkspaceScreen(); public void startBinding(); public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end, boolean forceAnimateIcons); public void bindScreens(ArrayList<Long> orderedScreenIds); public void bindAddScreens(ArrayList<Long> orderedScreenIds); public void bindFolders(HashMap<Long,FolderInfo> folders); public void finishBindingItems(boolean upgradePath); public void bindAppWidget(LauncherAppWidgetInfo info); public void bindAllApplications(ArrayList<AppInfo> apps); public void bindAppsAdded(ArrayList<Long> newScreens, ArrayList<ItemInfo> addNotAnimated, ArrayList<ItemInfo> addAnimated, ArrayList<AppInfo> addedApps); public void bindAppsUpdated(ArrayList<AppInfo> apps); public void bindComponentsRemoved(ArrayList<String> packageNames, ArrayList<AppInfo> appInfos, boolean matchPackageNamesOnly); public void bindPackagesUpdated(ArrayList<Object> widgetsAndShortcuts); public void bindSearchablesChanged(); public boolean isAllAppsButtonRank(int rank); public void onPageBoundSynchronously(int page); public void dumpLogsToLocalData(); }
通过方法名我们大概可以猜到每个回调方法的作用,因为Launcher类(Main Activity)实现了该接口,并作为参数传递给了LauncherModel的mCallback,所以bindWorkspace的过程就是通过回调,一步步地通知Launcher类进行相应界面和相应数据的绑定。
bindWorkspace的过程如下:
1.将items分为current和other
ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<ItemInfo>();ArrayList<ItemInfo> otherWorkspaceItems = new ArrayList<ItemInfo>();ArrayList<LauncherAppWidgetInfo> currentAppWidgets = new ArrayList<LauncherAppWidgetInfo>();ArrayList<LauncherAppWidgetInfo> otherAppWidgets = new ArrayList<LauncherAppWidgetInfo>();HashMap<Long, FolderInfo> currentFolders = new HashMap<Long, FolderInfo>();HashMap<Long, FolderInfo> otherFolders = new HashMap<Long, FolderInfo>();// Separate the items that are on the current screen, and all the other remaining itemsfilterCurrentWorkspaceItems(currentScreen, workspaceItems, currentWorkspaceItems, otherWorkspaceItems);filterCurrentAppWidgets(currentScreen, appWidgets, currentAppWidgets, otherAppWidgets);filterCurrentFolders(currentScreen, itemsIdMap, folders, currentFolders, otherFolders);sortWorkspaceItemsSpatially(currentWorkspaceItems);sortWorkspaceItemsSpatially(otherWorkspaceItems);
先绑定当前页面的数据,再绑定其他页面,从而提供更好的用户体验。
// Tell the workspace that we're about to start binding items r = new Runnable() { public void run() { Callbacks callbacks = tryGetCallbacks(oldCallbacks); if (callbacks != null) { callbacks.startBinding(); } } }; runOnMainThread(r, MAIN_THREAD_BINDING_RUNNABLE);完成绑定前的初始化工作。
3.调用bindScreens()
final Runnable r = new Runnable() { @Override public void run() { Callbacks callbacks = tryGetCallbacks(oldCallbacks); if (callbacks != null) { callbacks.bindScreens(orderedScreens); } } }; runOnMainThread(r, MAIN_THREAD_BINDING_RUNNABLE);完成screen的初始化。
4.加载当前页面的item
bindWorkspaceItems(oldCallbacks, currentWorkspaceItems, currentAppWidgets, currentFolders, null);
bindWorkspaceItems(oldCallbacks, otherWorkspaceItems, otherAppWidgets, otherFolders, (isLoadingSynchronously ? mDeferredBindRunnables : null));
6.调用finishBindingItems()
// Tell the workspace that we're done binding items r = new Runnable() { public void run() { Callbacks callbacks = tryGetCallbacks(oldCallbacks); if (callbacks != null) { callbacks.finishBindingItems(isUpgradePath); } mIsLoadingAndBindingWorkspace = false; } }; runOnMainThread(r, MAIN_THREAD_BINDING_RUNNABLE);
以上是Workspace数据绑定的步骤,Launcher类通过回调在每个步骤中完成相应的UI渲染工作。
0 0
- Launcher3源码分析 — 将Workspace的数据与界面绑定
- Launcher3源码分析 — 加载Workspace的数据
- Launcher3源码分析 — 加载Workspace的数据
- Launcher3源码分析 — 加载Workspace的数据 .
- Launcher3源码分析(Workspace)
- Launcher3源码分析 — 所有应用页面的数据加载和绑定
- Launcher3源码分析 — 主界面的UI结构
- Launcher3的workspace滑动分析
- Launcher3源码分析 — 数据加载过程
- Launcher3源码分析 — 数据加载过程
- Launcher3源码分析(LauncherModel加载数据)
- Android Launcher3源码分析与修改
- Launcher3源码分析 — bindScreen的具体实现
- Launcher3源码分析 — bindWorkspaceItems的具体实现
- Launcher3 Workspace的高度调节
- Launcher3源码浅析(5.1)--Workspace
- Launcher3源码分析——去掉cling
- Launcher3源码分析 — ui结构
- [2014-03-07]JAVA笔记_继承、方法重写
- XML概述
- set autotrace常用操作
- 数据存储-Content Providers(内容提供者)和Uri详解
- ntfs 格式在linux下挂载
- Launcher3源码分析 — 将Workspace的数据与界面绑定
- Java关键字transient和volatile
- 21世纪初最有影响力的20篇计算机视觉期刊论文
- UITextField详解
- 绘制图形
- 谷歌的安卓平台将不会为企业用户使用
- 网页专属名词释疑解惑
- 5款替代微软Visio的开源免费软件
- 链表倒数第k个节点