Search in sources :

Example 26 with ClipData

use of android.content.ClipData in project platform_frameworks_base by android.

the class TextView method paste.

/**
     * Paste clipboard content between min and max positions.
     */
private void paste(int min, int max, boolean withFormatting) {
    ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null) {
        boolean didFirst = false;
        for (int i = 0; i < clip.getItemCount(); i++) {
            final CharSequence paste;
            if (withFormatting) {
                paste = clip.getItemAt(i).coerceToStyledText(getContext());
            } else {
                // Get an item as text and remove all spans by toString().
                final CharSequence text = clip.getItemAt(i).coerceToText(getContext());
                paste = (text instanceof Spanned) ? text.toString() : text;
            }
            if (paste != null) {
                if (!didFirst) {
                    Selection.setSelection((Spannable) mText, max);
                    ((Editable) mText).replace(min, max, paste);
                    didFirst = true;
                } else {
                    ((Editable) mText).insert(getSelectionEnd(), "\n");
                    ((Editable) mText).insert(getSelectionEnd(), paste);
                }
            }
        }
        sLastCutCopyOrTextChangedTime = 0;
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) Editable(android.text.Editable) ClipData(android.content.ClipData) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 27 with ClipData

use of android.content.ClipData in project libgdx by libgdx.

the class AndroidClipboard method getContents.

@Override
public String getContents() {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        if (clipboard.getText() == null)
            return null;
        return clipboard.getText().toString();
    } else {
        ClipData clip = honeycombClipboard.getPrimaryClip();
        if (clip == null)
            return null;
        CharSequence text = clip.getItemAt(0).getText();
        if (text == null)
            return null;
        return text.toString();
    }
}
Also used : ClipData(android.content.ClipData)

Example 28 with ClipData

use of android.content.ClipData in project Talon-for-Twitter by klinker24.

the class TouchableSpan method copy.

private void copy() {
    ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Activity.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("link", full);
    clipboard.setPrimaryClip(clip);
    Toast.makeText(mContext, R.string.copied, Toast.LENGTH_SHORT).show();
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Example 29 with ClipData

use of android.content.ClipData in project android-common by litesuits.

the class ClipboardUtil method getItemCount.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static int getItemCount(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData data = clipboard.getPrimaryClip();
    return data.getItemCount();
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData) TargetApi(android.annotation.TargetApi)

Example 30 with ClipData

use of android.content.ClipData in project sharelock-android by auth0.

the class ComposeActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    final int entryCount = getSupportFragmentManager().getBackStackEntryCount();
    final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    if (entryCount == 0 && clipboardManager.hasPrimaryClip() && clipboardManager.getPrimaryClip().getItemCount() > 0) {
        final ClipData primaryClip = clipboardManager.getPrimaryClip();
        final ClipData.Item item = primaryClip.getItemAt(0);
        final String text = item.coerceToText(this).toString();
        if (text.trim().length() > 0) {
            final Snackbar snackbar = Snackbar.with(this).text(getString(R.string.paste_from_clipboard_prompt)).actionLabel(getString(R.string.paste_clipboard_action)).actionColorResource(R.color.sharelock_orange).actionListener(new ActionClickListener() {

                @Override
                public void onActionClicked(Snackbar snackbar) {
                    bus.postSticky(new ClipboardSecretEvent(text));
                    clipboardManager.setPrimaryClip(ClipData.newPlainText("", ""));
                }
            }).duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE);
            SnackbarManager.show(snackbar);
        }
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData) ActionClickListener(com.nispok.snackbar.listeners.ActionClickListener) Snackbar(com.nispok.snackbar.Snackbar) ClipboardSecretEvent(com.auth0.sharelock.event.ClipboardSecretEvent)

Aggregations

ClipData (android.content.ClipData)180 ClipboardManager (android.content.ClipboardManager)70 Intent (android.content.Intent)48 Uri (android.net.Uri)39 Paint (android.graphics.Paint)24 MenuItem (android.view.MenuItem)20 View (android.view.View)14 ArrayList (java.util.ArrayList)14 PendingIntent (android.app.PendingIntent)11 RemoteException (android.os.RemoteException)11 ContentResolver (android.content.ContentResolver)10 Nullable (android.support.annotation.Nullable)10 TextPaint (android.text.TextPaint)10 DocumentInfo (com.android.documentsui.model.DocumentInfo)10 Item (android.content.ClipData.Item)9 Editable (android.text.Editable)9 TextView (android.widget.TextView)9 DialogInterface (android.content.DialogInterface)8 ImageView (android.widget.ImageView)8 AlertDialog (android.app.AlertDialog)7