Search in sources :

Example 6 with DocumentInfo

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

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 7 with DocumentInfo

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

the class DirectoryFragment method copySelectionToClipboard.

void copySelectionToClipboard(Selection selected) {
    assert (!selected.isEmpty());
    // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
    List<DocumentInfo> docs = mModel.getDocuments(selected);
    mClipper.clipDocuments(docs);
    Activity activity = getActivity();
    Snackbars.makeSnackbar(activity, activity.getResources().getQuantityString(R.plurals.clipboard_files_clipped, docs.size(), docs.size()), Snackbar.LENGTH_SHORT).show();
}
Also used : BaseActivity(com.android.documentsui.BaseActivity) DocumentsActivity(com.android.documentsui.DocumentsActivity) Activity(android.app.Activity) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 8 with DocumentInfo

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

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 9 with DocumentInfo

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

the class DocumentsProviderHelper method listChildren.

public List<DocumentInfo> listChildren(String documentId) throws Exception {
    Uri uri = buildChildDocumentsUri(mAuthority, documentId);
    List<DocumentInfo> children = new ArrayList<>();
    try (Cursor cursor = mClient.query(uri, null, null, null, null, null)) {
        Cursor wrapper = new RootCursorWrapper(mAuthority, "totally-fake", cursor, 100);
        while (wrapper.moveToNext()) {
            children.add(DocumentInfo.fromDirectoryCursor(wrapper));
        }
    }
    return children;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) DocumentsContract.buildDocumentUri(android.provider.DocumentsContract.buildDocumentUri) DocumentsContract.buildChildDocumentsUri(android.provider.DocumentsContract.buildChildDocumentsUri) DocumentsContract.buildRootsUri(android.provider.DocumentsContract.buildRootsUri) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 10 with DocumentInfo

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

the class DocumentsProviderHelper method assertHasDirectory.

public void assertHasDirectory(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 name=" + name + " in children " + children);
}
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