Launcher8.0启动流程的第六步在workspace图标显示完成就开始准备allapp的显示。因为allapp需要点击或滑动allappButton才能打开,所以显示在workspace之后。Loadallapp是从系统获取所有的应用,然后将其显示到allapp里面。
继续bindallapp,完成了排序后,需要统计sectionname也就首字母,是用于allapp右侧的快捷栏。
Locale curLocale = mLauncher.getResources().getConfiguration().locale;
boolean localeRequiresSectionSorting = curLocale.equals(Locale.SIMPLIFIED_CHINESE);
if (localeRequiresSectionSorting) {
TreeMap<String, ArrayList<AppInfo>> sectionMap = new TreeMap<>(new LabelComparator());
for (AppInfo info : mApps) {
String sectionName = getAndUpdateCachedSectionName(info.title);
ArrayList<AppInfo> sectionApps = sectionMap.get(sectionName);
if (sectionApps == null) {
sectionApps = new ArrayList<>();
sectionMap.put(sectionName, sectionApps);
}
sectionApps.add(info);
}
mApps.clear();
for (Map.Entry<String, ArrayList<AppInfo>> entry : sectionMap.entrySet()) {
mApps.addAll(entry.getValue());
}
} else {
for (AppInfo info : mApps) {
getAndUpdateCachedSectionName(info.title);
}
}
updateAdapterItems();
}
到这里准备工作做好了,即有排序的代码已经完成,随后就是updateAdapterItems。Allapp使用recycleVIew里面的图标都属于AdapterItem。updateAdapterItems有两个方法,其中refillAdapterItems是把图标数据都存到recycleview里面,而refreshRecyclerView则是自动刷新,自动刷新后,recycleview会自动把需要显示的内容放到recycleView里面。伟大的recycleView。
private void updateAdapterItems() {
refillAdapterItems();
refreshRecyclerView();
}
进行一个小回忆,allapp第一小步从手机用user获取所有应用。第二小步,按字母排序。第三步refillAdapterItems。refillAdapterItems源码如下:
private void refillAdapterItems() {
String lastSectionName = null;
FastScrollSectionInfo lastFastScrollerSectionInfo = null;
int position = 0;
int appIndex = 0;
mFilteredApps.clear();
mFastScrollerSections.clear();
mAdapterItems.clear();
//mAdapterItems就是recycleView的内容,刷新的时候会将里面的内容刷新到桌面。首先是mAdapterItems.clear()清空里面的数据然后开始填充,首先填充的是分割线。allapp中在recycleVIew顶部,有一个搜索栏而在搜索栏和第一行应用之间有一条横线,是用于分割搜索栏的,在代码中叫做AdapterItem.asSearchDivider。
mAdapter