List of usage examples for android.content ClipboardManager setText
@Deprecated public void setText(CharSequence text)
From source file:com.forrestguice.suntimeswidget.LocationConfigView.java
public void copyLocationToClipboard(Context context, boolean silent) { WidgetSettings.Location location = getLocation(); String clipboardText = location.toString(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("lat, lon", clipboardText); clipboard.setPrimaryClip(clip);/*from w w w . j a v a 2s . c o m*/ } else { @SuppressWarnings("deprecation") android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(clipboardText); } if (!silent) { Toast copiedMsg = Toast.makeText(context, Html.fromHtml(context.getString(R.string.location_dialog_toast_copied, clipboardText)), Toast.LENGTH_LONG); copiedMsg.show(); } }
From source file:de.enlightened.peris.PostsFragment.java
@SuppressLint("NewApi") private void storePostInClipboard() { //Copy text support for all Android versions if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { final ClipboardManager clipboard = (ClipboardManager) this.activity .getSystemService(Context.CLIPBOARD_SERVICE); final ClipData cd = ClipData.newHtmlText(this.currentThreadSubject, this.selectedPost.body, this.selectedPost.body); clipboard.setPrimaryClip(cd);/*from w ww . j ava 2s.co m*/ } else { final android.text.ClipboardManager clipboard = (android.text.ClipboardManager) this.activity .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(this.selectedPost.body); } final Toast toast = Toast.makeText(this.activity, "Text copied!", Toast.LENGTH_SHORT); toast.show(); }
From source file:sjizl.com.ChatActivityFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int index = info.position; String textTocopy = ArrChatLines.get(index).getLaatstBericht(); switch (item.getItemId()) { case R.id.delete: // quoteResult.remove(info.position); // ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged(); Toast.makeText(getActivity().getApplicationContext(), "delete almost implementated", Toast.LENGTH_SHORT) .show();/*from w ww .ja v a 2 s. c om*/ return false; case R.id.copy: // quoteResult.remove(info.position); // ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("simple text", textTocopy); clipboard.setPrimaryClip(clip); } else { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(textTocopy); } //place your TextView's text in clipboard Toast.makeText(getActivity().getApplicationContext(), "Item copied", Toast.LENGTH_SHORT).show(); return false; } return false; }
From source file:sjizl.com.ChatActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int index = info.position; String textTocopy = ArrChatLines.get(index).getLaatstBericht(); switch (item.getItemId()) { case R.id.delete: // quoteResult.remove(info.position); // ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged(); Toast.makeText(getApplicationContext(), "delete almost implementated", Toast.LENGTH_SHORT).show(); return false; case R.id.copy: // quoteResult.remove(info.position); // ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("simple text", textTocopy); clipboard.setPrimaryClip(clip); } else {/*from w ww . j av a 2 s . co m*/ android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); clipboard.setText(textTocopy); } //place your TextView's text in clipboard Toast.makeText(getApplicationContext(), "Item copied", Toast.LENGTH_SHORT).show(); return false; } return false; }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * @inheritDoc/* w w w. ja va 2 s . c o m*/ */ public void copyToClipboard(final Object obj) { if (getActivity() == null) { return; } getActivity().runOnUiThread(new Runnable() { @Override public void run() { int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < 11) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(obj.toString()); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = ClipData.newPlainText("Codename One", obj.toString()); clipboard.setPrimaryClip(clip); } } }); }