aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Mertz <scott@cyngn.com>2016-06-23 10:59:21 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-06-23 14:30:59 -0700
commit58688653758ac52c79bcca311751db30dda97f50 (patch)
treeb1aa63852e9f12feec1578621f144b971ae2f16c
parent8328024c8409c947d69092479073c16ac3f1aa2a (diff)
downloadandroid_packages_apps_CMFileManager-58688653758ac52c79bcca311751db30dda97f50.tar.gz
android_packages_apps_CMFileManager-58688653758ac52c79bcca311751db30dda97f50.tar.bz2
android_packages_apps_CMFileManager-58688653758ac52c79bcca311751db30dda97f50.zip
Remove send/send multiple if intent doesn't resolve to any activity
Instead of falling back to the editor activity as a last resort for "Send", remove the option if there's no potential candidate. The editor activity won't handle the ACTION_SEND/ACTION_SEND_MULTIPLE intent anyway. This stops an error from popping up in the editor if the file cannot be sent from any other activity. FEIJ-1380 Change-Id: I2330299e0cb8b6f3c93d5a190067b8bfe6a3f56f (cherry picked from commit 92ac0ff6ad6e6cc774c634bbd4b78856942e98c2)
-rw-r--r--src/com/cyanogenmod/filemanager/ui/dialogs/ActionsDialog.java7
-rwxr-xr-xsrc/com/cyanogenmod/filemanager/ui/policy/IntentsActionPolicy.java110
2 files changed, 68 insertions, 49 deletions
diff --git a/src/com/cyanogenmod/filemanager/ui/dialogs/ActionsDialog.java b/src/com/cyanogenmod/filemanager/ui/dialogs/ActionsDialog.java
index 4aaf32d0..75514757 100644
--- a/src/com/cyanogenmod/filemanager/ui/dialogs/ActionsDialog.java
+++ b/src/com/cyanogenmod/filemanager/ui/dialogs/ActionsDialog.java
@@ -653,6 +653,10 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
menu.removeItem(R.id.mnu_actions_send);
}
+ if (!IntentsActionPolicy.sendHandledByAnyActivity(mContext, this.mFso)) {
+ menu.removeItem(R.id.mnu_actions_send);
+ }
+
// Create link (not allow in storage volume)
if (StorageHelper.isPathInStorageVolume(this.mFso.getFullPath())) {
menu.removeItem(R.id.mnu_actions_create_link);
@@ -758,7 +762,8 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
break;
}
}
- if (!areAllFiles) {
+ if (!areAllFiles ||
+ !IntentsActionPolicy.sendHandledByAnyActivity(mContext, selection)) {
menu.removeItem(R.id.mnu_actions_send_selection);
}
}
diff --git a/src/com/cyanogenmod/filemanager/ui/policy/IntentsActionPolicy.java b/src/com/cyanogenmod/filemanager/ui/policy/IntentsActionPolicy.java
index 4944adf7..022de6c9 100755
--- a/src/com/cyanogenmod/filemanager/ui/policy/IntentsActionPolicy.java
+++ b/src/com/cyanogenmod/filemanager/ui/policy/IntentsActionPolicy.java
@@ -49,6 +49,7 @@ import com.cyanogenmod.filemanager.util.ResourcesHelper;
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -177,6 +178,65 @@ public final class IntentsActionPolicy extends ActionsPolicy {
return context.getPackageManager().queryIntentActivities(i, 0).size() > 0;
}
+ public static boolean sendHandledByAnyActivity(final Context ctx, final FileSystemObject fso) {
+ return ctx.getPackageManager().queryIntentActivities(getFsoSendIntent(ctx, fso), 0).size() > 0;
+ }
+
+ public static boolean sendHandledByAnyActivity(final Context ctx, final List<FileSystemObject> fsos) {
+ return ctx.getPackageManager().queryIntentActivities(getFsoSendIntent(ctx, fsos), 0).size() > 0;
+ }
+
+ private static Intent getFsoSendIntent(final Context ctx, final FileSystemObject fso) {
+ return getFsoSendIntent(ctx, Arrays.asList(fso));
+ }
+
+ private static Intent getFsoSendIntent(final Context ctx, final List<FileSystemObject> fsos) {
+ Intent intent = new Intent();
+ intent.setAction(fsos.size() > 1 ? Intent.ACTION_SEND_MULTIPLE : Intent.ACTION_SEND);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+
+ // Create an array list of the uris to send
+ ArrayList<Uri> uris = new ArrayList<Uri>();
+
+ int cc = fsos.size();
+ String lastMimeType = null;
+ boolean sameMimeType = true;
+ for (int i = 0; i < cc; i++) {
+ FileSystemObject fso = fsos.get(i);
+
+ // Folders are not allowed
+ if (FileHelper.isDirectory(fso)) continue;
+
+ // Check if we can use a unique mime/type
+ String mimeType = MimeTypeHelper.getMimeType(ctx, fso);
+ if (mimeType == null) {
+ sameMimeType = false;
+ }
+ if (sameMimeType &&
+ (mimeType != null && lastMimeType != null &&
+ mimeType.compareTo(lastMimeType) != 0)) {
+ sameMimeType = false;
+ }
+ lastMimeType = mimeType;
+
+ // Add the uri
+ uris.add(getUriFromFile(ctx, fso));
+ }
+ if (lastMimeType != null) {
+ if (sameMimeType) {
+ intent.setType(lastMimeType);
+ } else {
+ intent.setType(MimeTypeHelper.ALL_MIME_TYPES);
+ }
+ }
+ if (uris.size() > 1) {
+ intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
+ } else {
+ intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
+ }
+ return intent;
+ }
+
/**
* Method that sends a {@link FileSystemObject} with the default registered application
* by the system, or ask the user for select a registered application.
@@ -188,18 +248,10 @@ public final class IntentsActionPolicy extends ActionsPolicy {
public static void sendFileSystemObject(
final Context ctx, final FileSystemObject fso, OnDismissListener onDismissListener) {
try {
- // Create the intent to
- Intent intent = new Intent();
- intent.setAction(android.content.Intent.ACTION_SEND);
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- intent.setType(MimeTypeHelper.getMimeType(ctx, fso));
- Uri uri = getUriFromFile(ctx, fso);
- intent.putExtra(Intent.EXTRA_STREAM, uri);
-
// Resolve the intent
resolveIntent(
ctx,
- intent,
+ getFsoSendIntent(ctx, fso),
false,
onDismissListener);
@@ -220,48 +272,10 @@ public final class IntentsActionPolicy extends ActionsPolicy {
final Context ctx, final List<FileSystemObject> fsos,
OnDismissListener onDismissListener) {
try {
- // Create the intent to
- Intent intent = new Intent();
- intent.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
-
- // Create an array list of the uris to send
- ArrayList<Uri> uris = new ArrayList<Uri>();
- int cc = fsos.size();
- String lastMimeType = null;
- boolean sameMimeType = true;
- for (int i = 0; i < cc; i++) {
- FileSystemObject fso = fsos.get(i);
-
- // Folders are not allowed
- if (FileHelper.isDirectory(fso)) continue;
-
- // Check if we can use a unique mime/type
- String mimeType = MimeTypeHelper.getMimeType(ctx, fso);
- if (mimeType == null) {
- sameMimeType = false;
- }
- if (sameMimeType &&
- (mimeType != null && lastMimeType != null &&
- mimeType.compareTo(lastMimeType) != 0)) {
- sameMimeType = false;
- }
- lastMimeType = mimeType;
-
- // Add the uri
- uris.add(getUriFromFile(ctx, fso));
- }
- if (sameMimeType) {
- intent.setType(lastMimeType);
- } else {
- intent.setType(MimeTypeHelper.ALL_MIME_TYPES);
- }
- intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
-
// Resolve the intent
resolveIntent(
ctx,
- intent,
+ getFsoSendIntent(ctx, fsos),
false,
onDismissListener);