Search in sources :

Example 26 with MatrixCursor

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

the class ExternalStorageProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
    if (mArchiveHelper.isArchivedDocument(parentDocumentId) || DocumentArchiveHelper.isSupportedArchiveType(getDocumentType(parentDocumentId))) {
        return mArchiveHelper.queryChildDocuments(parentDocumentId, projection, sortOrder);
    }
    final File parent = getFileForDocId(parentDocumentId);
    final MatrixCursor result = new DirectoryCursor(resolveDocumentProjection(projection), parentDocumentId, parent);
    updateSettings();
    for (File file : parent.listFiles()) {
        includeFile(result, null, file);
    }
    return result;
}
Also used : FileUtils.getTypeForFile(dev.dworks.apps.anexplorer.misc.FileUtils.getTypeForFile) DocumentFile(android.support.provider.DocumentFile) File(java.io.File) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 27 with MatrixCursor

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

the class ExternalStorageProvider method querySearchDocuments.

@Override
public Cursor querySearchDocuments(String rootId, String query, String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final File parent;
    synchronized (mRootsLock) {
        parent = mRoots.get(rootId).path;
    }
    updateSettings();
    for (File file : FileUtils.searchDirectory(parent.getPath(), query)) {
        includeFile(result, null, file);
    }
    return result;
}
Also used : FileUtils.getTypeForFile(dev.dworks.apps.anexplorer.misc.FileUtils.getTypeForFile) DocumentFile(android.support.provider.DocumentFile) File(java.io.File) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 28 with MatrixCursor

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

the class MediaDocumentsProvider method queryDocument.

@Override
public Cursor queryDocument(String docId, String[] projection) 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)) {
            // single root
            includeImagesRootDocument(result);
        } else if (TYPE_IMAGES_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI, ImagesBucketQuery.PROJECTION, ImageColumns.BUCKET_ID + "=" + ident.id, null, ImagesBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImagesBucket(result, cursor);
            }
        } else if (TYPE_IMAGE.equals(ident.type)) {
            // single image
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI, ImageQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null, null);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(ident.type)) {
            // single root
            includeVideosRootDocument(result);
        } else if (TYPE_VIDEOS_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI, VideosBucketQuery.PROJECTION, VideoColumns.BUCKET_ID + "=" + ident.id, null, VideosBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideosBucket(result, cursor);
            }
        } else if (TYPE_VIDEO.equals(ident.type)) {
            // single video
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI, VideoQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null, null);
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideo(result, cursor);
            }
        } else if (TYPE_AUDIO_ROOT.equals(ident.type)) {
            // single root
            includeAudioRootDocument(result);
        } else if (TYPE_ARTIST.equals(ident.type)) {
            // single artist
            cursor = resolver.query(Artists.EXTERNAL_CONTENT_URI, ArtistQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null, null);
            copyNotificationUri(result, Artists.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeArtist(result, cursor);
            }
        } else if (TYPE_ALBUM.equals(ident.type)) {
            // single album
            cursor = resolver.query(Albums.EXTERNAL_CONTENT_URI, AlbumQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null, null);
            copyNotificationUri(result, Albums.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAlbum(result, cursor);
            }
        } else if (TYPE_AUDIO.equals(ident.type)) {
            // single song
            cursor = resolver.query(Audio.Media.EXTERNAL_CONTENT_URI, SongQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null, null);
            copyNotificationUri(result, Audio.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                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 29 with MatrixCursor

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

the class NetworkStorageProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    synchronized (mRootsLock) {
        for (Map.Entry<String, NetworkConnection> root : mRoots.entrySet()) {
            NetworkConnection networkConnection = root.getValue();
            String documentId = getDocIdForFile(networkConnection.file);
            int flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPPORTS_IS_CHILD;
            boolean isServer = networkConnection.getType().compareToIgnoreCase(SERVER) == 0;
            if (isServer) {
                if (!Utils.hasWiFi(getContext())) {
                    continue;
                }
                flags |= Root.FLAG_CONNECTION_SERVER;
            }
            final RowBuilder row = result.newRow();
            // These columns are required
            row.add(Root.COLUMN_ROOT_ID, root.getKey());
            row.add(Root.COLUMN_DOCUMENT_ID, documentId);
            row.add(Root.COLUMN_TITLE, networkConnection.name);
            row.add(Root.COLUMN_FLAGS, flags);
            // These columns are optional
            row.add(Root.COLUMN_SUMMARY, isServer ? networkConnection.getPath() : networkConnection.getSummary());
            row.add(Root.COLUMN_PATH, networkConnection.getPath());
        }
    }
    return result;
}
Also used : NetworkConnection(dev.dworks.apps.anexplorer.network.NetworkConnection) RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 30 with MatrixCursor

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

the class HeatMapProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
    final File parent = getFileForDocId(parentDocumentId);
    final MatrixCursor result = new DirectoryCursor(resolveDocumentProjection(projection), parentDocumentId, parent);
    for (File file : parent.listFiles()) {
        includeFile(result, null, file);
    }
    return result;
}
Also used : File(java.io.File) 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