Example usage for android.support.v4.content CursorLoader loadInBackground

List of usage examples for android.support.v4.content CursorLoader loadInBackground

Introduction

In this page you can find the example usage for android.support.v4.content CursorLoader loadInBackground.

Prototype

@Override
    public Cursor loadInBackground() 

Source Link

Usage

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle arg1) {
    CursorLoader loader = null;
    int flag = (int) Math.pow(2, id + 1);
    if ((OpenCursor.LoadedCursors & flag) == flag)
        return null;
    switch (id) {
    case 0: // videos
        loader = new CursorLoader(getApplicationContext(), MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                //Uri.parse("content://media/external/video/media"),
                bRetrieveExtraVideoDetails
                        ? new String[] { "_id", "_display_name", "_data", "_size", "date_modified",
                                MediaStore.Video.VideoColumns.RESOLUTION,
                                MediaStore.Video.VideoColumns.DURATION }
                        : new String[] { "_id", "_display_name", "_data", "_size", "date_modified" },
                MediaStore.Video.Media.SIZE + " > 10000", null, MediaStore.Video.Media.BUCKET_DISPLAY_NAME
                        + " ASC, " + MediaStore.Video.Media.DATE_MODIFIED + " DESC");
        if (bRetrieveExtraVideoDetails)
            try {
                loader.loadInBackground();
            } catch (SQLiteException e) {
                bRetrieveExtraVideoDetails = false;
                setSetting("tag_novidinfo", true);
                return onCreateLoader(id, arg1);
            }/*from w w w  .  j  a va2 s . com*/
        break;
    case 1: // images
        loader = new CursorLoader(getApplicationContext(), Uri.parse("content://media/external/images/media"),
                bRetrieveDimensionsForPhotos ? // It seems that < 2.3.3 don't have width & height
                        new String[] { "_id", "_display_name", "_data", "_size", "date_modified", "width",
                                "height" }
                        : new String[] { "_id", "_display_name", "_data", "_size", "date_modified" },
                MediaStore.Images.Media.SIZE + " > 10000", null, MediaStore.Images.Media.DATE_ADDED + " DESC");
        if (bRetrieveDimensionsForPhotos) {
            try {
                loader.loadInBackground();
            } catch (SQLiteException e) {
                bRetrieveDimensionsForPhotos = false;
                setSetting("tag_nodims", true);
                return onCreateLoader(id, arg1);
            }
        }
        break;
    case 2: // music
        loader = new CursorLoader(getApplicationContext(), Uri.parse("content://media/external/audio/media"),
                new String[] { "_id", "_display_name", "_data", "_size", "date_modified",
                        MediaStore.Audio.AudioColumns.DURATION },
                MediaStore.Audio.Media.SIZE + " > 10000", null, MediaStore.Audio.Media.DATE_ADDED + " DESC");
        break;
    case 3: // apks
        if (bRetrieveCursorFiles)
            loader = new CursorLoader(getApplicationContext(), MediaStore.Files.getContentUri("/mnt"),
                    new String[] { "_id", "_display_name", "_data", "_size", "date_modified" },
                    "_size > 10000 AND _data LIKE '%apk'", null, "date modified DESC");
        break;
    }

    return loader;
}