Search in sources :

Example 91 with ClipboardManager

use of android.content.ClipboardManager in project SeeWeather by xcc3641.

the class Util method copyToClipboard.

public static void copyToClipboard(String info, Context context) {
    ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText("msg", info);
    manager.setPrimaryClip(clipData);
    ToastUtil.showShort(String.format("[%s] 已经复制到剪切板啦( •̀ .̫ •́ )✧", info));
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Example 92 with ClipboardManager

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

the class TextView method setPrimaryClip.

private void setPrimaryClip(ClipData clip) {
    ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(clip);
    sLastCutOrCopyTime = SystemClock.uptimeMillis();
}
Also used : ClipboardManager(android.content.ClipboardManager)

Example 93 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 94 with ClipboardManager

use of android.content.ClipboardManager in project WordPress-Android by wordpress-mobile.

the class AppLogViewerActivity method copyAppLogToClipboard.

private void copyAppLogToClipboard() {
    try {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("AppLog", AppLog.toPlainText(this)));
        ToastUtils.showToast(this, R.string.logs_copied_to_clipboard);
    } catch (Exception e) {
        AppLog.e(T.UTILS, e);
        ToastUtils.showToast(this, R.string.error_copy_to_clipboard);
    }
}
Also used : ClipboardManager(android.content.ClipboardManager)

Example 95 with ClipboardManager

use of android.content.ClipboardManager in project WordPress-Android by wordpress-mobile.

the class UtilsTest method getClipboardUrlHelper.

private String getClipboardUrlHelper(int itemCount, String clipText) {
    ClipData.Item mockItem = mock(ClipData.Item.class);
    when(mockItem.getText()).thenReturn(clipText);
    ClipData mockPrimary = mock(ClipData.class);
    when(mockPrimary.getItemCount()).thenReturn(itemCount);
    when(mockPrimary.getItemAt(0)).thenReturn(mockItem);
    ClipboardManager mockManager = mock(ClipboardManager.class);
    when(mockManager.getPrimaryClip()).thenReturn(mockPrimary);
    Context mockContext = mock(Context.class);
    when(mockContext.getSystemService(Context.CLIPBOARD_SERVICE)).thenReturn(mockManager);
    return getUrlFromClipboard(mockContext);
}
Also used : ClipboardManager(android.content.ClipboardManager) Context(android.content.Context) ClipData(android.content.ClipData)

Aggregations

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