launcher绑定view事件
- Launcher.onCreate()->
- (1) LauncherAppState app = LauncherAppState.getInstance(this);
获取getInstance单例,构造LauncherModel传入IconCache和IntentFilter filter放入 mBgAllAppsList并将LauncherAppState给mAPP;
- (2) mModel = app.setLauncher(this);
为launcher设置监听,
LauncherAppState调用内部LauncherModel类型的mMode的initialize()方法将launcher作为callback加入mModel的WeakReference mCallbacks中
并且返回mModel;
- int currentScreen = PagedView.INVALID_RESTORE_PAGE;
值是-1001
- (3) mModel.startLoader(currentScreen);
- LauncherModel.startLoader(int synchronousBindPage)返回值boolean->
- (1) LoaderResults loaderResults = new LoaderResults(mApp, sBgDataModel,mBgAllAppsList, synchronousBindPage, mCallbacks);
- 所需变量sBgDataModel类加载的时候初始化,synchronousBindPage是方法调用传入;
在LancherAppState的构造方法中调用LauncherModel构造方法传入mApp(LauncherAppState)和mBgAllAppsList,
LancherAppState调用LauncherModel的initialize传入mCallbacks;
- (2)startLoaderForResults(loaderResults);
- 因为mModelLoaded默认是false所以调用;
- LoaderResults.startLoaderForResults(LoaderResults results)->
清空mLoaderTask并停止旧的,mLoaderTask = new LoaderTask(mApp, mBgAllAppsList, sBgDataModel, results);然后执行它
- new LoaderTask()->
将mApp、mBgAllAppsList、mBgDataModel、mResults = results;
并获取以下实例
mLauncherApps = LauncherAppsCompat.getInstance(mApp.getContext());
mUserManager = UserManagerCompat.getInstance(mApp.getContext());
mShortcutManager = DeepShortcutManager.getInstance(mApp.getContext());
mPackageInstaller = PackageInstallerCompat.getInstance(mApp.getContext());
mAppWidgetManager = AppWidgetManagerCompat.getInstance(mApp.getContext());
mIconCache = mApp.getIconCache();
//来自LauncherAppState,提供icon获取主要来自 IconProvider IconDB mPackageManager
//mPackageManager是获取应用resources对应id图片
//为DB获取提供本地缓存
- LoaderTask.run()->
因为mStopped默认false所以开始下面的流程
- (1) 创建自动关闭流LauncherModel.LoaderTransaction,
并将自己传入,用于判断是否操作当前对象;
- (2) 调用loadWorkspace()
主要看synchronized (mBgDataModel){}大括号内代码
mBgDataModel.clear()
清除mBgDataModel内部所以缓存
mPackageInstaller.updateAndGetActiveSessionCache()
获取已安装信息
mFirstScreenBroadcast = new FirstScreenBroadcast(installingPkgs);
新建第一个屏幕的广播
mBgDataModel.workspaceScreens.addAll(LauncherModel.loadWorkspaceScreensDb(context))
工作屏幕id
final LoaderCursor c = new LoaderCursor(contentResolver.query(
LauncherSettings.Favorites.CONTENT_URI, null, null, null, null), mApp);
获取桌面快捷图标信息,
然后循环游标获取,标记当前删除或者更新对应内容,
然后把属性封装各种类型的info装入mBgDataModel,当前元素最多是一种info:
ShortcutInfo, SessionInfo(会被转成ShortcutInfo) FolderInfo, LauncherAppWidgetInfo
- (3) mResults.bindWorkspace()
mBgDataModel的ItemInfo、LauncherAppWidgetInfo、屏幕Id放到本地各自的list当中
按照当前屏幕把itemInfo和LauncherAppWidgetInfo各自分成current和other两个list
然后筛选当前屏幕的itemInfo和LauncherAppWidgetInfo
排序当前iteminfo和otheriteminfo
在MainThreadExecutor中执行调用callbacks.startBinding()的Runnable,做清空和刷新操作
在MainThreadExecutor中执行调用callbacks.bindScreens(orderedScreenIds)的Runnable,绑定屏幕id到Workspace
然后绑定快捷图标和部件到当前页bindWorkspaceItems(currentWorkspaceItems, currentAppWidgets, mainExecutor)
/packages/apps/Launcher3/src/com/android/launcher3/Launcher.java
获取final Executor deferredExecutor =
validFirstPage ? new ViewOnDrawExecutor() : mainExecutor;
在MainThreadExecutor中执行调用
callbacks.finishFirstPageBind(validFirstPage ? (ViewOnDrawExecutor) deferredExecutor : null)的Runnable,如果需要立马显示第一个屏幕就不执行属性动画直到它的ondraw方法完成,否则执行动画
绑定快捷图标和部件到页面bindWorkspaceItems(otherWorkspaceItems, otherAppWidgets, deferredExecutor)
主要分析点击事件是如何绑定所以就到这里----------------
- mResults.bindWorkspace()
将callbacks.bindItems(workspaceItems.subList(start, start+chunkSize), false)的runnable放入调度器执行
- Launcher.bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons)
当item.itemType是下面这三种时:
LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
获取WorkspaceItemInfo info = (WorkspaceItemInfo) item;
然后调用view = createShortcut(info);
- createShortcut(info)调用了
createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info)
createShortcut(ViewGroup parent, WorkspaceItemInfo info)
最终给BubbleTextView绑定了onclick事件
public View createShortcut(ViewGroup parent, WorkspaceItemInfo info) {
BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext())
.inflate(R.layout.app_icon, parent, false);
favorite.applyFromWorkspaceItem(info);
favorite.setOnClickListener(ItemClickHandler.INSTANCE);
favorite.setOnFocusChangeListener(mFocusHandler);
return favorite;
}
网友评论