本文整理汇总了Java中android.content.ClipboardManager.getPrimaryClip方法的典型用法代码示例。如果您正苦于以下问题:Java ClipboardManager.getPrimaryClip方法的具体用法?Java ClipboardManager.getPrimaryClip怎么用?Java ClipboardManager.getPrimaryClip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ClipboardManager
的用法示例。
在下文中一共展示了ClipboardManager.getPrimaryClip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIntent
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* 获取剪贴板的意图
*
* @return 剪贴板的意图
*/
public static Intent getIntent() {
ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null && clip.getItemCount() > 0) {
return clip.getItemAt(0).getIntent();
}
return null;
}
示例2: getString
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
@JSMethod
public void getString(@Nullable JSCallback callback) {
Context context = mWXSDKInstance.getContext();
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
Map<String, Object> map = new HashMap<>(2);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null && clip.getItemCount() > 0) {
ClipData.Item item = clip.getItemAt(0);
CharSequence text = coerceToText(context, item);
map.put(RESULT, text != null ? RESULT_OK : RESULT_FAILED);
map.put(DATA, text != null ? text : "");
} else {
map.put(RESULT, RESULT_FAILED);
map.put(DATA, "");
}
if (null != callback) {
callback.invoke(map);
}
}
示例3: decodeFromClipboard
import android.content.ClipboardManager; //导入方法依赖的package包/类
public double decodeFromClipboard() {
double donate2 = 0d;
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null && clip.getItemCount() > 0) {
CharSequence text = clip.getItemAt(0).getText();
if (text != null && text.toString().startsWith("br")) {
String alipay2 = text.subSequence(2, text.length()).toString().trim();
donate2 = decode(this, alipay2, false);
if (DecimalUtils.isPositive(donate2)) {
PreferencesUtils.getPreferences(this)
.edit().putString("alipay2", alipay2).apply();
String format = DecimalUtils.format(donate2);
String message = getString(R.string.toast_donate, format);
clipboard.setText(message);
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
}
return donate2;
}
示例4: getText
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* 获取剪贴板的文本
*
* @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;
}
示例5: getText
import android.content.ClipboardManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static String getText(Context context, int index) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null && clip.getItemCount() > index) {
return String.valueOf(clip.getItemAt(0).coerceToText(context));
}
return null;
}
示例6: getUri
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* 获取剪贴板的uri
*
* @return 剪贴板的uri
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static Uri getUri()
{
ClipboardManager clipboardManager = Managers.getClipboardManager();
ClipData clipData = clipboardManager.getPrimaryClip();
if(clipData != null && clipData.getItemCount() > 0)
{
return clipData.getItemAt(0).getUri();
}
return null;
}
示例7: getIntent
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* 获取剪贴板的意图
*
* @return 剪贴板的意图
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static Intent getIntent()
{
ClipboardManager clipboardManager = Managers.getClipboardManager();
ClipData clipData = clipboardManager.getPrimaryClip();
if(clipData != null && clipData.getItemCount() > 0)
{
return clipData.getItemAt(0).getIntent();
}
return null;
}
示例8: getLatestText
import android.content.ClipboardManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static String getLatestText(Context context) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null && clip.getItemCount() > 0) {
return String.valueOf(clip.getItemAt(0).coerceToText(context));
}
return null;
}
示例9: getUri
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* 获取剪贴板的uri
*
* @return 剪贴板的uri
*/
public static Uri getUri() {
ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
if (clip != null && clip.getItemCount() > 0) {
return clip.getItemAt(0).getUri();
}
return null;
}
示例10: onTextContextMenuItem
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public boolean onTextContextMenuItem(int id) {
if (id == android.R.id.paste) {
ClipboardManager clipboard = (ClipboardManager) getContext()
.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = clipboard.getPrimaryClip();
if (clipData != null) {
// Convert the clip data to a simple string
StringBuilder builder = new StringBuilder();
for (int i = 0; i < clipData.getItemCount(); i++) {
builder.append(clipData.getItemAt(i).coerceToText(getContext()));
}
// Identify how much of the original text should be replaced
int min = 0;
int max = getText().length();
if (isFocused()) {
final int selStart = getSelectionStart();
final int selEnd = getSelectionEnd();
min = Math.max(0, Math.min(selStart, selEnd));
max = Math.max(0, Math.max(selStart, selEnd));
}
Selection.setSelection(getText(), max);
getText().replace(min, max, builder.toString());
return true;
}
}
return super.onTextContextMenuItem(id);
}
示例11: getText
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* 获取剪贴板文本,当获取到是空时,返回默认字符串
*
* @param textIfNull 剪贴板文本如果为空,返回这个字符串
* @return 剪贴板文本
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static String getText(String textIfNull)
{
ClipboardManager clipboardManager = getClipboardManager();
ClipData clipData = clipboardManager.getPrimaryClip();
if(clipData != null && clipData.getItemCount() > 0)
{
return clipData.getItemAt(0).coerceToText(Easy.getContext()).toString();
}
return textIfNull;
}
示例12: getItemCount
import android.content.ClipboardManager; //导入方法依赖的package包/类
@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();
}
示例13: hasText
import android.content.ClipboardManager; //导入方法依赖的package包/类
public static boolean hasText(Context context) {
ClipboardManager clipboard = getManager(context);
ClipData clip = clipboard.getPrimaryClip();
return clip != null && clip.getItemCount() > 0;
}
示例14: hasText
import android.content.ClipboardManager; //导入方法依赖的package包/类
public static boolean hasText(Context context) {
ClipboardManager clipboard = getManager(context);
ClipData clip = clipboard.getPrimaryClip();
return clip != null && clip.getItemCount() > 0;
}
示例15: performPaste
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* A helper method that replaces the note's data with the contents of the clipboard.
*/
private final void performPaste() {
// Gets a handle to the Clipboard Manager
ClipboardManager clipboard = (ClipboardManager)
getSystemService(Context.CLIPBOARD_SERVICE);
// Gets a content resolver instance
ContentResolver cr = getContentResolver();
// Gets the clipboard data from the clipboard
ClipData clip = clipboard.getPrimaryClip();
if (clip != null) {
String text=null;
String title=null;
// Gets the first item from the clipboard data
ClipData.Item item = clip.getItemAt(0);
// Tries to get the item's contents as a URI pointing to a note
Uri uri = item.getUri();
// Tests to see that the item actually is an URI, and that the URI
// is a content URI pointing to a provider whose MIME type is the same
// as the MIME type supported by the Note pad provider.
if (uri != null && NotePad.Notes.CONTENT_ITEM_TYPE.equals(cr.getType(uri))) {
// The clipboard holds a reference to data with a note MIME type. This copies it.
Cursor orig = cr.query(
uri, // URI for the content provider
PROJECTION, // Get the columns referred to in the projection
null, // No selection variables
null, // No selection variables, so no criteria are needed
null // Use the default sort order
);
// If the Cursor is not null, and it contains at least one record
// (moveToFirst() returns true), then this gets the note data from it.
if (orig != null) {
if (orig.moveToFirst()) {
int colNoteIndex = orig.getColumnIndex(NotePad.Notes.COLUMN_NAME_NOTE);
int colTitleIndex = orig.getColumnIndex(NotePad.Notes.COLUMN_NAME_TITLE);
text = orig.getString(colNoteIndex);
title = orig.getString(colTitleIndex);
}
// Closes the cursor.
orig.close();
}
}
// If the contents of the clipboard wasn't a reference to a note, then
// this converts whatever it is to text.
if (text == null) {
text = item.coerceToText(this).toString();
}
// Updates the current note with the retrieved title and text.
updateNote(text, title);
}
}