【源码剖析】Launcher 8.0 源码 (12) --- Launcher 启动流程 第五步之计算桌面各布局细节参数

第四步主要讲解了桌面布局的创建与绑定,这篇主要是讲各布局的细节参数的计算。

我们来看一下这一步的具体代码。

  mDeviceProfile.layout(this, false /* notifyListeners */);
        loadExtractedColorsAndColorItems();

        mPopupDataProvider = new PopupDataProvider(this);

        ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
                .addAccessibilityStateChangeListener(this);

        restoreState(savedInstanceState);

        // We only load the page synchronously if the user rotates (or triggers a
        // configuration change) while launcher is in the foreground
        int currentScreen = PagedView.INVALID_RESTORE_PAGE;
        if (savedInstanceState != null) {
            currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
        }

1.mDeviceProfile.layout(this, false /* notifyListeners */);

在该方法中有一些具体的注释,主要是桌面具体控件布局的位置放置,包括searchbar,allapps,workspace,hotseat,indicators,等等。
// Layout the search bar space
//Layout the all apps
// Layout the workspace
// Layout the hotseat
// Layout the page indicators
//layout the arrow tips
//// Layout the flat menu page indicators
// Layout the Overview Mode
// Layout the snack tips
// Layout the AllAppsRecyclerView

2.loadExtractedColorsAndColorItems();

此方法中是设置控件的颜色

private void loadExtractedColorsAndColorItems() {
        // TODO: do this in pre-N as well, once the extraction part is complete.
        if (Utilities.ATLEAST_NOUGAT) {
            mExtractedColors.load(this);
            mHotseat.updateColor(mExtractedColors, !mPaused);
            mWorkspace.getPageIndicator().updateColor(mExtractedColors);
        }
    }

会根据壁纸的颜色,来调节Hotseat,pageIndicator的颜色。workspace图标文字的颜色。

3.mPopupDataProvider = new PopupDataProvider(this);

当你长按桌面图片,或者allapps里面的图标的时候会弹出来一个窗口,窗口里面有几个选项可供选择。

4.((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
            .addAccessibilityStateChangeListener(this);

监听桌面的变化,进行事件分发,AccessibilityManager是系统级别的服务,用来管理AccessibilityService服务,比如分发事件,查询系统中服务的状态等等。

5.对界面,以及数据进行恢复
restoreState(savedInstanceState);

        if (LauncherAppState.PROFILE_STARTUP) {
            Trace.endSection();
        }

        // We only load the page synchronously if the user rotates (or triggers a
        // configuration change) while launcher is in the foreground
        int currentScreen = PagedView.INVALID_RESTORE_PAGE;
        if (savedInstanceState != null) {
            currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
        }

这里进行数据的保存与恢复。这里运用了安卓的数据储存恢复机制,对保存在savedInstanceState里面的数据进行恢复。

到这里整个Launcher 启动流程 第五步之计算桌面各布局细节参数,就分析完了。接下来继续讲解。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,081评论 25 709
  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 13,085评论 2 59
  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,026评论 3 119
  • 好不容易得休假 天南海北都想去 可是谁人有我去的地方多 朋友圈里见过的美景我都浪了个遍 雪山草地大海森林 踏遍天上...
    东风西游阅读 182评论 1 3
  • 我也想让自己的文章投出去变现,用工资以外的收入来解决自己的零花钱问题,所以,心动不如行动。首先当然要解决文字投稿的...
    书生琅琅1阅读 427评论 0 7