List of usage examples for android.content ClipData newPlainText
static public ClipData newPlainText(CharSequence label, CharSequence text)
From source file:Main.java
public static void clip(Context context, String text) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboardManager = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(text);//from ww w . j a v a 2 s. co m } else { ClipboardManager clipboardManager = (ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setPrimaryClip(ClipData.newPlainText("content", text)); } }
From source file:Main.java
/** * Copy a text to the clipboard./*from w w w .j av 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(Activity.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
/** * This will copy text to the device's clipboard. * * @param context an application or activity context * @param text the string to be copied to the clipboard * @param description a user-visible label for the copied text *//*from ww w. j av a 2 s. com*/ @TargetApi(VERSION_CODES.HONEYCOMB) public static void copyText(Context context, String text, String description) { if (IS_AT_LEAST_HC) { ClipData clip = ClipData.newPlainText(description, text); ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(clip); } else { android.text.ClipboardManager cm = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(text); } }
From source file:Main.java
public static void setClipBoard(final Context context, final String msg, Handler handler) { Runnable updater = new Runnable() { public void run() { ClipboardManager clip = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = ClipData.newPlainText("Remoteroid_Clip", msg); clip.setPrimaryClip(data);//from w w w . j a v a2 s. c o m } }; handler.post(updater); }
From source file:Main.java
public static void addToClipboard(Context ctx, String text) { ClipboardManager clipboardManager = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setPrimaryClip(ClipData.newPlainText(CLIPBOARD_LABEL, text)); }
From source file:Main.java
@SuppressLint("NewApi") public static void copyToClipboard(Context context, String message) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipData clip = ClipData.newPlainText("", message); clipboard.setPrimaryClip(clip);//www.j av a 2 s . co m } else { clipboard.setText(message); } }
From source file:com.btmura.android.reddit.app.MenuHelper.java
/** * Sets a plain text {@link ClipData} with the provided label and text to the * clipboard and shows a toast with the text. *///from w ww . j a va 2s . c o m public static void copyUrl(Context context, CharSequence label, CharSequence text) { context = context.getApplicationContext(); ClipboardManager cb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); cb.setPrimaryClip(ClipData.newPlainText(label, text)); Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); }
From source file:me.zchang.onchart.ui.DonateFragment.java
@NonNull @Override//www . j a v a2 s. c o m public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setPositiveButton(getString(R.string.button_donate), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = getActivity().getPackageManager() .getLaunchIntentForPackage("com.eg.android.AlipayGphone"); ClipboardManager clipboardManager = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = ClipData.newPlainText(ClipDescription.MIMETYPE_TEXT_PLAIN, getString(R.string.alipay_account)); clipboardManager.setPrimaryClip(data); if (intent != null) { Toast.makeText(getActivity(), getString(R.string.alert_clipboard_complete), Toast.LENGTH_LONG) .show(); startActivity(intent); } else { Toast.makeText(getActivity(), getString(R.string.alert_no_alipay), Toast.LENGTH_SHORT).show(); } } }).setView(getActivity().getLayoutInflater().inflate(R.layout.fragment_donate, null)); return builder.create(); }
From source file:cc.echonet.coolmicapp.AboutActivity.java
public void onCMDAboutCopy(View view) { ClipData myClip = ClipData.newPlainText("text", getString(R.string.aboutactivity_copy_string, BuildConfig.VERSION_NAME, BuildConfig.BUILD_TYPE, BuildConfig.GIT_BRANCH, BuildConfig.GIT_REVISION, BuildConfig.GIT_DIRTY)); myClipboard.setPrimaryClip(myClip);/* w ww . j a va2 s .c o m*/ Toast.makeText(getApplicationContext(), R.string.aboutactivity_copied_string, Toast.LENGTH_SHORT).show(); }
From source file:com.actionbarsherlock.sample.hcgallery.TitlesFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //Current position should survive screen rotations. if (savedInstanceState != null) { mCategory = savedInstanceState.getInt("category"); mCurPosition = savedInstanceState.getInt("listPosition"); }//from w w w.j a va 2s . c om populateTitles(mCategory); ListView lv = getListView(); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); lv.setCacheColorHint(Color.TRANSPARENT); lv.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) { final String title = (String) ((TextView) v).getText(); // Set up clip data with the category||entry_id format. final String textData = String.format("%d||%d", mCategory, pos); ClipData data = ClipData.newPlainText(title, textData); v.startDrag(data, new MyDragShadowBuilder(v), null, 0); return true; } }); selectPosition(mCurPosition); }