Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c0729c4 authored by Alex Chau's avatar Alex Chau
Browse files

Add task menu item to move task to Desktop

- Call SystemUiProxy.moveToDesktop to move existing Overview tasks to desktop
- Animation polish will be handled separately
- Refactored AbstractFloatingView method into a helper to allow testing

Fix: 320310347
Test: DesktopSystemShortcutTest, AbstractFloatingViewHelperTest
Flag: ACONFIG com.android.window.flags.enable_desktop_windowing_mode DEVELOPMENT
Change-Id: I2e4e04182e46ba4750e0683ee1789ba8fada06ea
parent 0e920d2c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@
    <string name="recent_task_option_pin">Pin</string>
    <!-- Title for an option to enter freeform mode for a given app -->
    <string name="recent_task_option_freeform">Freeform</string>
    <!-- Title for an option to enter desktop windowing mode for a given app -->
    <string name="recent_task_option_desktop">Desktop</string>

    <!-- Recents: The empty recents string. [CHAR LIMIT=NONE] -->
    <string name="recents_empty_message">No recent items</string>
+6 −2
Original line number Diff line number Diff line
@@ -56,6 +56,11 @@ class DesktopRecentsTransitionController(
        systemUiProxy.showDesktopApps(desktopTaskView.display.displayId, transition)
    }

    /** Launch desktop tasks from recents view */
    fun moveToDesktop(taskId: Int) {
        systemUiProxy.moveToDesktop(taskId)
    }

    private class RemoteDesktopLaunchTransitionRunner(
        private val desktopTaskView: DesktopTaskView,
        private val stateManager: StateManager<*>,
@@ -99,8 +104,7 @@ class DesktopRecentsTransitionController(
            finishCallback: IRemoteTransitionFinishedCallback
        ) {}

        override fun onTransitionConsumed(transition: IBinder?, aborted: Boolean) {
        }
        override fun onTransitionConsumed(transition: IBinder?, aborted: Boolean) {}
    }

    companion object {
+1 −1
Original line number Diff line number Diff line
@@ -499,7 +499,7 @@ public class HotseatPredictionController implements DragController.DragListener,

        @Override
        public void onClick(View view) {
            dismissTaskMenuView(mTarget);
            dismissTaskMenuView();
            pinPrediction(mItemInfo);
        }
    }
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.quickstep

import android.view.View
import com.android.launcher3.AbstractFloatingViewHelper
import com.android.launcher3.BaseDraggingActivity
import com.android.launcher3.R
import com.android.launcher3.logging.StatsLogManager.LauncherEvent
import com.android.launcher3.popup.SystemShortcut
import com.android.quickstep.views.RecentsView
import com.android.quickstep.views.TaskView.TaskIdAttributeContainer
import com.android.window.flags.Flags

/** A menu item, "Desktop", that allows the user to bring the current app into Desktop Windowing. */
class DesktopSystemShortcut(
    activity: BaseDraggingActivity,
    private val mTaskContainer: TaskIdAttributeContainer,
    abstractFloatingViewHelper: AbstractFloatingViewHelper
) :
    SystemShortcut<BaseDraggingActivity>(
        R.drawable.ic_caption_desktop_button_foreground,
        R.string.recent_task_option_desktop,
        activity,
        mTaskContainer.itemInfo,
        mTaskContainer.taskView,
        abstractFloatingViewHelper
    ) {
    override fun onClick(view: View) {
        dismissTaskMenuView()
        val recentsView = mTarget!!.getOverviewPanel<RecentsView<*, *>>()
        recentsView.moveTaskToDesktop(mTaskContainer) {
            mTarget.statsLogManager
                .logger()
                .withItemInfo(mTaskContainer.itemInfo)
                .log(LauncherEvent.LAUNCHER_SYSTEM_SHORTCUT_DESKTOP_TAP)
        }
    }

    companion object {
        /** Creates a factory for creating Desktop system shorcuts. */
        @JvmOverloads
        fun createFactory(
            abstractFloatingViewHelper: AbstractFloatingViewHelper = AbstractFloatingViewHelper()
        ): TaskShortcutFactory {
            return object : TaskShortcutFactory {
                override fun getShortcuts(
                    activity: BaseDraggingActivity,
                    taskContainer: TaskIdAttributeContainer
                ): List<DesktopSystemShortcut>? {
                    return if (!Flags.enableDesktopWindowingMode()) null
                    else if (!taskContainer.task.isDockable) null
                    else
                        listOf(
                            DesktopSystemShortcut(
                                activity,
                                taskContainer,
                                abstractFloatingViewHelper
                            )
                        )
                }

                override fun showForSplitscreen() = true
            }
        }
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -1473,6 +1473,17 @@ public class SystemUiProxy implements ISystemUiProxy, NavHandle {
        }
    }

    /** Call shell to move a task with given `taskId` to desktop  */
    public void moveToDesktop(int taskId) {
        if (mDesktopMode != null) {
            try {
                mDesktopMode.moveToDesktop(taskId);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed call moveToDesktop", e);
            }
        }
    }

    //
    // Unfold transition
    //
Loading