Android T多屏多显——应用双屏间拖拽移动功能(更新中)

功能以及显示效果简介

需求:在双屏显示中,把启动的应用从其中一个屏幕中移动到另一个屏幕中。
操作:通过双指按压应用使其移动,如果移动的距离过小,我们就不移动到另一屏幕,否则移动到另一屏。
请添加图片描述

功能分析

多屏中移动应用至另一屏本质就是Task的移动。
从窗口层级结构的角度来说,就是把Display1中的DefaultTaskDisplayArea上的Task,移动到Display2中的DefaultTaskDisplayArea上

关键代码知识点

移动Task至另一屏幕

代码路径:frameworks/base/services/core/java/com/android/server/wm/RootWindowContainer.java

    /**
     * Move root task with all its existing content to specified display.
     *
     * @param rootTaskId Id of root task to move.
     * @param displayId  Id of display to move root task to.
     * @param onTop      Indicates whether container should be place on top or on bottom.
     */
    void moveRootTaskToDisplay(int rootTaskId, int displayId, boolean onTop) {
        final DisplayContent displayContent = getDisplayContentOrCreate(displayId);
        if (displayContent == null) {
            throw new IllegalArgumentException("moveRootTaskToDisplay: Unknown displayId="
                    + displayId);
        }

        moveRootTaskToTaskDisplayArea(rootTaskId, displayContent.getDefaultTaskDisplayArea(),
                onTop);
    }
    
    
    
    /**
     * Move root task with all its existing content to specified task display area.
     *
     * @param rootTaskId      Id of root task to move.
     * @param taskDisplayArea The task display area to move root task to.
     * @param onTop           Indicates whether container should be place on top or on bottom.
     */
    void moveRootTaskToTaskDisplayArea(int rootTaskId, TaskDisplayArea taskDisplayArea,
            boolean onTop) {
        final Task rootTask = getRootTask(rootTaskId);
        if (rootTask == null) {
            throw new IllegalArgumentException("moveRootTaskToTaskDisplayArea: Unknown rootTaskId="
                    + rootTaskId);
        }

        final TaskDisplayArea currentTaskDisplayArea = rootTask.getDisplayArea();
        if (currentTaskDisplayArea == null) {
            throw new IllegalStateException("moveRootTaskToTaskDisplayArea: rootTask=" + rootTask
                    + " is not attached to any task display area.");
        }

        if (taskDisplayArea == null) {
            throw new IllegalArgumentException(
                    "moveRootTaskToTaskDisplayArea: Unknown taskDisplayArea=" + taskDisplayArea);
        }

        if (currentTaskDisplayArea == taskDisplayArea) {
            throw new IllegalArgumentException("Trying to move rootTask=" + rootTask
                    + " to its current taskDisplayArea=" + taskDisplayArea);
        }
        rootTask.reparent(taskDisplayArea, onTop);

        // Resume focusable root task after reparenting to another display area.
        rootTask.resumeNextFocusAfterReparent();

        // TODO(multi-display): resize rootTasks properly if moved from split-screen.
    }

相关推荐

  1. android-Presentation

    2024-04-13 03:06:02       13 阅读
  2. android 13.0 Launcher3禁止app图标到第一

    2024-04-13 03:06:02       38 阅读
  3. Android 车联网——用户(十五)

    2024-04-13 03:06:02       33 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-13 03:06:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-13 03:06:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-13 03:06:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-13 03:06:02       18 阅读

热门阅读

  1. 桶排序:原理、实现与应用场景详解

    2024-04-13 03:06:02       14 阅读
  2. LeetCode 1. Two Sum

    2024-04-13 03:06:02       14 阅读
  3. 记录一次关于线程池任务编排和共享数据的尝试

    2024-04-13 03:06:02       13 阅读
  4. [AIGC] 分布式锁及其实现方式详解与Python代码示例

    2024-04-13 03:06:02       17 阅读
  5. Python学习入门(1)——基础语句

    2024-04-13 03:06:02       15 阅读
  6. ubuntu添加环境变量

    2024-04-13 03:06:02       17 阅读
  7. vue 事件$on,$off的注意事项

    2024-04-13 03:06:02       15 阅读
  8. Spring WebFlux响应式实现WebFilter解决跨域问题

    2024-04-13 03:06:02       16 阅读
  9. C++类引用的好处

    2024-04-13 03:06:02       15 阅读
  10. 详解QUuid类的使用

    2024-04-13 03:06:02       12 阅读