Search in sources :

Example 66 with ClipData

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);
                    }
                }
            }
        }
    }
}
Also used : UserInfo(android.content.pm.UserInfo) RemoteException(android.os.RemoteException) ClipData(android.content.ClipData)

Example 67 with ClipData

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();
}
Also used : AlertDialog(android.app.AlertDialog) ActivityNotFoundException(android.content.ActivityNotFoundException) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) ClipData(android.content.ClipData)

Example 68 with ClipData

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;
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Example 69 with ClipData

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);
        }
    }
}
Also used : Item(android.content.ClipData.Item) MenuItem(android.view.MenuItem) SpannableStringBuilder(android.text.SpannableStringBuilder) DragAndDropPermissions(android.view.DragAndDropPermissions) ClipData(android.content.ClipData) Paint(android.graphics.Paint)

Example 70 with ClipData

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;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) ClipData(android.content.ClipData) Uri(android.net.Uri) ContentProviderClient(android.content.ContentProviderClient) DocumentInfo(com.android.documentsui.model.DocumentInfo) ContentResolver(android.content.ContentResolver)

Aggregations

ClipData (android.content.ClipData)343 ClipboardManager (android.content.ClipboardManager)190 Intent (android.content.Intent)83 Uri (android.net.Uri)65 View (android.view.View)38 MenuItem (android.view.MenuItem)34 TextView (android.widget.TextView)34 ArrayList (java.util.ArrayList)29 Paint (android.graphics.Paint)24 ImageView (android.widget.ImageView)20 Context (android.content.Context)19 DialogInterface (android.content.DialogInterface)19 PendingIntent (android.app.PendingIntent)16 Bundle (android.os.Bundle)16 RemoteException (android.os.RemoteException)14 SpannableStringBuilder (android.text.SpannableStringBuilder)14 SuppressLint (android.annotation.SuppressLint)12 TargetApi (android.annotation.TargetApi)12 Drawable (android.graphics.drawable.Drawable)11 RecyclerView (android.support.v7.widget.RecyclerView)11