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));
}
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();
}
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;
}
}
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);
}
}
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);
}
Aggregations