OSDN Git Service

cmfm: add support for Intent.EXTRA_MIME_TYPES
authorJorge Ruesga <jorge@ruesga.com>
Thu, 26 Feb 2015 01:00:56 +0000 (02:00 +0100)
committerJorge Ruesga <jorge@ruesga.com>
Fri, 27 Feb 2015 17:23:07 +0000 (18:23 +0100)
Since KitKat GET_CONTENT supports Intent.EXTRA_MIME_TYPES to limit the mime types of the returned
data. Use this information to add mimetype restrictions (if #getType is not present).

Change-Id: Ia968e06d899f695ea555c746d90bb5a3231cc1c9
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
src/com/cyanogenmod/filemanager/activities/PickerActivity.java
src/com/cyanogenmod/filemanager/preferences/DisplayRestrictions.java
src/com/cyanogenmod/filemanager/util/FileHelper.java

index e269e3a..5f61927 100644 (file)
@@ -21,7 +21,6 @@ import android.app.AlertDialog;
 import android.content.ActivityNotFoundException;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
-import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnCancelListener;
@@ -209,6 +208,7 @@ public class PickerActivity extends Activity
         }
 
         // Display restrictions
+        Bundle extras = getIntent().getExtras();
         Map<DisplayRestrictions, Object> restrictions = new HashMap<DisplayRestrictions, Object>();
         //- Mime/Type restriction
         String mimeType = getIntent().getType();
@@ -221,9 +221,13 @@ public class PickerActivity extends Activity
                 mimeType = MimeTypeHelper.ALL_MIME_TYPES;
             }
             restrictions.put(DisplayRestrictions.MIME_TYPE_RESTRICTION, mimeType);
+        } else {
+            String[] mimeTypes = getIntent().getStringArrayExtra(Intent.EXTRA_MIME_TYPES);
+            if (mimeTypes != null && mimeTypes.length > 0) {
+                restrictions.put(DisplayRestrictions.MIME_TYPE_RESTRICTION, mimeTypes);
+            }
         }
         // Other restrictions
-        Bundle extras = getIntent().getExtras();
         Log.d(TAG, "PickerActivity. extras: " + String.valueOf(extras)); //$NON-NLS-1$
         if (extras != null) {
             //-- File size
index 7b1e9cf..9c88dea 100644 (file)
@@ -25,7 +25,8 @@ public enum DisplayRestrictions {
      */
     CATEGORY_TYPE_RESTRICTION,
     /**
-     * Restriction for display only files with the mime/type.
+     * Restriction for display only files with these mime/types (this restriction
+     * accepts a String or String[] as parameter).
      */
     MIME_TYPE_RESTRICTION,
     /**
index eb245f1..93a2df0 100644 (file)
@@ -721,15 +721,29 @@ public final class FileHelper {
                     break;
 
                 case MIME_TYPE_RESTRICTION:
+                    String[] mimeTypes = null;
                     if (value instanceof String) {
-                        String mimeType = (String)value;
-                        if (mimeType.compareTo(MimeTypeHelper.ALL_MIME_TYPES) != 0) {
+                        mimeTypes = new String[] {(String) value};
+                    } else if (value instanceof String[]) {
+                        mimeTypes = (String[]) value;
+                    }
+                    if (mimeTypes != null) {
+                        boolean matches = false;
+                        for (String mimeType : mimeTypes) {
+                            if (mimeType.compareTo(MimeTypeHelper.ALL_MIME_TYPES) == 0) {
+                                matches = true;
+                                break;
+                            }
                             // NOTE: We don't need the context here, because mime-type
                             // database should be loaded prior to this call
-                            if (!MimeTypeHelper.matchesMimeType(null, fso, mimeType)) {
-                                return false;
+                            if (MimeTypeHelper.matchesMimeType(null, fso, mimeType)) {
+                                matches = true;
+                                break;
                             }
                         }
+                        if (!matches) {
+                            return false;
+                        }
                     }
                     break;