use of android.content.ClipData in project android_frameworks_base by crdroidandroid.
the class ClipboardService method setPrimaryClip.
public void setPrimaryClip(ClipData clip, String callingPackage) {
synchronized (this) {
if (clip != null && clip.getItemCount() <= 0) {
throw new IllegalArgumentException("No items");
}
final int callingUid = Binder.getCallingUid();
if (mAppOps.noteOp(AppOpsManager.OP_WRITE_CLIPBOARD, callingUid, callingPackage) != AppOpsManager.MODE_ALLOWED) {
return;
}
checkDataOwnerLocked(clip, callingUid);
final int userId = UserHandle.getUserId(callingUid);
PerUserClipboard clipboard = getClipboard(userId);
revokeUris(clipboard);
setPrimaryClipInternal(clipboard, clip);
List<UserInfo> related = getRelatedProfiles(userId);
if (related != null) {
int size = related.size();
if (size > 1) {
// Related profiles list include the current profile.
boolean canCopy = false;
try {
canCopy = !mUm.getUserRestrictions(userId).getBoolean(UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE);
} catch (RemoteException e) {
Slog.e(TAG, "Remote Exception calling UserManager: " + e);
}
// primary clip in related users to prevent pasting stale content.
if (!canCopy) {
clip = null;
} else {
// We want to fix the uris of the related user's clip without changing the
// uris of the current user's clip.
// So, copy the ClipData, and then copy all the items, so that nothing
// is shared in memmory.
clip = new ClipData(clip);
for (int i = clip.getItemCount() - 1; i >= 0; i--) {
clip.setItemAt(i, new ClipData.Item(clip.getItemAt(i)));
}
clip.fixUrisLight(userId);
}
for (int i = 0; i < size; i++) {
int id = related.get(i).id;
if (id != userId) {
setPrimaryClipInternal(getClipboard(id), clip);
}
}
}
}
}
}
use of android.content.ClipData in project android_frameworks_base by AOSPA.
the class DumpHeapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mProcess = getIntent().getStringExtra(KEY_PROCESS);
mSize = getIntent().getLongExtra(KEY_SIZE, 0);
String directLaunch = getIntent().getStringExtra(KEY_DIRECT_LAUNCH);
if (directLaunch != null) {
Intent intent = new Intent(ActivityManager.ACTION_REPORT_HEAP_LIMIT);
intent.setPackage(directLaunch);
ClipData clip = ClipData.newUri(getContentResolver(), "Heap Dump", JAVA_URI);
intent.setClipData(clip);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType(clip.getDescription().getMimeType(0));
intent.putExtra(Intent.EXTRA_STREAM, JAVA_URI);
try {
startActivity(intent);
scheduleDelete();
mHandled = true;
finish();
return;
} catch (ActivityNotFoundException e) {
Slog.i("DumpHeapActivity", "Unable to direct launch to " + directLaunch + ": " + e.getMessage());
}
}
AlertDialog.Builder b = new AlertDialog.Builder(this, android.R.style.Theme_Material_Light_Dialog_Alert);
b.setTitle(com.android.internal.R.string.dump_heap_title);
b.setMessage(getString(com.android.internal.R.string.dump_heap_text, mProcess, DebugUtils.sizeValueToString(mSize, null)));
b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mHandled = true;
sendBroadcast(new Intent(ACTION_DELETE_DUMPHEAP));
finish();
}
});
b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mHandled = true;
scheduleDelete();
Intent intent = new Intent(Intent.ACTION_SEND);
ClipData clip = ClipData.newUri(getContentResolver(), "Heap Dump", JAVA_URI);
intent.setClipData(clip);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType(clip.getDescription().getMimeType(0));
intent.putExtra(Intent.EXTRA_STREAM, JAVA_URI);
startActivity(Intent.createChooser(intent, getText(com.android.internal.R.string.dump_heap_title)));
finish();
}
});
mDialog = b.show();
}
use of android.content.ClipData in project weex-example by KalicyZhou.
the class ClipboardInterface method getText.
public static CharSequence getText(Context context) {
ClipboardManager clipboard = getManager(context);
ClipData clip = clipboard.getPrimaryClip();
return hasText(context) ? clip.getItemAt(0).coerceToText(context) : null;
}
use of android.content.ClipData in project android_frameworks_base by AOSPA.
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 AOSPA.
the class DocumentClipper method getDocumentsFromClipData.
/**
* Returns a list of Documents as decoded in clipData.
* This should be run from inside an AsyncTask.
*/
public List<DocumentInfo> getDocumentsFromClipData(ClipData clipData) {
assert (clipData != null);
final List<DocumentInfo> srcDocs = new ArrayList<>();
int count = clipData.getItemCount();
if (count == 0) {
return srcDocs;
}
ContentResolver resolver = mContext.getContentResolver();
for (int i = 0; i < count; ++i) {
ClipData.Item item = clipData.getItemAt(i);
Uri itemUri = item.getUri();
if (itemUri != null && DocumentsContract.isDocumentUri(mContext, itemUri)) {
ContentProviderClient client = null;
Cursor cursor = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, itemUri.getAuthority());
cursor = client.query(itemUri, null, null, null, null);
cursor.moveToPosition(0);
srcDocs.add(DocumentInfo.fromCursor(cursor, itemUri.getAuthority()));
} catch (Exception e) {
Log.e(TAG, e.getMessage());
} finally {
IoUtils.closeQuietly(cursor);
ContentProviderClient.releaseQuietly(client);
}
}
}
return srcDocs;
}
Aggregations