From 1963d3f3eded20d9c52a6032f479067c7a0e52bb Mon Sep 17 00:00:00 2001 From: Sreyas Date: Mon, 9 Mar 2020 18:10:08 -0700 Subject: [PATCH] OverviewActions: Adding action buttons to Oem quickstep. Change-Id: Id5c0d8f1b41107535c1bac982b47f67eb2574c21 --- quickstep/AndroidManifest.xml | 11 ++ .../android/quickstep/ImageActionsApi.java | 94 ++++++++++ .../android/quickstep/TaskOverlayFactory.java | 96 ++++++++-- .../quickstep/views/OverviewActionsView.java | 79 +++++++++ quickstep/res/drawable/ic_screenshot.xml | 23 +++ quickstep/res/drawable/ic_share.xml | 23 +++ quickstep/res/layout/overview_actions.xml | 41 +++++ .../res/layout/overview_actions_container.xml | 23 +++ quickstep/res/values/dimens.xml | 2 +- quickstep/res/values/strings.xml | 6 + quickstep/res/values/styles.xml | 9 + .../res/xml/overview_file_provider_paths.xml | 5 + .../quickstep/util/ImageActionUtils.java | 164 ++++++++++++++++++ 13 files changed, 556 insertions(+), 20 deletions(-) create mode 100644 quickstep/recents_ui_overrides/src/com/android/quickstep/ImageActionsApi.java create mode 100644 quickstep/recents_ui_overrides/src/com/android/quickstep/views/OverviewActionsView.java create mode 100644 quickstep/res/drawable/ic_screenshot.xml create mode 100644 quickstep/res/drawable/ic_share.xml create mode 100644 quickstep/res/layout/overview_actions.xml create mode 100644 quickstep/res/layout/overview_actions_container.xml create mode 100644 quickstep/res/xml/overview_file_provider_paths.xml create mode 100644 quickstep/src/com/android/quickstep/util/ImageActionUtils.java diff --git a/quickstep/AndroidManifest.xml b/quickstep/AndroidManifest.xml index 1d0b0455c8..04506b5647 100644 --- a/quickstep/AndroidManifest.xml +++ b/quickstep/AndroidManifest.xml @@ -73,6 +73,17 @@ + + + + + diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/ImageActionsApi.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/ImageActionsApi.java new file mode 100644 index 0000000000..33fe5a9e0a --- /dev/null +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/ImageActionsApi.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2020 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 static android.content.Intent.EXTRA_STREAM; + +import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; +import static com.android.quickstep.util.ImageActionUtils.persistBitmapAndStartActivity; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.Insets; +import android.graphics.Rect; +import android.util.Log; + +import androidx.annotation.Nullable; +import androidx.annotation.UiThread; + +import com.android.launcher3.BuildConfig; +import com.android.quickstep.util.ImageActionUtils; + +import java.util.function.Supplier; + +/** + * Contains image selection functions necessary to complete overview action button functions. + */ +public class ImageActionsApi { + + private static final String TAG = BuildConfig.APPLICATION_ID + "ImageActionsApi"; + private final Context mContext; + private final Supplier mBitmapSupplier; + private final SystemUiProxy mSystemUiProxy; + + public ImageActionsApi(Context context, Supplier bitmapSupplier) { + mContext = context; + mBitmapSupplier = bitmapSupplier; + mSystemUiProxy = SystemUiProxy.INSTANCE.get(context); + } + + /** + * Share the image this api was constructed with using the provided intent. The implementation + * should add an {@link Intent#EXTRA_STREAM} with the URI pointing to the image to the intent. + */ + @UiThread + public void shareWithExplicitIntent(@Nullable Rect crop, Intent intent) { + if (mBitmapSupplier.get() == null) { + Log.e(TAG, "No snapshot available, not starting share."); + return; + } + + UI_HELPER_EXECUTOR.execute(() -> persistBitmapAndStartActivity(mContext, + mBitmapSupplier.get(), crop, intent, (uri, intentForUri) -> { + intentForUri.putExtra(EXTRA_STREAM, uri); + return new Intent[]{intentForUri}; + }, TAG)); + + } + + /** + * Share the image this api was constructed with. + */ + @UiThread + public void startShareActivity() { + ImageActionUtils.startShareActivity(mContext, mBitmapSupplier, null, null, TAG); + } + + /** + * @param screenshot to be saved to the media store. + * @param screenshotBounds the location of where the bitmap was laid out on the screen in + * screen coordinates. + * @param visibleInsets that are used to draw the screenshot within the bounds. + * @param taskId of the task that the screenshot was taken of. + */ + public void saveScreenshot(Bitmap screenshot, Rect screenshotBounds, + Insets visibleInsets, int taskId) { + ImageActionUtils.saveScreenshot(mSystemUiProxy, screenshot, screenshotBounds, visibleInsets, + taskId); + } +} 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 33d9d9aa55..fbf29af9fb 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskOverlayFactory.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskOverlayFactory.java @@ -16,12 +16,13 @@ package com.android.quickstep; +import static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_ACTIONS; import static com.android.launcher3.util.MainThreadInitializedObject.forOverride; +import android.content.Context; +import android.graphics.Insets; import android.graphics.Matrix; -import android.view.View; - -import androidx.annotation.Nullable; +import android.graphics.Rect; import com.android.launcher3.BaseActivity; import com.android.launcher3.BaseDraggingActivity; @@ -29,6 +30,7 @@ import com.android.launcher3.R; import com.android.launcher3.popup.SystemShortcut; import com.android.launcher3.util.MainThreadInitializedObject; import com.android.launcher3.util.ResourceBasedOverride; +import com.android.quickstep.views.OverviewActionsView; import com.android.quickstep.views.TaskThumbnailView; import com.android.quickstep.views.TaskView; import com.android.systemui.plugins.OverscrollPlugin; @@ -43,16 +45,6 @@ import java.util.List; */ public class TaskOverlayFactory implements ResourceBasedOverride { - /** Note that these will be shown in order from top to bottom, if available for the task. */ - private static final TaskShortcutFactory[] MENU_OPTIONS = new TaskShortcutFactory[]{ - TaskShortcutFactory.APP_INFO, - TaskShortcutFactory.SPLIT_SCREEN, - TaskShortcutFactory.PIN, - TaskShortcutFactory.INSTALL, - TaskShortcutFactory.FREE_FORM, - TaskShortcutFactory.WELLBEING - }; - public static List getEnabledShortcuts(TaskView taskView) { final ArrayList shortcuts = new ArrayList<>(); final BaseDraggingActivity activity = BaseActivity.fromContext(taskView.getContext()); @@ -76,25 +68,68 @@ public class TaskOverlayFactory implements ResourceBasedOverride { } public TaskOverlay createOverlay(TaskThumbnailView thumbnailView) { - return new TaskOverlay(); + return new TaskOverlay(thumbnailView); } + /** Note that these will be shown in order from top to bottom, if available for the task. */ + private static final TaskShortcutFactory[] MENU_OPTIONS = new TaskShortcutFactory[]{ + TaskShortcutFactory.APP_INFO, + TaskShortcutFactory.SPLIT_SCREEN, + TaskShortcutFactory.PIN, + TaskShortcutFactory.INSTALL, + TaskShortcutFactory.FREE_FORM, + TaskShortcutFactory.WELLBEING + }; + + /** + * Overlay on each task handling Overview Action Buttons. + */ public static class TaskOverlay { + private final Context mApplicationContext; + private OverviewActionsView mActionsView; + private final TaskThumbnailView mThumbnailView; + + + protected TaskOverlay(TaskThumbnailView taskThumbnailView) { + mApplicationContext = taskThumbnailView.getContext().getApplicationContext(); + mThumbnailView = taskThumbnailView; + } + /** * Called when the current task is interactive for the user */ - public void initOverlay(Task task, ThumbnailData thumbnail, Matrix matrix) { } + public void initOverlay(Task task, ThumbnailData thumbnail, Matrix matrix) { + ImageActionsApi imageApi = new ImageActionsApi( + mApplicationContext, mThumbnailView::getThumbnail); + + if (mActionsView == null && ENABLE_OVERVIEW_ACTIONS.get() + && SysUINavigationMode.removeShelfFromOverview(mApplicationContext)) { + mActionsView = BaseActivity.fromContext(mThumbnailView.getContext()).findViewById( + R.id.overview_actions_view); + } + if (mActionsView != null) { + mActionsView.setListener(new OverviewActionsView.Listener() { + @Override + public void onShare() { + imageApi.startShareActivity(); + } + + @Override + public void onScreenshot() { + imageApi.saveScreenshot(mThumbnailView.getThumbnail(), + getTaskSnapshotBounds(), getTaskSnapshotInsets(), task.key.id); + } + }); + } - @Nullable - public View getActionsView() { - return null; } /** * Called when the overlay is no longer used. */ - public void reset() { } + public void reset() { + } /** * Whether the overlay is modal, which means only tapping is enabled, but no swiping. @@ -102,5 +137,28 @@ public class TaskOverlayFactory implements ResourceBasedOverride { public boolean isOverlayModal() { return false; } + + /** + * Gets the task snapshot as it is displayed on the screen. + * + * @return the bounds of the snapshot in screen coordinates. + */ + public Rect getTaskSnapshotBounds() { + int[] location = new int[2]; + mThumbnailView.getLocationOnScreen(location); + + return new Rect(location[0], location[1], mThumbnailView.getWidth() + location[0], + mThumbnailView.getHeight() + location[1]); + } + + /** + * Gets the insets that the snapshot is drawn with. + * + * @return the insets in screen coordinates. + */ + public Insets getTaskSnapshotInsets() { + // TODO: return the real insets + return Insets.of(0, 0, 0, 0); + } } } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/OverviewActionsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/OverviewActionsView.java new file mode 100644 index 0000000000..6a37e2b7de --- /dev/null +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/OverviewActionsView.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2020 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.views; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.FrameLayout; + +import androidx.annotation.Nullable; + +import com.android.launcher3.R; + +/** + * View for showing action buttons in Overview + */ +public class OverviewActionsView extends FrameLayout { + + private final View mScreenshotButton; + private final View mShareButton; + + /** + * Listener for taps on the various actions. + */ + public interface Listener { + /** User has initiated the share actions. */ + void onShare(); + + /** User has initiated the screenshot action. */ + void onScreenshot(); + } + + public OverviewActionsView(Context context) { + this(context, null); + } + + public OverviewActionsView(Context context, @Nullable AttributeSet attrs) { + this(context, attrs, 0); + } + + public OverviewActionsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + this(context, attrs, defStyleAttr, 0); + } + + public OverviewActionsView(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + LayoutInflater.from(context).inflate(R.layout.overview_actions, this, true); + mShareButton = findViewById(R.id.action_share); + mScreenshotButton = findViewById(R.id.action_screenshot); + } + + /** + * Set listener for callbacks on action button taps. + * + * @param listener for callbacks, or {@code null} to clear the listener. + */ + public void setListener(@Nullable OverviewActionsView.Listener listener) { + mShareButton.setOnClickListener( + listener == null ? null : view -> listener.onShare()); + mScreenshotButton.setOnClickListener( + listener == null ? null : view -> listener.onScreenshot()); + } +} diff --git a/quickstep/res/drawable/ic_screenshot.xml b/quickstep/res/drawable/ic_screenshot.xml new file mode 100644 index 0000000000..d97eae1d15 --- /dev/null +++ b/quickstep/res/drawable/ic_screenshot.xml @@ -0,0 +1,23 @@ + + + + diff --git a/quickstep/res/drawable/ic_share.xml b/quickstep/res/drawable/ic_share.xml new file mode 100644 index 0000000000..ff4baec79b --- /dev/null +++ b/quickstep/res/drawable/ic_share.xml @@ -0,0 +1,23 @@ + + + + diff --git a/quickstep/res/layout/overview_actions.xml b/quickstep/res/layout/overview_actions.xml new file mode 100644 index 0000000000..ad5efb6ae0 --- /dev/null +++ b/quickstep/res/layout/overview_actions.xml @@ -0,0 +1,41 @@ + + + + + +