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