From 849622f6cb3ce905bffeb58ceeeda4be0ee155c0 Mon Sep 17 00:00:00 2001 From: Becky Qiu Date: Thu, 28 May 2020 15:52:02 -0700 Subject: [PATCH] [Overview Actions] Add actions to the task menu for in-place landscape. Test: local Bug: 153736749 Change-Id: I9ba5a089e434e75de7d9cc29ebd303f7a1388324 --- .../android/quickstep/TaskOverlayFactory.java | 82 ++++++++++++++++--- .../quickstep/TaskShortcutFactory.java | 17 ++++ .../android/quickstep/views/RecentsView.java | 5 ++ .../quickstep/views/TaskThumbnailView.java | 10 +++ 4 files changed, 104 insertions(+), 10 deletions(-) diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskOverlayFactory.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskOverlayFactory.java index 97cd11b4f5..a6a08cb656 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskOverlayFactory.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskOverlayFactory.java @@ -16,6 +16,8 @@ package com.android.quickstep; +import static android.view.Surface.ROTATION_0; + import static com.android.launcher3.util.MainThreadInitializedObject.forOverride; import android.annotation.SuppressLint; @@ -24,6 +26,7 @@ import android.graphics.Insets; import android.graphics.Matrix; import android.graphics.Rect; import android.os.Build; +import android.view.View; import android.widget.Toast; import androidx.annotation.RequiresApi; @@ -31,9 +34,12 @@ import androidx.annotation.RequiresApi; import com.android.launcher3.BaseActivity; import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.R; +import com.android.launcher3.model.data.ItemInfo; +import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.popup.SystemShortcut; import com.android.launcher3.util.MainThreadInitializedObject; import com.android.launcher3.util.ResourceBasedOverride; +import com.android.quickstep.util.RecentsOrientedState; import com.android.quickstep.views.OverviewActionsView; import com.android.quickstep.views.TaskThumbnailView; import com.android.quickstep.views.TaskView; @@ -58,6 +64,19 @@ public class TaskOverlayFactory implements ResourceBasedOverride { shortcuts.add(shortcut); } } + RecentsOrientedState orientedState = taskView.getRecentsView().getPagedViewOrientedState(); + boolean canLauncherRotate = orientedState.canLauncherRotate(); + boolean isInLandscape = orientedState.getTouchRotation() != ROTATION_0; + + // Add overview actions to the menu when in in-place rotate landscape mode. + if (!canLauncherRotate && isInLandscape) { + for (TaskShortcutFactory actionMenuOption : ACTION_MENU_OPTIONS) { + SystemShortcut shortcut = actionMenuOption.getShortcut(activity, taskView); + if (shortcut != null) { + shortcuts.add(shortcut); + } + } + } return shortcuts; } @@ -85,6 +104,11 @@ public class TaskOverlayFactory implements ResourceBasedOverride { TaskShortcutFactory.WELLBEING }; + private static final TaskShortcutFactory[] ACTION_MENU_OPTIONS = new TaskShortcutFactory[]{ + TaskShortcutFactory.SCREENSHOT, + TaskShortcutFactory.MODAL + }; + /** * Overlay on each task handling Overview Action Buttons. */ @@ -94,10 +118,14 @@ public class TaskOverlayFactory implements ResourceBasedOverride { protected final TaskThumbnailView mThumbnailView; private T mActionsView; + private ImageActionsApi mImageApi; + private boolean mIsAllowedByPolicy; protected TaskOverlay(TaskThumbnailView taskThumbnailView) { mApplicationContext = taskThumbnailView.getContext().getApplicationContext(); mThumbnailView = taskThumbnailView; + mImageApi = new ImageActionsApi( + mApplicationContext, mThumbnailView::getThumbnail); } protected T getActionsView() { @@ -112,15 +140,12 @@ public class TaskOverlayFactory implements ResourceBasedOverride { * Called when the current task is interactive for the user */ public void initOverlay(Task task, ThumbnailData thumbnail, Matrix matrix) { - ImageActionsApi imageApi = new ImageActionsApi( - mApplicationContext, mThumbnailView::getThumbnail); final boolean isAllowedByPolicy = thumbnail.isRealSnapshot; - getActionsView().setCallbacks(new OverlayUICallbacks() { @Override public void onShare() { if (isAllowedByPolicy) { - imageApi.startShareActivity(); + mImageApi.startShareActivity(); } else { showBlockedByPolicyMessage(); } @@ -129,16 +154,23 @@ public class TaskOverlayFactory implements ResourceBasedOverride { @SuppressLint("NewApi") @Override public void onScreenshot() { - if (isAllowedByPolicy) { - imageApi.saveScreenshot(mThumbnailView.getThumbnail(), - getTaskSnapshotBounds(), getTaskSnapshotInsets(), task.key); - } else { - showBlockedByPolicyMessage(); - } + saveScreenshot(task); } }); } + /** + * Called to save screenshot of the task thumbnail. + */ + @SuppressLint("NewApi") + private void saveScreenshot(Task task) { + if (mThumbnailView.isRealSnapshot()) { + mImageApi.saveScreenshot(mThumbnailView.getThumbnail(), + getTaskSnapshotBounds(), getTaskSnapshotInsets(), task.key); + } else { + showBlockedByPolicyMessage(); + } + } /** * Called when the overlay is no longer used. @@ -146,6 +178,20 @@ public class TaskOverlayFactory implements ResourceBasedOverride { public void reset() { } + /** + * Gets the modal state system shortcut. + */ + public SystemShortcut getModalStateSystemShortcut(WorkspaceItemInfo itemInfo) { + return null; + } + + /** + * Gets the system shortcut for the screenshot that will be added to the task menu. + */ + public SystemShortcut getScreenshotShortcut(BaseDraggingActivity activity, + ItemInfo iteminfo) { + return new ScreenshotSystemShortcut(activity, iteminfo); + } /** * Gets the task snapshot as it is displayed on the screen. * @@ -175,6 +221,22 @@ public class TaskOverlayFactory implements ResourceBasedOverride { R.string.blocked_by_policy, Toast.LENGTH_LONG).show(); } + + private class ScreenshotSystemShortcut extends SystemShortcut { + + private final BaseDraggingActivity mActivity; + + ScreenshotSystemShortcut(BaseDraggingActivity activity, ItemInfo itemInfo) { + super(R.drawable.ic_screenshot, R.string.action_screenshot, activity, itemInfo); + mActivity = activity; + } + + @Override + public void onClick(View view) { + saveScreenshot(mThumbnailView.getTaskView().getTask()); + dismissTaskMenuView(mActivity); + } + } } /** diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskShortcutFactory.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskShortcutFactory.java index 3623e671f1..ea1795c032 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskShortcutFactory.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskShortcutFactory.java @@ -18,6 +18,8 @@ package com.android.quickstep; import static android.view.Display.DEFAULT_DISPLAY; +import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_ACTIONS; +import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_SELECTIONS; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SYSTEM_SHORTCUT_FREE_FORM_TAP; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SYSTEM_SHORTCUT_SPLIT_SCREEN_TAP; import static com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch.TAP; @@ -332,4 +334,19 @@ public interface TaskShortcutFactory { TaskShortcutFactory WELLBEING = (activity, view) -> WellbeingModel.SHORTCUT_FACTORY.getShortcut(activity, dummyInfo(view)); + + TaskShortcutFactory SCREENSHOT = (activity, tv) -> { + if (ENABLE_OVERVIEW_ACTIONS.get()) { + return tv.getThumbnail().getTaskOverlay() + .getScreenshotShortcut(activity, dummyInfo(tv)); + } + return null; + }; + + TaskShortcutFactory MODAL = (activity, tv) -> { + if (ENABLE_OVERVIEW_ACTIONS.get() && ENABLE_OVERVIEW_SELECTIONS.get()) { + return tv.getThumbnail().getTaskOverlay().getModalStateSystemShortcut(dummyInfo(tv)); + } + return null; + }; } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java index 98784efdc1..1e4a87c4b0 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java @@ -2182,6 +2182,11 @@ public abstract class RecentsView extends PagedView impl if (getCurrentPageTaskView() != null) { getCurrentPageTaskView().setModalness(modalness); } + // Only show actions view when it's modal for in-place landscape mode. + boolean inPlaceLandscape = !mOrientationState.canLauncherRotate() + && mOrientationState.getTouchRotation() != ROTATION_0; + mActionsView.updateHiddenFlags(HIDDEN_NON_ZERO_ROTATION, modalness < 1 && inPlaceLandscape); + LayoutUtils.setViewEnabled(mActionsView, true); } @Nullable diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java index a371dd21ff..26fb563b82 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java @@ -447,6 +447,16 @@ public class TaskThumbnailView extends View implements PluginListener