【源码剖析】Launcher 8.0 源码 (22) --- Launcher 启动流程 第六步之loadAllApps第2小步recycleVIew显示

本文详细剖析了Android Launcher 8.0中加载所有应用的过程,包括根据首字母进行排序、构建快捷栏,并重点讲解了如何使用RecyclerView显示应用图标。在完成准备工作后,通过`updateAdapterItems`更新Adapter内容并刷新RecyclerView,展示了应用列表。此外,还介绍了预测应用、搜索功能和深链接快捷方式的加载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值