Launcher 整体概述

2023-09-11  本文已影响0人  smart_dev

概述

初识launcher3源码,可以发现有个最重要的Activity,即Launcher.java

重要组成部分

Launcher 主要继承关系

基于Android GO

事件处理组成部分

在正式看事件分发(后续文章)之前,我们先来看下,事件处理组成部分都有哪些类

  1. launcher.xml 主布局中可以看到根view是 LauncherRootView,但这个View并没有重写任何事件方法,即不做事件分发与拦截
  2. 接下来引入的是 DragLayer,实际上是一个 FrameLayout
  3. DragLayer 这个类采用组合引入的方式,将事件交给了 TouchController
  4. 我们从代码中找到到 Launcher 在启动的时候会添加四个 TouchController
    path: com.android.launcher3.uioverrides.QuickstepLauncher#createTouchControllers
@Override
public TouchController[] createTouchControllers() {
    Mode mode = SysUINavigationMode.getMode(this);

    ArrayList<TouchController> list = new ArrayList<>();
    list.add(getDragController());
    switch (mode) {
        case NO_BUTTON:
            list.add(new NoButtonQuickSwitchTouchController(this));
            list.add(new NavBarToHomeTouchController(this));
            list.add(new NoButtonNavbarToOverviewTouchController(this));
            break;
        case TWO_BUTTONS:
            list.add(new TwoButtonNavbarTouchController(this));
            list.add(getDeviceProfile().isVerticalBarLayout()
                    ? new TransposedQuickSwitchTouchController(this)
                    : new QuickSwitchTouchController(this));
            list.add(new PortraitStatesTouchController(this));
            break;
        case THREE_BUTTONS:
        default:
            list.add(new PortraitStatesTouchController(this));
    }

    if (!getDeviceProfile().isMultiWindowMode) {
        list.add(new StatusBarTouchController(this));
    }

    list.add(new LauncherTaskViewController(this));
    return list.toArray(new TouchController[list.size()]);
}

实际上会添加四个controoler

上一篇 下一篇

猜你喜欢

热点阅读