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());
}
}
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());
}
}
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;
}
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;
}
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);
}
Aggregations