Search in sources :

Example 1 with RootFile

use of dev.dworks.apps.anexplorer.root.RootFile in project AnExplorer by 1hakr.

the class RootedStorageProvider method updateRoots.

@Override
public void updateRoots() {
    mRoots.clear();
    try {
        final String rootId = ROOT_ID_ROOT;
        final RootFile path = new RootFile("/");
        final RootInfo root = new RootInfo();
        mRoots.put(rootId, root);
        root.rootId = rootId;
        root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_EDIT | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED;
        root.title = getContext().getString(R.string.root_root_storage);
        root.path = path;
        root.docId = getDocIdForRootFile(path);
    } catch (FileNotFoundException e) {
        CrashReportingManager.logException(e);
    }
    notifyRootsChanged(getContext());
}
Also used : FileNotFoundException(java.io.FileNotFoundException) RootFile(dev.dworks.apps.anexplorer.root.RootFile)

Example 2 with RootFile

use of dev.dworks.apps.anexplorer.root.RootFile in project AnExplorer by 1hakr.

the class RootedStorageProvider method openOrCreateDocumentThumbnail.

public AssetFileDescriptor openOrCreateDocumentThumbnail(String docId, Point sizeHint, CancellationSignal signal) throws FileNotFoundException {
    // final ContentResolver resolver = getContext().getContentResolver();
    final RootFile file = getRootFileForDocId(docId);
    final String mimeType = getTypeForFile(file);
    final String typeOnly = mimeType.split("/")[0];
    final long token = Binder.clearCallingIdentity();
    try {
        if ("audio".equals(typeOnly)) {
            final long id = getAlbumForPathCleared(file.getPath());
            return openOrCreateAudioThumbnailCleared(id, signal);
        } else if ("image".equals(typeOnly)) {
            final long id = getImageForPathCleared(file.getPath());
            return openOrCreateImageThumbnailCleared(id, signal);
        } else if ("video".equals(typeOnly)) {
            final long id = getVideoForPathCleared(file.getPath());
            return openOrCreateVideoThumbnailCleared(id, signal);
        } else {
            // DocumentsContract.openImageThumbnail(file);
            return null;
        }
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : RootFile(dev.dworks.apps.anexplorer.root.RootFile)

Example 3 with RootFile

use of dev.dworks.apps.anexplorer.root.RootFile in project AnExplorer by 1hakr.

the class RootedStorageProvider method renameDocument.

@Override
public String renameDocument(String documentId, String displayName) throws FileNotFoundException {
    // Since this provider treats renames as generating a completely new
    // docId, we're okay with letting the MIME type change.
    displayName = FileUtils.buildValidFatFilename(displayName);
    final RootFile before = getRootFileForDocId(documentId);
    final RootFile after = new RootFile(before.getParent(), displayName);
    if (!RootCommands.renameRootTarget(before, after)) {
        throw new IllegalStateException("Failed to rename " + before);
    }
    final String afterDocId = getDocIdForRootFile(new RootFile(after.getParent(), displayName));
    if (!TextUtils.equals(documentId, afterDocId)) {
        notifyDocumentsChanged(documentId);
        return afterDocId;
    } else {
        return null;
    }
}
Also used : RootFile(dev.dworks.apps.anexplorer.root.RootFile)

Example 4 with RootFile

use of dev.dworks.apps.anexplorer.root.RootFile in project AnExplorer by 1hakr.

the class RootedStorageProvider method deleteDocument.

@Override
public void deleteDocument(String docId) throws FileNotFoundException {
    final RootFile file = getRootFileForDocId(docId);
    if (!RootCommands.deleteFileRoot(file.getPath())) {
        throw new IllegalStateException("Failed to delete " + file);
    }
    notifyDocumentsChanged(docId);
}
Also used : RootFile(dev.dworks.apps.anexplorer.root.RootFile)

Example 5 with RootFile

use of dev.dworks.apps.anexplorer.root.RootFile in project AnExplorer by 1hakr.

the class RootedStorageProvider method querySearchDocuments.

@SuppressWarnings("unused")
@Override
public Cursor querySearchDocuments(String rootId, String query, String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final RootFile parent;
    synchronized (mRootsLock) {
        parent = mRoots.get(rootId).path;
    }
    try {
        BufferedReader br = RootCommands.findFiles(parent.getPath(), query);
        if (null != br) {
            Scanner scanner = new Scanner(br);
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                try {
                    includeRootFile(result, null, new RootFile(parent, line));
                } catch (Exception e) {
                    CrashReportingManager.logException(e);
                }
            }
            scanner.close();
        }
    } catch (Exception e) {
        CrashReportingManager.logException(e);
    }
    return result;
}
Also used : Scanner(java.util.Scanner) BufferedReader(java.io.BufferedReader) RootFile(dev.dworks.apps.anexplorer.root.RootFile) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

RootFile (dev.dworks.apps.anexplorer.root.RootFile)11 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)4 Point (android.graphics.Point)2 MatrixCursor (dev.dworks.apps.anexplorer.cursor.MatrixCursor)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 Scanner (java.util.Scanner)2 InputStream (java.io.InputStream)1