Merge "Move bitmapSupplier.get() call to a worker thread." into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a65cc60f9d
@@ -78,16 +78,17 @@ public class ImageActionsApi {
|
||||
addImageAndSendIntent(crop, intent, true, exceptionCallback);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void addImageAndSendIntent(@Nullable Rect crop, Intent intent, boolean setData,
|
||||
@Nullable Runnable exceptionCallback) {
|
||||
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) -> {
|
||||
UI_HELPER_EXECUTOR.execute(() -> {
|
||||
Bitmap bitmap = mBitmapSupplier.get();
|
||||
if (bitmap == null) {
|
||||
Log.e(TAG, "No snapshot available, not starting share.");
|
||||
return;
|
||||
}
|
||||
persistBitmapAndStartActivity(mContext,
|
||||
bitmap, crop, intent, (uri, intentForUri) -> {
|
||||
intentForUri.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
|
||||
if (setData) {
|
||||
intentForUri.setData(uri);
|
||||
@@ -95,7 +96,8 @@ public class ImageActionsApi {
|
||||
intentForUri.putExtra(EXTRA_STREAM, uri);
|
||||
}
|
||||
return new Intent[]{intentForUri};
|
||||
}, TAG, exceptionCallback));
|
||||
}, TAG, exceptionCallback);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,7 +43,6 @@ 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;
|
||||
|
||||
@@ -86,67 +85,70 @@ public class ImageActionUtils {
|
||||
* 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<Bitmap> 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);
|
||||
UI_HELPER_EXECUTOR.execute(() -> {
|
||||
Bitmap bitmap = bitmapSupplier.get();
|
||||
if (bitmap == null) {
|
||||
return;
|
||||
}
|
||||
Rect crop = new Rect();
|
||||
rectF.round(crop);
|
||||
Intent intent = new Intent();
|
||||
Uri uri = getImageUri(bitmap, 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);
|
||||
|
||||
if (context.getUserId() != appTarget.getUser().getIdentifier()) {
|
||||
intent.prepareToLeaveUser(context.getUserId());
|
||||
intent.fixUris(context.getUserId());
|
||||
context.startActivityAsUser(intent, appTarget.getUser());
|
||||
} else {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
if (context.getUserId() != appTarget.getUser().getIdentifier()) {
|
||||
intent.prepareToLeaveUser(context.getUserId());
|
||||
intent.fixUris(context.getUserId());
|
||||
context.startActivityAsUser(intent, appTarget.getUser());
|
||||
} else {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the activity to share image.
|
||||
*/
|
||||
@UiThread
|
||||
public static void startShareActivity(Context context, Supplier<Bitmap> bitmapSupplier,
|
||||
Rect crop, Intent intent, String tag) {
|
||||
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));
|
||||
UI_HELPER_EXECUTOR.execute(() -> {
|
||||
Bitmap bitmap = bitmapSupplier.get();
|
||||
if (bitmap == null) {
|
||||
Log.e(tag, "No snapshot available, not starting share.");
|
||||
return;
|
||||
}
|
||||
persistBitmapAndStartActivity(context, bitmap, crop, intent,
|
||||
ImageActionUtils::getShareIntentForImageUri, tag);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the activity to share image with shared element transition.
|
||||
*/
|
||||
@UiThread
|
||||
public static void startShareActivity(Context context, Supplier<Bitmap> 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));
|
||||
UI_HELPER_EXECUTOR.execute(() -> {
|
||||
Bitmap bitmap = bitmapSupplier.get();
|
||||
if (bitmap == null) {
|
||||
Log.e(tag, "No snapshot available, not starting share.");
|
||||
return;
|
||||
}
|
||||
persistBitmapAndStartActivity(context, bitmap,
|
||||
crop, intent, ImageActionUtils::getShareIntentForImageUri, tag, sharedElement);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user