Search in sources :

Example 51 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.

the class AbstractJobTest method createJob.

final T createJob(List<Uri> srcs, Uri srcParent, Uri destination) throws Exception {
    DocumentStack stack = new DocumentStack();
    stack.push(DocumentInfo.fromUri(mResolver, destination));
    List<DocumentInfo> srcDocs = Lists.newArrayList();
    for (Uri src : srcs) {
        srcDocs.add(DocumentInfo.fromUri(mResolver, src));
    }
    return createJob(srcDocs, DocumentInfo.fromUri(mResolver, srcParent), stack);
}
Also used : DocumentStack(com.android.documentsui.model.DocumentStack) Uri(android.net.Uri) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 52 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.

the class FileOperationServiceTest method createDoc.

private static DocumentInfo createDoc(Uri destination) {
    DocumentInfo destDoc = new DocumentInfo();
    destDoc.derivedUri = destination;
    return destDoc;
}
Also used : DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 53 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.

the class DirectoryFragment method transferDocuments.

private void transferDocuments(final Selection selected, @OpType final int mode) {
    if (mode == FileOperationService.OPERATION_COPY) {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_COPY_TO);
    } else if (mode == FileOperationService.OPERATION_MOVE) {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_MOVE_TO);
    }
    // Pop up a dialog to pick a destination.  This is inadequate but works for now.
    // TODO: Implement a picker that is to spec.
    final Intent intent = new Intent(Shared.ACTION_PICK_COPY_DESTINATION, Uri.EMPTY, getActivity(), DocumentsActivity.class);
    // Relay any config overrides bits present in the original intent.
    Intent original = getActivity().getIntent();
    if (original != null && original.hasExtra(Shared.EXTRA_PRODUCTIVITY_MODE)) {
        intent.putExtra(Shared.EXTRA_PRODUCTIVITY_MODE, original.getBooleanExtra(Shared.EXTRA_PRODUCTIVITY_MODE, false));
    }
    // Set an appropriate title on the drawer when it is shown in the picker.
    // Coupled with the fact that we auto-open the drawer for copy/move operations
    // it should basically be the thing people see first.
    int drawerTitleId = mode == FileOperationService.OPERATION_MOVE ? R.string.menu_move : R.string.menu_copy;
    intent.putExtra(DocumentsContract.EXTRA_PROMPT, getResources().getString(drawerTitleId));
    // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
    List<DocumentInfo> docs = mModel.getDocuments(selected);
    // TODO: Can this move to Fragment bundle state?
    getDisplayState().selectedDocumentsForCopy = docs;
    // Determine if there is a directory in the set of documents
    // to be copied? Why? Directory creation isn't supported by some roots
    // (like Downloads). This informs DocumentsActivity (the "picker")
    // to restrict available roots to just those with support.
    intent.putExtra(Shared.EXTRA_DIRECTORY_COPY, hasDirectory(docs));
    intent.putExtra(FileOperationService.EXTRA_OPERATION, mode);
    // This just identifies the type of request...we'll check it
    // when we reveive a response.
    startActivityForResult(intent, REQUEST_COPY_DESTINATION);
}
Also used : Intent(android.content.Intent) Point(android.graphics.Point) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 54 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.

the class Model method getDocuments.

List<DocumentInfo> getDocuments(Selection items) {
    final int size = (items != null) ? items.size() : 0;
    final List<DocumentInfo> docs = new ArrayList<>(size);
    for (String modelId : items.getAll()) {
        final Cursor cursor = getItem(modelId);
        if (cursor == null) {
            Log.w(TAG, "Skipping document. Unabled to obtain cursor for modelId: " + modelId);
            continue;
        }
        docs.add(DocumentInfo.fromDirectoryCursor(cursor));
    }
    return docs;
}
Also used : ArrayList(java.util.ArrayList) DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString) MergeCursor(android.database.MergeCursor) Cursor(android.database.Cursor) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 55 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.

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)

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