Search in sources :

Example 31 with RowBuilder

use of dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder 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 32 with RowBuilder

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

the class HeatMapProvider method includeFile.

private void includeFile(MatrixCursor result, String docId, File file) throws FileNotFoundException {
    if (docId == null) {
        docId = getDocIdForFile(file);
    } else {
        file = getFileForDocId(docId);
    }
    int flags = 0;
    if (file.canWrite()) {
        if (file.isDirectory()) {
            flags |= Document.FLAG_DIR_SUPPORTS_CREATE;
        } else {
            flags |= Document.FLAG_SUPPORTS_WRITE;
        }
        flags |= Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_EDIT;
    }
    final String displayName = file.getName();
    final String mimeType = getTypeForFile(file);
    if (mimeType.startsWith("image/") || mimeType.startsWith("audio/") || mimeType.startsWith("video/") || mimeType.startsWith("application/vnd.android.package-archive")) {
        flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
    }
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);
    row.add(Document.COLUMN_DISPLAY_NAME, displayName);
    row.add(Document.COLUMN_SIZE, file.length());
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    row.add(Document.COLUMN_PATH, file.getAbsolutePath());
    row.add(Document.COLUMN_FLAGS, flags);
    if (file.isDirectory() && null != file.list()) {
        String summary = FileUtils.formatFileCount(file.list().length);
        row.add(Document.COLUMN_SUMMARY, summary);
    }
    // Only publish dates reasonably after epoch
    long lastModified = file.lastModified();
    if (lastModified > 31536000000L) {
        row.add(Document.COLUMN_LAST_MODIFIED, lastModified);
    }
}
Also used : RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 33 with RowBuilder

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

the class HeatMapProvider method queryDocument.

@Override
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    // includeFile(result, documentId, null);
    synchronized (mRootsLock) {
        for (String rootId : mIdToPath.keySet()) {
            final RootInfo root = mIdToRoot.get(rootId);
            final File path = mIdToPath.get(rootId);
            final String mimeType = getTypeForFile(path);
            final RowBuilder row = result.newRow();
            // row.add(Document.COLUMN_DOCUMENT_ID, documentId);
            row.add(Document.COLUMN_DOCUMENT_ID, root.docId);
            row.add(Document.COLUMN_FLAGS, root.flags);
            row.add(Document.COLUMN_DISPLAY_NAME, root.title);
            row.add(Document.COLUMN_MIME_TYPE, mimeType);
            row.add(Document.COLUMN_PATH, path.getAbsolutePath());
            if (ROOT_ID_PRIMARY_EMULATED.equals(root.rootId) || root.rootId.startsWith(ROOT_ID_SECONDARY)) {
                row.add(Document.COLUMN_SIZE, path.getFreeSpace());
            }
            if (path.isDirectory() && null != path.list()) {
                String summary = FileUtils.formatFileCount(path.list().length);
                row.add(Document.COLUMN_SUMMARY, summary);
            }
            // Only publish dates reasonably after epoch
            long lastModified = path.lastModified();
            if (lastModified > 31536000000L) {
                row.add(Document.COLUMN_LAST_MODIFIED, lastModified);
            }
        }
    }
    return result;
}
Also used : RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder) File(java.io.File) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor)

Example 34 with RowBuilder

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

the class NonMediaDocumentsProvider method includeFileRootDocument.

private void includeFileRootDocument(MatrixCursor result, String root_type, int name_id) {
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, root_type);
    row.add(Document.COLUMN_DISPLAY_NAME, getContext().getString(name_id));
    row.add(Document.COLUMN_FLAGS, Document.FLAG_DIR_PREFERS_GRID | Document.FLAG_DIR_PREFERS_LAST_MODIFIED | Document.FLAG_SUPPORTS_DELETE);
    row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
}
Also used : RowBuilder(dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder)

Aggregations

RowBuilder (dev.dworks.apps.anexplorer.cursor.MatrixCursor.RowBuilder)34 Point (android.graphics.Point)11 SuppressLint (android.annotation.SuppressLint)7 MatrixCursor (dev.dworks.apps.anexplorer.cursor.MatrixCursor)7 ApplicationInfo (android.content.pm.ApplicationInfo)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 DocumentFile (android.support.provider.DocumentFile)2 ArrayMap (android.support.v4.util.ArrayMap)1 FileUtils.getTypeForFile (dev.dworks.apps.anexplorer.misc.FileUtils.getTypeForFile)1 StorageUtils (dev.dworks.apps.anexplorer.misc.StorageUtils)1 DocumentInfo.getCursorString (dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString)1 NetworkConnection (dev.dworks.apps.anexplorer.network.NetworkConnection)1 Map (java.util.Map)1