Search in sources :

Example 6 with MatrixCursor

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.

the class MediaDocumentsProvider method queryRecentDocuments.

@Override
public Cursor queryRecentDocuments(String rootId, String[] projection) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_IMAGES_ROOT.equals(rootId)) {
            // include all unique buckets
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI, ImageQuery.PROJECTION, null, null, ImageColumns.DATE_MODIFIED + " DESC");
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext() && result.getCount() < 64) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(rootId)) {
            // include all unique buckets
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI, VideoQuery.PROJECTION, null, null, VideoColumns.DATE_MODIFIED + " DESC");
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext() && result.getCount() < 64) {
                includeVideo(result, cursor);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported root " + rootId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
Also used : MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) ContentResolver(android.content.ContentResolver)

Example 7 with MatrixCursor

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.

the class MediaDocumentsProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String docId, String[] projection, String sortOrder) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final Ident ident = getIdentForDocId(docId);
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_IMAGES_ROOT.equals(ident.type)) {
            // include all unique buckets
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI, ImagesBucketQuery.PROJECTION, null, null, ImagesBucketQuery.SORT_ORDER);
            // multiple orders
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            long lastId = Long.MIN_VALUE;
            while (cursor.moveToNext()) {
                final long id = cursor.getLong(ImagesBucketQuery.BUCKET_ID);
                if (lastId != id) {
                    includeImagesBucket(result, cursor);
                    lastId = id;
                }
            }
        } else if (TYPE_IMAGES_BUCKET.equals(ident.type)) {
            // include images under bucket
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI, ImageQuery.PROJECTION, ImageColumns.BUCKET_ID + "=" + ident.id, null, null);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext()) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(ident.type)) {
            // include all unique buckets
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI, VideosBucketQuery.PROJECTION, null, null, VideosBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            long lastId = Long.MIN_VALUE;
            while (cursor.moveToNext()) {
                final long id = cursor.getLong(VideosBucketQuery.BUCKET_ID);
                if (lastId != id) {
                    includeVideosBucket(result, cursor);
                    lastId = id;
                }
            }
        } else if (TYPE_VIDEOS_BUCKET.equals(ident.type)) {
            // include videos under bucket
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI, VideoQuery.PROJECTION, VideoColumns.BUCKET_ID + "=" + ident.id, null, null);
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext()) {
                includeVideo(result, cursor);
            }
        } else if (TYPE_AUDIO_ROOT.equals(ident.type)) {
            /*                // include all artists
                cursor = resolver.query(Audio.Artists.EXTERNAL_CONTENT_URI,
                        ArtistQuery.PROJECTION, null, null, null);
                copyNotificationUri(result, Artists.EXTERNAL_CONTENT_URI);
                while (cursor.moveToNext()) {
                    includeArtist(result, cursor);
                }*/
            // include all albums under artist
            cursor = resolver.query(Audio.Albums.EXTERNAL_CONTENT_URI, AlbumQuery.PROJECTION, null, null, null);
            copyNotificationUri(result, Audio.Albums.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext()) {
                includeAlbum(result, cursor);
            }
        } else if (TYPE_ARTIST.equals(ident.type)) {
            // include all albums under artist
            cursor = resolver.query(Artists.Albums.getContentUri("external", ident.id), AlbumQuery.PROJECTION, null, null, null);
            copyNotificationUri(result, Artists.Albums.getContentUri("external", ident.id));
            while (cursor.moveToNext()) {
                includeAlbum(result, cursor);
            }
        } else if (TYPE_ALBUM.equals(ident.type)) {
            // include all songs under album
            cursor = resolver.query(Audio.Media.EXTERNAL_CONTENT_URI, SongQuery.PROJECTION, AudioColumns.ALBUM_ID + "=" + ident.id, null, null);
            copyNotificationUri(result, Audio.Media.EXTERNAL_CONTENT_URI);
            while (cursor.moveToNext()) {
                includeAudio(result, cursor);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported document " + docId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
Also used : MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) ContentResolver(android.content.ContentResolver)

Example 8 with MatrixCursor

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.

the class MediaDocumentsProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    includeImagesRoot(result);
    includeVideosRoot(result);
    includeAudioRoot(result);
    return result;
}
Also used : MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 9 with MatrixCursor

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.

the class NetworkStorageProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final NetworkFile parent = getFileForDocId(parentDocumentId);
    final NetworkConnection connection = getNetworkConnection(parentDocumentId);
    try {
        connection.getConnectedClient().changeWorkingDirectory(parent.getPath());
        for (FTPFile file : connection.getConnectedClient().listFiles()) {
            includeFile(result, null, new NetworkFile(parent, file));
        }
    } catch (IOException e) {
        CrashReportingManager.logException(e);
    }
    return result;
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) FTPFile(org.apache.commons.net.ftp.FTPFile) IOException(java.io.IOException) NetworkFile(dev.dworks.apps.anexplorer.network.NetworkFile) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 10 with MatrixCursor

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.

the class NetworkStorageProvider method queryDocument.

@Override
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    includeFile(result, documentId, null);
    return result;
}
Also used : MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Aggregations

MatrixCursor (dev.dworks.apps.anexplorer.cursor.MatrixCursor)37 Cursor (android.database.Cursor)10 RowBuilder (dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder)7 ContentResolver (android.content.ContentResolver)6 File (java.io.File)6 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)5 Query (android.app.DownloadManager.Query)4 DocumentFile (android.support.provider.DocumentFile)3 UsbFile (com.github.mjdev.libaums.fs.UsbFile)3 FileUtils.getTypeForFile (dev.dworks.apps.anexplorer.misc.FileUtils.getTypeForFile)3 ArrayMap (android.support.v4.util.ArrayMap)2 NetworkConnection (dev.dworks.apps.anexplorer.network.NetworkConnection)2 RootFile (dev.dworks.apps.anexplorer.root.RootFile)2 BufferedReader (java.io.BufferedReader)2 Scanner (java.util.Scanner)2 ZipEntry (java.util.zip.ZipEntry)2 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)1 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)1 DownloadManager (android.app.DownloadManager)1