android.provider.DocumentsContract.Document#FLAG_DIR_SUPPORTS_CREATE源码实例Demo

下面列出了android.provider.DocumentsContract.Document#FLAG_DIR_SUPPORTS_CREATE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: JPPF   文件: AppStorageProvider.java
/**
 * 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);
}
 
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;
}
 
源代码3 项目: storage-samples   文件: MyCloudProvider.java
/**
 * 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);
}
 
源代码4 项目: android-StorageProvider   文件: MyCloudProvider.java
/**
 * 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);
}