Search in sources :

Example 86 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.

the class DirectoryFragment method getDraggableDocuments.

private List<DocumentInfo> getDraggableDocuments(View currentItemView) {
    String modelId = getModelId(currentItemView);
    if (modelId == null) {
        return Collections.EMPTY_LIST;
    }
    final List<DocumentInfo> selectedDocs = mModel.getDocuments(mSelectionManager.getSelection());
    if (!selectedDocs.isEmpty()) {
        if (!isSelected(modelId)) {
            // There is a selection that does not include the current item, drag nothing.
            return Collections.EMPTY_LIST;
        }
        return selectedDocs;
    }
    final Cursor cursor = mModel.getItem(modelId);
    if (cursor == null) {
        Log.w(TAG, "Undraggable document. Can't obtain cursor for modelId " + modelId);
        return Collections.EMPTY_LIST;
    }
    return Lists.newArrayList(DocumentInfo.fromDirectoryCursor(cursor));
}
Also used : DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString) Cursor(android.database.Cursor) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 87 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.

the class DirectoryFragment method shareDocuments.

private void shareDocuments(final Selection selected) {
    Metrics.logUserAction(getContext(), Metrics.USER_ACTION_SHARE);
    // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
    List<DocumentInfo> docs = mModel.getDocuments(selected);
    Intent intent;
    // Filter out directories and virtual files - those can't be shared.
    List<DocumentInfo> docsForSend = new ArrayList<>();
    for (DocumentInfo doc : docs) {
        if (!doc.isDirectory() && !doc.isVirtualDocument()) {
            docsForSend.add(doc);
        }
    }
    if (docsForSend.size() == 1) {
        final DocumentInfo doc = docsForSend.get(0);
        intent = new Intent(Intent.ACTION_SEND);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setType(doc.mimeType);
        intent.putExtra(Intent.EXTRA_STREAM, doc.derivedUri);
    } else if (docsForSend.size() > 1) {
        intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        final ArrayList<String> mimeTypes = new ArrayList<>();
        final ArrayList<Uri> uris = new ArrayList<>();
        for (DocumentInfo doc : docsForSend) {
            mimeTypes.add(doc.mimeType);
            uris.add(doc.derivedUri);
        }
        intent.setType(findCommonMimeType(mimeTypes));
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    } else {
        return;
    }
    intent = Intent.createChooser(intent, getActivity().getText(R.string.share_via));
    startActivity(intent);
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 88 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.

the class DocumentsProviderHelper method assertHasFile.

public void assertHasFile(Uri parentUri, String name) throws Exception {
    List<DocumentInfo> children = listChildren(parentUri);
    for (DocumentInfo child : children) {
        if (name.equals(child.displayName) && !child.isDirectory()) {
            return;
        }
    }
    fail("Could not find file named=" + name + " in children " + children);
}
Also used : DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 89 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.

the class DocumentsProviderHelper method assertFileContents.

public void assertFileContents(String parentId, String fileName, byte[] expected) throws Exception {
    DocumentInfo file = findFile(parentId, fileName);
    assertNotNull(file);
    assertFileContents(file.derivedUri, expected);
}
Also used : DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 90 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.

the class CopyJob method start.

@Override
void start() {
    mStartTime = elapsedRealtime();
    try {
        mBatchSize = calculateSize(mSrcs);
    } catch (ResourceException e) {
        Log.w(TAG, "Failed to calculate total size. Copying without progress.", e);
        mBatchSize = -1;
    }
    DocumentInfo srcInfo;
    DocumentInfo dstInfo = stack.peek();
    for (int i = 0; i < mSrcs.size() && !isCanceled(); ++i) {
        srcInfo = mSrcs.get(i);
        if (DEBUG)
            Log.d(TAG, "Copying " + srcInfo.displayName + " (" + srcInfo.derivedUri + ")" + " to " + dstInfo.displayName + " (" + dstInfo.derivedUri + ")");
        try {
            if (dstInfo.equals(srcInfo) || isDescendentOf(srcInfo, dstInfo)) {
                Log.e(TAG, "Skipping recursive copy of " + srcInfo.derivedUri);
                onFileFailed(srcInfo);
            } else {
                processDocument(srcInfo, null, dstInfo);
            }
        } catch (ResourceException e) {
            Log.e(TAG, "Failed to copy " + srcInfo.derivedUri, e);
            onFileFailed(srcInfo);
        }
    }
    Metrics.logFileOperation(service, operationType, mSrcs, dstInfo);
}
Also used : DocumentInfo(com.android.documentsui.model.DocumentInfo)

Aggregations

DocumentInfo (com.android.documentsui.model.DocumentInfo)150 Uri (android.net.Uri)40 Cursor (android.database.Cursor)30 DocumentInfo.getCursorString (com.android.documentsui.model.DocumentInfo.getCursorString)30 FragmentManager (android.app.FragmentManager)20 Point (android.graphics.Point)20 RootInfo (com.android.documentsui.model.RootInfo)20 ArrayList (java.util.ArrayList)20 Intent (android.content.Intent)15 DocumentsContract.buildChildDocumentsUri (android.provider.DocumentsContract.buildChildDocumentsUri)15 DocumentsContract.buildDocumentUri (android.provider.DocumentsContract.buildDocumentUri)15 ClipData (android.content.ClipData)10 ContentResolver (android.content.ContentResolver)10 DialogInterface (android.content.DialogInterface)10 RemoteException (android.os.RemoteException)10 BaseActivity (com.android.documentsui.BaseActivity)10 DocumentStack (com.android.documentsui.model.DocumentStack)10 Activity (android.app.Activity)5 AlertDialog (android.app.AlertDialog)5 ContentProviderClient (android.content.ContentProviderClient)5