Merge "Collect mime type data correctly for all URIs added to ClipData" into nyc-dev am: e06ef946f4

am: 36ad144f6d

* commit '36ad144f6d28034edc1dd7e7f387c3ab432ce475':
  Collect mime type data correctly for all URIs added to ClipData

Change-Id: I2ce8d4850d83f6bfb43862ad0638035cbe252f6c
This commit is contained in:
Vladislav Kaznacheev
2016-05-04 17:17:21 +00:00
committed by android-build-merger

View File

@@ -32,7 +32,9 @@ import com.android.documentsui.model.DocumentInfo;
import libcore.io.IoUtils; import libcore.io.IoUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
/** /**
@@ -125,22 +127,39 @@ public final class DocumentClipper {
*/ */
public @Nullable ClipData getClipDataForDocuments(List<DocumentInfo> docs) { public @Nullable ClipData getClipDataForDocuments(List<DocumentInfo> docs) {
final ContentResolver resolver = mContext.getContentResolver(); final ContentResolver resolver = mContext.getContentResolver();
final String[] mimeTypes = getMimeTypes(resolver, docs);
ClipData clipData = null; ClipData clipData = null;
for (DocumentInfo doc : docs) { for (DocumentInfo doc : docs) {
final Uri uri = DocumentsContract.buildDocumentUri(doc.authority, doc.documentId);
if (clipData == null) { if (clipData == null) {
// TODO: figure out what this string should be. // TODO: figure out what this string should be.
// Currently it is not displayed anywhere in the UI, but this might change. // Currently it is not displayed anywhere in the UI, but this might change.
final String label = ""; final String label = "";
clipData = ClipData.newUri(resolver, label, uri); clipData = new ClipData(label, mimeTypes, new ClipData.Item(doc.derivedUri));
} else { } else {
// TODO: update list of mime types in ClipData. // TODO: update list of mime types in ClipData.
clipData.addItem(new ClipData.Item(uri)); clipData.addItem(new ClipData.Item(doc.derivedUri));
} }
} }
return clipData; return clipData;
} }
private static String[] getMimeTypes(ContentResolver resolver, List<DocumentInfo> docs) {
final HashSet<String> mimeTypes = new HashSet<>();
for (DocumentInfo doc : docs) {
assert(doc != null);
assert(doc.derivedUri != null);
final Uri uri = doc.derivedUri;
if ("content".equals(uri.getScheme())) {
mimeTypes.add(resolver.getType(uri));
final String[] streamTypes = resolver.getStreamTypes(uri, "*/*");
if (streamTypes != null) {
mimeTypes.addAll(Arrays.asList(streamTypes));
}
}
}
return mimeTypes.toArray(new String[0]);
}
public void clipDocuments(List<DocumentInfo> docs) { public void clipDocuments(List<DocumentInfo> docs) {
ClipData data = getClipDataForDocuments(docs); ClipData data = getClipDataForDocuments(docs);
mClipboard.setPrimaryClip(data); mClipboard.setPrimaryClip(data);