Launcher3: Start lens activity directly instead of sharesheet

We don't need to open the sharesheet as we're targeting a specific
application (Google Lens).

Change-Id: I042b3a712dcf03eda21504b66cf99394b0bd4d2b
This commit is contained in:
Adithya R 2023-11-04 17:21:51 +05:30 committed by fazilsheik96
parent 67b6936756
commit 4aa72dfab8
2 changed files with 23 additions and 28 deletions

View File

@ -111,7 +111,7 @@ public class ImageActionsApi {
@UiThread
public void startLensActivity() {
ImageActionUtils.startLensActivity(mContext, mBitmapSupplier, null, null, TAG);
ImageActionUtils.startLensActivity(mContext, mBitmapSupplier, null, TAG);
}
/**

View File

@ -161,15 +161,28 @@ public class ImageActionUtils {
}
public static void startLensActivity(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::getLensIntentForImageUri,
tag));
Rect crop, String tag) {
UI_HELPER_EXECUTOR.execute(() -> {
Bitmap bitmap = bitmapSupplier.get();
if (bitmap == null) {
Log.e(tag, "No snapshot available, not starting lens.");
return;
}
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(Utilities.GSA_PACKAGE, Utilities.LENS_SHARE_ACTIVITY))
.addFlags(FLAG_ACTIVITY_NEW_TASK)
.addFlags(FLAG_GRANT_READ_URI_PERMISSION)
.setType("image/png")
.putExtra(Intent.EXTRA_STREAM, uri)
.setClipData(clipdata);
context.startActivity(intent);
});
}
/**
@ -312,24 +325,6 @@ public class ImageActionUtils {
return new Intent[]{Intent.createChooser(intent, null).addFlags(FLAG_ACTIVITY_NEW_TASK)};
}
@WorkerThread
private static Intent[] getLensIntentForImageUri(Uri uri, Intent intent) {
if (intent == null) {
intent = new Intent();
}
ClipData clipdata = new ClipData(new ClipDescription("content",
new String[]{"image/png"}),
new ClipData.Item(uri));
intent.setAction(Intent.ACTION_SEND)
.setComponent(new ComponentName(Utilities.GSA_PACKAGE, Utilities.LENS_SHARE_ACTIVITY))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(FLAG_GRANT_READ_URI_PERMISSION)
.setType("image/png")
.putExtra(Intent.EXTRA_STREAM, uri)
.setClipData(clipdata);
return new Intent[]{Intent.createChooser(intent, null).addFlags(FLAG_ACTIVITY_NEW_TASK)};
}
private static void clearOldCacheFiles(Context context) {
THREAD_POOL_EXECUTOR.execute(() -> {
File parent = new File(context.getCacheDir(), SUB_FOLDER);