use of android.content.ClipData in project android_frameworks_base by crdroidandroid.
the class FilesActivity method onTaskFinished.
@Override
void onTaskFinished(Uri... uris) {
if (DEBUG)
Log.d(TAG, "onFinished() " + Arrays.toString(uris));
final Intent intent = new Intent();
if (uris.length == 1) {
intent.setData(uris[0]);
} else if (uris.length > 1) {
final ClipData clipData = new ClipData(null, mState.acceptMimes, new ClipData.Item(uris[0]));
for (int i = 1; i < uris.length; i++) {
clipData.addItem(new ClipData.Item(uris[i]));
}
intent.setClipData(clipData);
}
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
setResult(Activity.RESULT_OK, intent);
finish();
}
use of android.content.ClipData in project android_frameworks_base by crdroidandroid.
the class DocumentClipper method getClipDataForDocuments.
/**
* Returns ClipData representing the list of docs, or null if docs is empty,
* or docs cannot be converted.
*/
@Nullable
public ClipData getClipDataForDocuments(List<DocumentInfo> docs) {
final ContentResolver resolver = mContext.getContentResolver();
final String[] mimeTypes = getMimeTypes(resolver, docs);
ClipData clipData = null;
for (DocumentInfo doc : docs) {
if (clipData == null) {
// TODO: figure out what this string should be.
// Currently it is not displayed anywhere in the UI, but this might change.
final String label = "";
clipData = new ClipData(label, mimeTypes, new ClipData.Item(doc.derivedUri));
} else {
// TODO: update list of mime types in ClipData.
clipData.addItem(new ClipData.Item(doc.derivedUri));
}
}
return clipData;
}
use of android.content.ClipData in project android_frameworks_base by crdroidandroid.
the class Editor method onDrop.
void onDrop(DragEvent event) {
StringBuilder content = new StringBuilder("");
final DragAndDropPermissions permissions = DragAndDropPermissions.obtain(event);
if (permissions != null) {
permissions.takeTransient();
}
try {
ClipData clipData = event.getClipData();
final int itemCount = clipData.getItemCount();
for (int i = 0; i < itemCount; i++) {
Item item = clipData.getItemAt(i);
content.append(item.coerceToStyledText(mTextView.getContext()));
}
} finally {
if (permissions != null) {
permissions.release();
}
}
final int offset = mTextView.getOffsetForPosition(event.getX(), event.getY());
Object localState = event.getLocalState();
DragLocalState dragLocalState = null;
if (localState instanceof DragLocalState) {
dragLocalState = (DragLocalState) localState;
}
boolean dragDropIntoItself = dragLocalState != null && dragLocalState.sourceTextView == mTextView;
if (dragDropIntoItself) {
if (offset >= dragLocalState.start && offset < dragLocalState.end) {
// A drop inside the original selection discards the drop.
return;
}
}
final int originalLength = mTextView.getText().length();
int min = offset;
int max = offset;
Selection.setSelection((Spannable) mTextView.getText(), max);
mTextView.replaceText_internal(min, max, content);
if (dragDropIntoItself) {
int dragSourceStart = dragLocalState.start;
int dragSourceEnd = dragLocalState.end;
if (max <= dragSourceStart) {
// Inserting text before selection has shifted positions
final int shift = mTextView.getText().length() - originalLength;
dragSourceStart += shift;
dragSourceEnd += shift;
}
mUndoInputFilter.setForceMerge(true);
try {
// Delete original selection
mTextView.deleteText_internal(dragSourceStart, dragSourceEnd);
// Make sure we do not leave two adjacent spaces.
final int prevCharIdx = Math.max(0, dragSourceStart - 1);
final int nextCharIdx = Math.min(mTextView.getText().length(), dragSourceStart + 1);
if (nextCharIdx > prevCharIdx + 1) {
CharSequence t = mTextView.getTransformedText(prevCharIdx, nextCharIdx);
if (Character.isSpaceChar(t.charAt(0)) && Character.isSpaceChar(t.charAt(1))) {
mTextView.deleteText_internal(prevCharIdx, prevCharIdx + 1);
}
}
} finally {
mUndoInputFilter.setForceMerge(false);
}
}
}
use of android.content.ClipData in project android_frameworks_base by crdroidandroid.
the class Editor method startDragAndDrop.
private void startDragAndDrop() {
// TODO: Fix drag and drop in full screen extracted mode.
if (mTextView.isInExtractedMode()) {
return;
}
final int start = mTextView.getSelectionStart();
final int end = mTextView.getSelectionEnd();
CharSequence selectedText = mTextView.getTransformedText(start, end);
ClipData data = ClipData.newPlainText(null, selectedText);
DragLocalState localState = new DragLocalState(mTextView, start, end);
mTextView.startDragAndDrop(data, getTextThumbnailBuilder(start, end), localState, View.DRAG_FLAG_GLOBAL);
stopTextActionMode();
if (hasSelectionController()) {
getSelectionController().resetTouchOffsets();
}
}
use of android.content.ClipData in project android_frameworks_base by crdroidandroid.
the class BugreportProgressService method buildSendIntent.
/**
* Build {@link Intent} that can be used to share the given bugreport.
*/
private static Intent buildSendIntent(Context context, BugreportInfo info) {
// Files are kept on private storage, so turn into Uris that we can
// grant temporary permissions for.
final Uri bugreportUri;
try {
bugreportUri = getUri(context, info.bugreportFile);
} catch (IllegalArgumentException e) {
// Should not happen on production, but happens when a Shell is sideloaded and
// FileProvider cannot find a configured root for it.
Log.wtf(TAG, "Could not get URI for " + info.bugreportFile, e);
return null;
}
final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
final String mimeType = "application/vnd.android.bugreport";
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType(mimeType);
final String subject = !TextUtils.isEmpty(info.title) ? info.title : bugreportUri.getLastPathSegment();
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
// EXTRA_TEXT should be an ArrayList, but some clients are expecting a single String.
// So, to avoid an exception on Intent.migrateExtraStreamToClipData(), we need to manually
// create the ClipData object with the attachments URIs.
final StringBuilder messageBody = new StringBuilder("Build info: ").append(SystemProperties.get("ro.build.description")).append("\nSerial number: ").append(SystemProperties.get("ro.serialno"));
if (!TextUtils.isEmpty(info.description)) {
messageBody.append("\nDescription: ").append(info.description);
}
intent.putExtra(Intent.EXTRA_TEXT, messageBody.toString());
final ClipData clipData = new ClipData(null, new String[] { mimeType }, new ClipData.Item(null, null, null, bugreportUri));
final ArrayList<Uri> attachments = Lists.newArrayList(bugreportUri);
for (File screenshot : info.screenshotFiles) {
final Uri screenshotUri = getUri(context, screenshot);
clipData.addItem(new ClipData.Item(null, null, null, screenshotUri));
attachments.add(screenshotUri);
}
intent.setClipData(clipData);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
final Account sendToAccount = findSendToAccount(context);
if (sendToAccount != null) {
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { sendToAccount.name });
}
return intent;
}
Aggregations