Search in sources :

Example 96 with ClipboardManager

use of android.content.ClipboardManager in project XobotOS by xamarin.

the class TextView method paste.

/**
     * Paste clipboard content between min and max positions.
     */
private void paste(int min, int max) {
    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++) {
            CharSequence paste = clip.getItemAt(i).coerceToText(getContext());
            if (paste != null) {
                if (!didFirst) {
                    long minMax = prepareSpacesAroundPaste(min, max, paste);
                    min = extractRangeStartFromLong(minMax);
                    max = extractRangeEndFromLong(minMax);
                    Selection.setSelection((Spannable) mText, max);
                    ((Editable) mText).replace(min, max, paste);
                    didFirst = true;
                } else {
                    ((Editable) mText).insert(getSelectionEnd(), "\n");
                    ((Editable) mText).insert(getSelectionEnd(), paste);
                }
            }
        }
        stopSelectionActionMode();
        sLastCutOrCopyTime = 0;
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) Editable(android.text.Editable) ClipData(android.content.ClipData) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 97 with ClipboardManager

use of android.content.ClipboardManager in project PhotoNoter by yydcdut.

the class WebViewActivity method copy2ClipBoard.

private void copy2ClipBoard(String string) {
    if (TextUtils.isEmpty(string)) {
        return;
    }
    ClipboardManager cbm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    ClipData.Item item = new ClipData.Item(string);
    ClipData clipData = cbm.getPrimaryClip();
    clipData.addItem(item);
    cbm.setPrimaryClip(clipData);
}
Also used : ClipboardManager(android.content.ClipboardManager) MenuItem(android.view.MenuItem) ClipData(android.content.ClipData)

Example 98 with ClipboardManager

use of android.content.ClipboardManager in project BarcodeEye by BarcodeEye.

the class ClipboardInterface method hasText.

public static boolean hasText(Context context) {
    ClipboardManager clipboard = getManager(context);
    ClipData clip = clipboard.getPrimaryClip();
    return clip != null && clip.getItemCount() > 0;
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Example 99 with ClipboardManager

use of android.content.ClipboardManager in project AndroidUtilCode by Blankj.

the class ClipboardUtils method copyText.

/**
     * 复制文本到剪贴板
     *
     * @param text 文本
     */
public static void copyText(CharSequence text) {
    ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newPlainText("text", text));
}
Also used : ClipboardManager(android.content.ClipboardManager)

Example 100 with ClipboardManager

use of android.content.ClipboardManager in project AndroidUtilCode by Blankj.

the class ClipboardUtils method getText.

/**
     * 获取剪贴板的文本
     *
     * @return 剪贴板的文本
     */
public static CharSequence getText() {
    ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        return clip.getItemAt(0).coerceToText(Utils.getContext());
    }
    return null;
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Aggregations

ClipboardManager (android.content.ClipboardManager)112 ClipData (android.content.ClipData)71 Intent (android.content.Intent)17 View (android.view.View)13 Context (android.content.Context)10 TextView (android.widget.TextView)10 Paint (android.graphics.Paint)9 DialogInterface (android.content.DialogInterface)7 Editable (android.text.Editable)7 TextPaint (android.text.TextPaint)7 TargetApi (android.annotation.TargetApi)5 Uri (android.net.Uri)5 AlertDialog (android.support.v7.app.AlertDialog)5 Spanned (android.text.Spanned)5 AlertDialog (android.app.AlertDialog)4 ImageView (android.widget.ImageView)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Drawable (android.graphics.drawable.Drawable)3 MenuItem (android.view.MenuItem)3 SharedPreferences (android.content.SharedPreferences)2