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);
}
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();
}
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;
}
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;
}
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);
}
Aggregations