use of dev.dworks.apps.anexplorer.cursor.MatrixCursor 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;
}
use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.
the class NonMediaDocumentsProvider 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_DOCUMENT_ROOT.equals(ident.type)) {
includeFileRootDocument(result, TYPE_DOCUMENT_ROOT, R.string.root_document);
} else if (TYPE_DOCUMENT.equals(ident.type)) {
queryFile(resolver, cursor, result, DOCUMENT_MIMES, "text");
} else if (TYPE_ARCHIVE_ROOT.equals(ident.type)) {
includeFileRootDocument(result, TYPE_ARCHIVE_ROOT, R.string.root_archive);
} else if (TYPE_ARCHIVE.equals(ident.type)) {
queryFile(resolver, cursor, result, ARCHIVE_MIMES);
} else if (TYPE_APK_ROOT.equals(ident.type)) {
includeFileRootDocument(result, TYPE_APK_ROOT, R.string.root_apk);
} else if (TYPE_APK.equals(ident.type)) {
queryFile(resolver, cursor, result, APK_MIMES);
} else {
throw new UnsupportedOperationException("Unsupported document " + docId);
}
} finally {
IoUtils.closeQuietly(cursor);
Binder.restoreCallingIdentity(token);
}
return result;
}
use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.
the class NonMediaDocumentsProvider 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_DOCUMENT_ROOT.equals(ident.type)) {
queryFile(resolver, cursor, result, DOCUMENT_MIMES, "text");
} else if (TYPE_ARCHIVE_ROOT.equals(ident.type)) {
queryFile(resolver, cursor, result, ARCHIVE_MIMES);
} else if (TYPE_APK_ROOT.equals(ident.type)) {
queryFile(resolver, cursor, result, APK_MIMES);
} else {
throw new UnsupportedOperationException("Unsupported document " + docId);
}
} finally {
IoUtils.closeQuietly(cursor);
Binder.restoreCallingIdentity(token);
}
return result;
}
use of dev.dworks.apps.anexplorer.cursor.MatrixCursor 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;
}
use of dev.dworks.apps.anexplorer.cursor.MatrixCursor in project AnExplorer by 1hakr.
the class RootedStorageProvider method queryChildDocuments.
@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
final RootFile parent = getRootFileForDocId(parentDocumentId);
final MatrixCursor result = new DirectoryCursor(resolveDocumentProjection(projection), parentDocumentId, parent);
try {
BufferedReader br = RootCommands.listFiles(parent.getPath());
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) {
e.printStackTrace();
}
}
scanner.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
Aggregations