Java Code Examples for android.provider.DocumentsContract.Document#FLAG_DIR_SUPPORTS_CREATE
The following examples show how to use
android.provider.DocumentsContract.Document#FLAG_DIR_SUPPORTS_CREATE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppStorageProvider.java From JPPF with Apache License 2.0 | 6 votes |
/** * Add a row in the specified cursor for the specified file. * @param child the file for which to add a row. * @param cursor the cursor to add a row to. */ private void createRowForChild(File child, MatrixCursor cursor) { MatrixCursor.RowBuilder row = cursor.newRow(); String type = getContext().getContentResolver().getType(Uri.fromFile(child)); Log.v(LOG_TAG, "createRowForChild(child=" + child + ") type=" + type); if (type == null) type = child.isDirectory() ? Document.MIME_TYPE_DIR : "application/octet-stream"; int flags = child.isDirectory() ? /*Document.FLAG_DIR_PREFERS_GRID |*/ Document.FLAG_DIR_PREFERS_LAST_MODIFIED | Document.FLAG_DIR_SUPPORTS_CREATE : /*Document.FLAG_SUPPORTS_WRITE*/ 0; row.add(Document.COLUMN_FLAGS, flags); row.add(Document.COLUMN_DISPLAY_NAME, child.getName()); row.add(Document.COLUMN_DOCUMENT_ID, getDocumentId(child)); row.add(Document.COLUMN_MIME_TYPE, type); row.add(Document.COLUMN_SIZE, child.isDirectory() ? child.getTotalSpace() - child.getFreeSpace() : child.length()); row.add(Document.COLUMN_LAST_MODIFIED, null); }
Example 2
Source File: SambaDocumentsProvider.java From samba-documents-provider with GNU General Public License v3.0 | 5 votes |
private Object[] getDocumentValues( String[] projection, DocumentMetadata metadata) { Object[] row = new Object[projection.length]; for (int i = 0; i < projection.length; ++i) { switch (projection[i]) { case Document.COLUMN_DOCUMENT_ID: row[i] = toDocumentId(metadata.getUri()); break; case Document.COLUMN_DISPLAY_NAME: row[i] = metadata.getDisplayName(); break; case Document.COLUMN_FLAGS: // Always assume it can write to it until the file operation fails. Windows 10 also does // the same thing. int flag = metadata.canCreateDocument() ? Document.FLAG_DIR_SUPPORTS_CREATE : 0; flag |= Document.FLAG_SUPPORTS_WRITE; flag |= Document.FLAG_SUPPORTS_DELETE; flag |= Document.FLAG_SUPPORTS_RENAME; flag |= Document.FLAG_SUPPORTS_REMOVE; flag |= Document.FLAG_SUPPORTS_MOVE; row[i] = flag; break; case Document.COLUMN_MIME_TYPE: row[i] = metadata.getMimeType(); break; case Document.COLUMN_SIZE: row[i] = metadata.getSize(); break; case Document.COLUMN_LAST_MODIFIED: row[i] = metadata.getLastModified(); break; case Document.COLUMN_ICON: row[i] = metadata.getIconResourceId(); break; } } return row; }
Example 3
Source File: MyCloudProvider.java From storage-samples with Apache License 2.0 | 4 votes |
/** * Add a representation of a file to a cursor. * * @param result the cursor to modify * @param docId the document ID representing the desired file (may be null if given file) * @param file the File object representing the desired file (may be null if given docID) * @throws java.io.FileNotFoundException */ 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.isDirectory()) { // Request the folder to lay out as a grid rather than a list. This also allows a larger // thumbnail to be displayed for each image. // flags |= Document.FLAG_DIR_PREFERS_GRID; // Add FLAG_DIR_SUPPORTS_CREATE if the file is a writable directory. if (file.isDirectory() && file.canWrite()) { flags |= Document.FLAG_DIR_SUPPORTS_CREATE; } } else if (file.canWrite()) { // If the file is writable set FLAG_SUPPORTS_WRITE and // FLAG_SUPPORTS_DELETE flags |= Document.FLAG_SUPPORTS_WRITE; flags |= Document.FLAG_SUPPORTS_DELETE; } final String displayName = file.getName(); final String mimeType = getTypeForFile(file); if (mimeType.startsWith("image/")) { // Allow the image to be represented by a thumbnail rather than an icon flags |= Document.FLAG_SUPPORTS_THUMBNAIL; } final MatrixCursor.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_LAST_MODIFIED, file.lastModified()); row.add(Document.COLUMN_FLAGS, flags); // Add a custom icon row.add(Document.COLUMN_ICON, R.drawable.ic_launcher); }
Example 4
Source File: MyCloudProvider.java From android-StorageProvider with Apache License 2.0 | 4 votes |
/** * Add a representation of a file to a cursor. * * @param result the cursor to modify * @param docId the document ID representing the desired file (may be null if given file) * @param file the File object representing the desired file (may be null if given docID) * @throws java.io.FileNotFoundException */ 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.isDirectory()) { // Request the folder to lay out as a grid rather than a list. This also allows a larger // thumbnail to be displayed for each image. // flags |= Document.FLAG_DIR_PREFERS_GRID; // Add FLAG_DIR_SUPPORTS_CREATE if the file is a writable directory. if (file.isDirectory() && file.canWrite()) { flags |= Document.FLAG_DIR_SUPPORTS_CREATE; } } else if (file.canWrite()) { // If the file is writable set FLAG_SUPPORTS_WRITE and // FLAG_SUPPORTS_DELETE flags |= Document.FLAG_SUPPORTS_WRITE; flags |= Document.FLAG_SUPPORTS_DELETE; } final String displayName = file.getName(); final String mimeType = getTypeForFile(file); if (mimeType.startsWith("image/")) { // Allow the image to be represented by a thumbnail rather than an icon flags |= Document.FLAG_SUPPORTS_THUMBNAIL; } final MatrixCursor.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_LAST_MODIFIED, file.lastModified()); row.add(Document.COLUMN_FLAGS, flags); // Add a custom icon row.add(Document.COLUMN_ICON, R.drawable.ic_launcher); }