本文整理汇总了Java中android.content.ClipboardManager.setPrimaryClip方法的典型用法代码示例。如果您正苦于以下问题:Java ClipboardManager.setPrimaryClip方法的具体用法?Java ClipboardManager.setPrimaryClip怎么用?Java ClipboardManager.setPrimaryClip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ClipboardManager
的用法示例。
在下文中一共展示了ClipboardManager.setPrimaryClip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyText
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void copyText() {
if (checkNull()) {
view.showCopyTextError();
return;
}
ClipboardManager manager = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
ClipData clipData = null;
switch (type) {
case TYPE_ZHIHU:
clipData = ClipData.newPlainText("text", Html.fromHtml(title + "\n" + zhihuDailyStory.getBody()).toString());
break;
case TYPE_GUOKR:
clipData = ClipData.newPlainText("text", Html.fromHtml(guokrStory).toString());
break;
case TYPE_DOUBAN:
clipData = ClipData.newPlainText("text", Html.fromHtml(title + "\n" + doubanMomentStory.getContent()).toString());
}
manager.setPrimaryClip(clipData);
view.showTextCopied();
}
示例2: copyStationToClipboard
import android.content.ClipboardManager; //导入方法依赖的package包/类
private void copyStationToClipboard() {
if (mStreamUri != null && mStationName != null) {
// create clip
String clipboardText;
ClipData clip;
if (mStationMetadata != null) {
clipboardText = mStationName + " - " + mStationMetadata + " (" + mStreamUri + ")";
} else {
clipboardText = mStationName + " (" + mStreamUri + ")";
}
clip = ClipData.newPlainText("simple text", clipboardText);
// copy clip to clipboard
ClipboardManager cm = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clip);
// notify user
Toast.makeText(mActivity, mActivity.getString(R.string.toastmessage_station_copied), Toast.LENGTH_SHORT).show();
}
}
示例3: inputText2
import android.content.ClipboardManager; //导入方法依赖的package包/类
public static boolean inputText2(Context context, AccessibilityService service, AccessibilityNodeInfo nodeInfo,
final String hello) {
//找到当前获取焦点的view
// AccessibilityNodeInfo target = nodeInfo.findFocus(AccessibilityNodeInfo.FOCUS_INPUT);
AccessUtil.findNodeInfosByName(nodeInfo, "android.widget.EditText");
AccessibilityNodeInfo target = editText;
if (target == null) {
L.d("inputHello: null");
return false;
} else {
L.d("inputHello: not null " + target.getText());
}
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("message", hello);
clipboard.setPrimaryClip(clip);
L.d("设置粘贴板");
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
// target.performAction(AccessibilityNodeInfo.ACTION_PASTE);
// }
target.performAction(AccessibilityNodeInfo.ACTION_FOCUS);
L.d("获取焦点");
target.performAction(AccessibilityNodeInfo.ACTION_PASTE);
L.d("粘贴内容");
return true;
}
示例4: onCopyClick
import android.content.ClipboardManager; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
public void onCopyClick() {
try {
ClipboardManager manager = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
logger.d("menu#onCopyClick content:%s", mMsgInfo.getContent());
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
ClipData data = ClipData.newPlainText("data", mMsgInfo.getContent());
manager.setPrimaryClip(data);
} else {
manager.setText(mMsgInfo.getContent());
}
} catch (Exception e) {
logger.e(e.getMessage());
}
}
示例5: copyTextToClipboard
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void copyTextToClipboard(String text) {
ClipboardManager manager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText(getString(R.string.post_text), text);
manager.setPrimaryClip(clipData);
Toast.makeText(getActivity(), R.string.copied_text, Toast.LENGTH_SHORT).show();
}
示例6: copy
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* Save {@code content} into device clipboard with {@code label}
*/
public static boolean copy(@NonNull final Context context,
@NonNull final String label,
@NonNull final String content) {
if (TextUtils.isEmpty(label) || TextUtils.isEmpty(content)) {
return false;
}
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(ClipData.newPlainText(label, content));
return true;
}
示例7: onClick
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
public void onClick(View view) {
String color = (String) view.getTag();
if (color != null) {
ClipboardManager clipboard = (ClipboardManager) view.getContext()
.getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", color);
clipboard.setPrimaryClip(clip);
Toast.makeText(view.getContext(),
R.string.copied_to_clipboard,
Toast.LENGTH_SHORT).show();
}
}
示例8: fireCopyClick
import android.content.ClipboardManager; //导入方法依赖的package包/类
public void fireCopyClick() {
ClipboardManager clipboard = (ClipboardManager) getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("response", fullResponseBody);
clipboard.setPrimaryClip(clip);
safeShowToast(getView(), R.string.copied_to_clipboard, false);
}
示例9: showHint
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* Show a toast message with the hex color code below the view.
*/
public void showHint() {
// final int[] screenPos = new int[2];
// final Rect displayFrame = new Rect();
// getLocationOnScreen(screenPos);
// getWindowVisibleDisplayFrame(displayFrame);
// final Context context = getContext();
// final int width = getWidth();
// final int height = getHeight();
// final int midy = screenPos[1] + height / 2;
// int referenceX = screenPos[0] + width / 2;
// if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
// final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
// referenceX = screenWidth - referenceX; // mirror
// }
StringBuilder hint = new StringBuilder("#");
if (Color.alpha(color) != 255) {
hint.append(Integer.toHexString(color).toUpperCase(Locale.getDefault()));
} else {
hint.append(String.format("%06X", 0xFFFFFF & color).toUpperCase(Locale.getDefault()));
}
Toast cheatSheet = Toast.makeText(getContext(), hint.toString() + " " + getContext().getResources().getString(R.string.copy_to_clipboard), Toast.LENGTH_SHORT);
// if (midy < displayFrame.height()) {
// // Show along the top; follow action buttons
// cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX,
// screenPos[1] + height - displayFrame.top);
// } else {
// // Show along the bottom center
// cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, height);
// }
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("color", hint.toString());
clipboard.setPrimaryClip(clip);
cheatSheet.show();
}
示例10: onFormulaClicked
import android.content.ClipboardManager; //导入方法依赖的package包/类
public void onFormulaClicked(View view) {
if (view instanceof TextView) {
TextView textView = (TextView) view;
final ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
final CharSequence textToCopy = textView.getText();
final ClipData clip = ClipData.newPlainText("formula", textToCopy);
Snackbar.make(binding.coordinatorLayout, String.format(getString(R.string.copied_alert), textToCopy), Snackbar.LENGTH_SHORT).show();
clipboard.setPrimaryClip(clip);
}
}
示例11: setString
import android.content.ClipboardManager; //导入方法依赖的package包/类
@Override
@JSMethod
public void setString(String text) {
if(null == text) {
return;
}
Context context = mWXSDKInstance.getContext();
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(CLIP_KEY, text);
clipboard.setPrimaryClip(clip);
}
示例12: setIntent
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* 设置意图到剪贴板
*
* @param intent 意图
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void setIntent(Intent intent)
{
ClipboardManager clipboardManager = Managers.getClipboardManager();
clipboardManager.setPrimaryClip(ClipData.newIntent(Intent, intent));
}
示例13: addToClipboard
import android.content.ClipboardManager; //导入方法依赖的package包/类
/**
* Places a string into the device's clipboard to paste
*
* @param context calling context
* @param label clip label
* @param content string to be pasted
*/
public static void addToClipboard(Context context, String label, String content) {
// Get the clipboard manager
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
// Create the new Clip Data with the label and content
ClipData clip = ClipData.newPlainText(label, content);
// Put the clip data into the clipboard manager
clipboard.setPrimaryClip(clip);
}
示例14: copyToClipboard
import android.content.ClipboardManager; //导入方法依赖的package包/类
public static void copyToClipboard(Activity activity, String text) {
ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context
.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("copy", text);
clipboard.setPrimaryClip(clip);
}
示例15: findEditText
import android.content.ClipboardManager; //导入方法依赖的package包/类
private boolean findEditText(AccessibilityNodeInfo rootNode, String content)
{
int count = rootNode.getChildCount();
// android.util.Log.d("maptrix", "root class=" + rootNode.getClassName() + "," + rootNode.getText() + "," + count);
for (int i = 0; i < count; i++)
{
AccessibilityNodeInfo nodeInfo = rootNode.getChild(i);
if (nodeInfo == null)
{
// android.util.Log.d("maptrix", "nodeinfo = null");
continue;
}
// android.util.Log.d("maptrix", "class=" + nodeInfo.getClassName());
// android.util.Log.e("maptrix", "ds=" + nodeInfo.getContentDescription());
if (nodeInfo.getContentDescription() != null)
{
int nindex = nodeInfo.getContentDescription().toString().indexOf(name);
int cindex = nodeInfo.getContentDescription().toString().indexOf(scontent);
// android.util.Log.e("maptrix", "nindex=" + nindex + " cindex=" + cindex);
if (nindex != -1)
{
itemNodeinfo = nodeInfo;
// android.util.Log.i("maptrix", "find node info");
}
}
if ("android.widget.EditText".equals(nodeInfo.getClassName()))
{
// android.util.Log.i("maptrix", "==================");
Bundle arguments = new Bundle();
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD);
arguments.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
true);
nodeInfo.performAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY,
arguments);
nodeInfo.performAction(AccessibilityNodeInfo.ACTION_FOCUS);
ClipData clip = ClipData.newPlainText("label", content);
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboardManager.setPrimaryClip(clip);
nodeInfo.performAction(AccessibilityNodeInfo.ACTION_PASTE);
return true;
}
if (findEditText(nodeInfo, content))
{
return true;
}
}
return false;
}