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