List of usage examples for android.content ClipData newPlainText
static public ClipData newPlainText(CharSequence label, CharSequence text)
From source file:Main.java
public static boolean copyStringToClipboard(Context context, String label, String src) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(label, src); clipboard.setPrimaryClip(clip);//ww w. j ava 2s .c o m return true; }
From source file:Main.java
/** * Copy tags to clipboard as multi-line text in the form * key1=value1//from w w w. ja va2s. c o m * key2=value2 * ..... * @param tags */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static void copyTags(Context ctx, Map<String, String> tags) { StringBuffer tagsAsText = new StringBuffer(); for (String key : tags.keySet()) { tagsAsText.append(key + "=" + tags.get(key) + "\n"); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipboardManager clipboard = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("OSM Tags", tagsAsText.toString()); clipboard.setPrimaryClip(clip); } else { android.text.ClipboardManager oldClipboard = (android.text.ClipboardManager) ctx .getSystemService(Context.CLIPBOARD_SERVICE); oldClipboard.setText(tagsAsText.toString()); } }
From source file:Main.java
/** * <pre>/*from w w w . jav a 2 s. c om*/ * Copy text to clipboard. * Different implementation for API < 11 and API >= 11. * </pre> */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static void copyTextToClipboard(String text) { if (Build.VERSION.SDK_INT < 11) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getCurrentContext() .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(text); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getCurrentContext() .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("PoketChat Copy To Clipboard", text)); } }
From source file:Main.java
public static void copyToClipBoard(Context context, String text, String success) { ClipData clipData = ClipData.newPlainText("meizhi_copy", text); ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); manager.setPrimaryClip(clipData);// www .j a v a 2 s. c o m Toast.makeText(context, success, Toast.LENGTH_SHORT).show(); }
From source file:Main.java
/** * /*from www . ja v a 2 s . co m*/ * @param context * @param label User-visible label for the clip data. * @param text The actual text in the clip. */ public static void copyFromEdit(Context context, CharSequence label, CharSequence text) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ((android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE)) .setPrimaryClip(ClipData.newPlainText(label, text)); return; } ((android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE)).setText(text); }
From source file:Main.java
@SuppressWarnings("deprecation") public static void setText(Context context, CharSequence sequence) { ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipData clip = ClipData.newPlainText("ClipboardManagerUtil", sequence); clipboardManager.setPrimaryClip(clip); } else {//from www . j a v a 2s . c o m clipboardManager.setText(sequence); } }
From source file:Main.java
public static void copyToClipboard(Context context, String label, String string, int toastMessageId) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(label, string); clipboard.setPrimaryClip(clip);// w w w . ja v a2 s . c o m if (toastMessageId > 0) { Toast.makeText(context, toastMessageId, Toast.LENGTH_LONG).show(); } }
From source file:Main.java
/** * Copy text to Clipboard// ww w. j a va 2s . c o m * * @param context * @param text */ public static void copy(Context context, String text) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText(null, text)); }
From source file:Main.java
/** * Copy a text to the clipboard.//from w w w.j a v a2 s. co m * @param context The current context. * @param text The text to copy. * @param toastMessage The message to show in a Toast notification. If empty or null, does not display notification. */ public static void copyTextToClipboard(Context context, String text, String toastMessage) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText(text, text)); if ((toastMessage != null) && (toastMessage.length() > 0)) { Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show(); } }
From source file:Main.java
public static boolean setText(final Context context, final CharSequence text) { if (context == null) return false; final ClipboardManager clipboardManager = (ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setPrimaryClip(ClipData.newPlainText(text, text)); return true;/* ww w . j a v a 2 s . c o m*/ }