Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 41e0d746 authored by Matt Garnes's avatar Matt Garnes
Browse files

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
parent 2ad1c339
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -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;

@@ -82,6 +83,11 @@ public final class IntentsActionPolicy extends ActionsPolicy {
    public static final String CATEGORY_EDITOR =
            "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 {
            // 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