From 41e0d746284f22fbed08fd6c4c09e46f69458c15 Mon Sep 17 00:00:00 2001 From: Matt Garnes Date: Sat, 17 Jan 2015 16:58:20 +0800 Subject: [PATCH] Add special case for Gallery2 when opening image files. Gallery2 will change the back button behavior when opening a media URI to a specific image with FLAG_ACTIVITY_NEW_TASK. Do not use this flag for intents resolving to Gallery2 for media URIs. Change-Id: I26d36536bf071403bfd6d8430c2656f1b3ec3449 --- .../filemanager/ui/policy/IntentsActionPolicy.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/com/cyanogenmod/filemanager/ui/policy/IntentsActionPolicy.java b/src/com/cyanogenmod/filemanager/ui/policy/IntentsActionPolicy.java index 026e31c..5dcab23 100644 --- a/src/com/cyanogenmod/filemanager/ui/policy/IntentsActionPolicy.java +++ b/src/com/cyanogenmod/filemanager/ui/policy/IntentsActionPolicy.java @@ -27,6 +27,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Bundle; +import android.provider.MediaStore; import android.util.Log; import android.widget.Toast; @@ -83,6 +84,11 @@ public final class IntentsActionPolicy extends ActionsPolicy { "com.cyanogenmod.filemanager.category.EDITOR"; //$NON-NLS-1$ /** + * The package name of Gallery2. + */ + public static final String GALLERY2_PACKAGE = "com.android.gallery3d"; + + /** * Method that opens a {@link FileSystemObject} with the default registered application * by the system, or ask the user for select a registered application. * @@ -484,8 +490,15 @@ public final class IntentsActionPolicy extends ActionsPolicy { } intent.setAction(a); } else { - // Create a new stack for the activity - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + // Opening image files with Gallery2 will behave incorrectly when started + // as a new task. We want to be able to return to CMFM with the back button. + if (!(Intent.ACTION_VIEW.equals(intent.getAction()) + && isGallery2(ri) + && intent.getData() != null + && MediaStore.AUTHORITY.equals(intent.getData().getAuthority()))) { + // Create a new stack for the activity + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + } intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); } @@ -578,6 +591,10 @@ public final class IntentsActionPolicy extends ActionsPolicy { IntentsActionPolicy.CATEGORY_INTERNAL_VIEWER, false); } + public static final boolean isGallery2(ResolveInfo ri) { + return GALLERY2_PACKAGE.equals(ri.activityInfo.packageName); + } + /** * Method that retrieve the finds the preferred activity, if one exists. In case * of multiple preferred activity exists the try to choose the better -- 2.11.0