Search in sources :

Example 16 with MatrixCursor

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

the class UsbStorageProvider method queryDocument.

@Override
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
    try {
        updateSettings();
        final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
        if (requestPermission()) {
            includeFile(result, getFileForDocId(documentId));
        } else {
            includeDefaultDocument(result, documentId);
        }
        return result;
    } catch (IOException e) {
        throw new FileNotFoundException(e.getMessage());
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 17 with MatrixCursor

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

the class UsbStorageProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
    try {
        updateSettings();
        final MatrixCursor result = new DocumentCursor(resolveDocumentProjection(projection), parentDocumentId);
        UsbFile parent;
        try {
            parent = getFileForDocId(parentDocumentId);
        } catch (Exception e) {
            return result;
        }
        for (UsbFile child : parent.listFiles()) {
            includeFile(result, child);
        }
        return result;
    } catch (IOException e) {
        throw new FileNotFoundException(e.getMessage());
    }
}
Also used : UsbFile(com.github.mjdev.libaums.fs.UsbFile) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 18 with MatrixCursor

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

the class UsbStorageProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    for (ArrayMap.Entry<String, UsbPartition> root : mRoots.entrySet()) {
        UsbPartition usbPartition = root.getValue();
        UsbDevice usbDevice = usbPartition.device;
        FileSystem fileSystem = usbPartition.fileSystem;
        UsbFile rootDirectory = null;
        String volumeLabel = null;
        Long availableBytes = 0L;
        Long capactityBytes = 0L;
        String documentId = root.getKey() + ROOT_SEPERATOR;
        if (null != fileSystem) {
            rootDirectory = fileSystem.getRootDirectory();
            volumeLabel = fileSystem.getVolumeLabel();
            availableBytes = fileSystem.getFreeSpace();
            capactityBytes = fileSystem.getCapacity();
            documentId = getDocIdForFile(rootDirectory);
        }
        String title = UsbUtils.getName(usbDevice);
        if (TextUtils.isEmpty(title)) {
            title = getContext().getString(R.string.root_usb);
        }
        int flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_EDIT | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPPORTS_IS_CHILD;
        final MatrixCursor.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, title);
        row.add(Root.COLUMN_FLAGS, flags);
        // These columns are optional
        row.add(Root.COLUMN_SUMMARY, volumeLabel);
        row.add(Root.COLUMN_AVAILABLE_BYTES, availableBytes);
        row.add(Root.COLUMN_CAPACITY_BYTES, capactityBytes);
        row.add(Root.COLUMN_PATH, UsbUtils.getPath(usbDevice));
    // Root.COLUMN_MIME_TYPE is another optional column and useful if you have multiple roots with different
    // types of mime types (roots that don't match the requested mime type are automatically hidden)
    }
    return result;
}
Also used : UsbFile(com.github.mjdev.libaums.fs.UsbFile) FileSystem(com.github.mjdev.libaums.fs.FileSystem) UsbDevice(android.hardware.usb.UsbDevice) ArrayMap(android.support.v4.util.ArrayMap) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 19 with MatrixCursor

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

the class DocumentArchive method queryDocument.

/**
 * Returns metadata of a document within an archive.
 */
public Cursor queryDocument(String documentId, @Nullable String[] projection) throws FileNotFoundException {
    final ParsedDocumentId parsedId = ParsedDocumentId.fromDocumentId(documentId, mIdDelimiter);
    Preconditions.checkArgumentEquals(mDocumentId, parsedId.mArchiveId, "Mismatching document ID. Expected: %s, actual: %s.");
    Preconditions.checkArgumentNotNull(parsedId.mPath, "Not a document within an archive.");
    final ZipEntry entry = mEntries.get(parsedId.mPath);
    if (entry == null) {
        throw new FileNotFoundException();
    }
    final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_PROJECTION);
    if (mNotificationUri != null) {
        result.setNotificationUri(mContext.getContentResolver(), mNotificationUri);
    }
    addCursorRow(result, entry);
    return result;
}
Also used : ZipEntry(java.util.zip.ZipEntry) FileNotFoundException(java.io.FileNotFoundException) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 20 with MatrixCursor

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

the class DocumentArchive method addCursorRow.

private void addCursorRow(MatrixCursor cursor, ZipEntry entry) {
    final MatrixCursor.RowBuilder row = cursor.newRow();
    final ParsedDocumentId parsedId = new ParsedDocumentId(mDocumentId, entry.getName());
    row.add(Document.COLUMN_DOCUMENT_ID, parsedId.toDocumentId(mIdDelimiter));
    final File file = new File(entry.getName());
    row.add(Document.COLUMN_DISPLAY_NAME, file.getName());
    row.add(Document.COLUMN_SIZE, entry.getSize());
    final String mimeType = getMimeTypeForEntry(entry);
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    final int flags = mimeType.startsWith("image/") ? Document.FLAG_SUPPORTS_THUMBNAIL : 0;
    row.add(Document.COLUMN_FLAGS, flags);
}
Also used : ZipFile(java.util.zip.ZipFile) File(java.io.File) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) Point(android.graphics.Point)

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