From b198d46f9ca68736e04345db645c238305cc5430 Mon Sep 17 00:00:00 2001 From: Becky Qiu Date: Wed, 13 Jan 2021 12:09:47 -0800 Subject: [PATCH] [Overview Sharing] Create the share function for sharing image in overview. Bug: 169772466, 169799864 Test: local Change-Id: Iaac49fa396e68f7392b59f6f9b8854cc1abe270b --- .../android/quickstep/ImageActionsApi.java | 11 +++++++ .../quickstep/util/ImageActionUtils.java | 32 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/quickstep/src/com/android/quickstep/ImageActionsApi.java b/quickstep/src/com/android/quickstep/ImageActionsApi.java index ba8ba3328b..b04905ca60 100644 --- a/quickstep/src/com/android/quickstep/ImageActionsApi.java +++ b/quickstep/src/com/android/quickstep/ImageActionsApi.java @@ -22,11 +22,14 @@ import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import static com.android.quickstep.util.ImageActionUtils.persistBitmapAndStartActivity; +import android.app.prediction.AppTarget; import android.content.Context; import android.content.Intent; +import android.content.pm.ShortcutInfo; import android.graphics.Bitmap; import android.graphics.Insets; import android.graphics.Rect; +import android.graphics.RectF; import android.util.Log; import androidx.annotation.Nullable; @@ -96,4 +99,12 @@ public class ImageActionsApi { ImageActionUtils.saveScreenshot(mSystemUiProxy, screenshot, screenshotBounds, visibleInsets, task); } + + /** + * Share the image when user taps on overview share targets. + */ + @UiThread + public void shareImage(RectF rectF, ShortcutInfo shortcutInfo, AppTarget appTarget) { + ImageActionUtils.shareImage(mContext, mBitmapSupplier, rectF, shortcutInfo, appTarget, TAG); + } } diff --git a/quickstep/src/com/android/quickstep/util/ImageActionUtils.java b/quickstep/src/com/android/quickstep/util/ImageActionUtils.java index e998e9a7ef..d022085877 100644 --- a/quickstep/src/com/android/quickstep/util/ImageActionUtils.java +++ b/quickstep/src/com/android/quickstep/util/ImageActionUtils.java @@ -22,15 +22,19 @@ import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION; import static com.android.launcher3.util.Executors.THREAD_POOL_EXECUTOR; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; +import android.app.prediction.AppTarget; import android.content.ClipData; import android.content.ClipDescription; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.pm.ShortcutInfo; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Insets; import android.graphics.Picture; import android.graphics.Rect; +import android.graphics.RectF; import android.net.Uri; import android.util.Log; @@ -70,6 +74,34 @@ public class ImageActionUtils { screenshotBounds, visibleInsets, task); } + /** + * Launch the activity to share image for overview sharing. This is to share cropped bitmap + * with specific share targets (with shortcutInfo and appTarget) rendered in overview. + */ + @UiThread + public static void shareImage(Context context, Supplier bitmapSupplier, RectF rectF, + ShortcutInfo shortcutInfo, AppTarget appTarget, String tag) { + if (bitmapSupplier.get() == null) { + return; + } + Rect crop = new Rect(); + rectF.round(crop); + Intent intent = new Intent(); + Uri uri = getImageUri(bitmapSupplier.get(), crop, context, tag); + ClipData clipdata = new ClipData(new ClipDescription("content", + new String[]{"image/png"}), + new ClipData.Item(uri)); + intent.setAction(Intent.ACTION_SEND) + .setComponent(new ComponentName(appTarget.getPackageName(), appTarget.getClassName())) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + .addFlags(FLAG_GRANT_READ_URI_PERMISSION) + .setType("image/png") + .putExtra(Intent.EXTRA_STREAM, uri) + .putExtra(Intent.EXTRA_SHORTCUT_ID, shortcutInfo.getId()) + .setClipData(clipdata); + context.startActivity(intent); + } + /** * Launch the activity to share image. */