From 8a9cc9689ab4478f9e4aa27d6889b355df730bf3 Mon Sep 17 00:00:00 2001 From: Sreyas Date: Thu, 18 Mar 2021 19:54:15 -0700 Subject: [PATCH] Shared element transition between image and sharesheet. Bug: 182373655 Test: Manual Change-Id: I6f5abffa0c4911d939ba45476fe1301d65b840cf --- .../quickstep/util/ImageActionUtils.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/quickstep/src/com/android/quickstep/util/ImageActionUtils.java b/quickstep/src/com/android/quickstep/util/ImageActionUtils.java index 0f2d778623..2285d74d73 100644 --- a/quickstep/src/com/android/quickstep/util/ImageActionUtils.java +++ b/quickstep/src/com/android/quickstep/util/ImageActionUtils.java @@ -19,9 +19,12 @@ package com.android.quickstep.util; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION; +import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.Executors.THREAD_POOL_EXECUTOR; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; +import android.app.Activity; +import android.app.ActivityOptions; import android.app.prediction.AppTarget; import android.content.ClipData; import android.content.ClipDescription; @@ -37,11 +40,13 @@ import android.graphics.Rect; import android.graphics.RectF; import android.net.Uri; import android.util.Log; +import android.view.View; import androidx.annotation.UiThread; import androidx.annotation.WorkerThread; import androidx.core.content.FileProvider; +import com.android.internal.app.ChooserActivity; import com.android.launcher3.BuildConfig; import com.android.quickstep.SystemUiProxy; import com.android.systemui.shared.recents.model.Task; @@ -125,6 +130,22 @@ public class ImageActionUtils { tag)); } + /** + * Launch the activity to share image with shared element transition. + */ + @UiThread + public static void startShareActivity(Context context, Supplier bitmapSupplier, + Rect crop, Intent intent, String tag, View sharedElement) { + if (bitmapSupplier.get() == null) { + Log.e(tag, "No snapshot available, not starting share."); + return; + } + + UI_HELPER_EXECUTOR.execute(() -> persistBitmapAndStartActivity(context, + bitmapSupplier.get(), crop, intent, ImageActionUtils::getShareIntentForImageUri, + tag, sharedElement)); + } + /** * Starts activity based on given intent created from image uri. */ @@ -141,6 +162,30 @@ public class ImageActionUtils { } } + /** + * Starts activity based on given intent created from image uri with shared element transition. + */ + @WorkerThread + public static void persistBitmapAndStartActivity(Context context, Bitmap bitmap, Rect crop, + Intent intent, BiFunction uriToIntentMap, String tag, + View scaledImage) { + Intent[] intents = uriToIntentMap.apply(getImageUri(bitmap, crop, context, tag), intent); + + // Work around b/159412574 + if (intents.length == 1) { + MAIN_EXECUTOR.execute(() -> context.startActivity(intents[0], + ActivityOptions.makeSceneTransitionAnimation((Activity) context, scaledImage, + ChooserActivity.FIRST_IMAGE_PREVIEW_TRANSITION_NAME).toBundle())); + + } else { + MAIN_EXECUTOR.execute(() -> context.startActivities(intents, + ActivityOptions.makeSceneTransitionAnimation((Activity) context, scaledImage, + ChooserActivity.FIRST_IMAGE_PREVIEW_TRANSITION_NAME).toBundle())); + } + } + + + /** * Converts image bitmap to Uri by temporarily saving bitmap to cache, and creating Uri pointing * to that location. Used to be able to share an image with another app.