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

Commit 39bb8290 authored by Jorge Ruesga's avatar Jorge Ruesga
Browse files

cmfm: add support for Intent.EXTRA_MIME_TYPES



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: default avatarJorge Ruesga <jorge@ruesga.com>
parent 75eb5095
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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,
    /**
+18 −4
Original line number Diff line number Diff line
@@ -721,14 +721,28 @@ 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;