List of usage examples for android.content ClipData newPlainText
static public ClipData newPlainText(CharSequence label, CharSequence text)
From source file:net.vivekiyer.GAL.Configure.java
@SuppressWarnings("deprecation") @TargetApi(11)//from w w w. j a va 2s .c o m @Override public void onChoiceDialogOptionPressed(int action) { switch (action) { case android.R.id.copy: if (Utility.isPreHoneycomb()) { final android.text.ClipboardManager clipboard; clipboard = (android.text.ClipboardManager) getSystemService( android.content.Context.CLIPBOARD_SERVICE); clipboard.setText(activeSyncManager.getDeviceId()); } else { ClipboardManager clip = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clip.setPrimaryClip(ClipData.newPlainText("Android Device ID", activeSyncManager.getDeviceId())); //$NON-NLS-1$ } break; } }
From source file:net.gsantner.opoc.util.ShareUtil.java
/*** * Replace (primary) clipboard contents with given {@code text} * @param text Text to be set// w w w . j av a2s. c om */ public boolean setClipboard(CharSequence text) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager cm = ((android.text.ClipboardManager) _context .getSystemService(Context.CLIPBOARD_SERVICE)); if (cm != null) { cm.setText(text); return true; } } else { android.content.ClipboardManager cm = ((android.content.ClipboardManager) _context .getSystemService(Context.CLIPBOARD_SERVICE)); if (cm != null) { ClipData clip = ClipData.newPlainText(_context.getPackageName(), text); cm.setPrimaryClip(clip); return true; } } return false; }
From source file:cc.echonet.coolmicapp.MainActivity.java
public void onImageClick(View view) { try {//from ww w .j a va2 s.c om String portnum = ""; String server = coolmic.getServerName(); Integer port_num = 8000; int counter = 0; for (int i = 0; i < server.length(); i++) { if (server.charAt(i) == ':') { counter++; } } if (counter == 1) { if (server.indexOf("/") > 0) { String[] split = server.split(":"); server = split[0].concat(":").concat(split[1]); portnum = "8000"; port_num = Integer.parseInt(portnum); } else { String[] split = server.split(":"); server = split[0]; portnum = split[1]; port_num = Integer.parseInt(portnum); } } else if (counter == 2) { String[] split = server.split(":"); server = split[0].concat(":").concat(split[1]); portnum = split[2]; port_num = Integer.parseInt(portnum); } Log.d("VS", server); Log.d("VS", portnum); if (server != null && !server.isEmpty()) { String text = server + ":" + port_num.toString() + "/" + coolmic.getMountpoint(); ClipData myClip = ClipData.newPlainText("text", text); myClipboard.setPrimaryClip(myClip); Toast.makeText(getApplicationContext(), "Broadcast URL copied to clipboard!", Toast.LENGTH_SHORT) .show(); } else { Toast.makeText(getApplicationContext(), "Set the connection details", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { Log.e("VS", "Exception", e); } }
From source file:com.chatwing.whitelabel.fragments.ChatMessagesFragment.java
private void copyMessage(Message message) { ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("message content", message.getContent()); clipboard.setPrimaryClip(clip);//from w ww .ja v a 2s . c om }
From source file:org.eatabrick.vecna.Vecna.java
@SuppressWarnings("deprecation") private void copyPassword(Entry entry) { int sdk = Build.VERSION.SDK_INT; if (sdk < 11) { ((android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE)).setText(entry.password); } else {//from w ww . j av a2s. c o m ClipData data = ClipData.newPlainText("simple text", entry.password); ((android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(data); } Toast.makeText(Vecna.this, getString(R.string.copied, entry.account), Toast.LENGTH_SHORT).show(); }
From source file:io.github.marktony.espresso.mvp.packages.PackagesFragment.java
/** * Copy the package number to clipboard. *//*from w ww . jav a 2 s.co m*/ @Override public void copyPackageNumber() { ClipboardManager manager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = ClipData.newPlainText("text", getSelectedPackageNumber()); manager.setPrimaryClip(data); Snackbar.make(fab, R.string.package_number_copied, Snackbar.LENGTH_SHORT).show(); }
From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java
@Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { if (menuItem.getItemId() == R.id.resend_button) { for (int i = 0; i < adapter.getItemCount(); i++) { if (adapter.isItemChecked(i)) { sendMessage(adapter.getItem(i).getDatabaseId()); break; }//from ww w .j a v a2 s . c o m } actionMode.finish(); return true; } else if (menuItem.getItemId() == R.id.info_button) { Message message = null; for (int i = 0; i < adapter.getItemCount(); i++) { if (adapter.isItemChecked(i)) { message = adapter.getItem(i); break; } } if (message != null) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String dialogText; if (message.getType() == Message.Type.INCOMING) { dialogText = (message.getVoipId() == null ? "" : (getString(R.string.conversation_info_id) + " " + message.getVoipId() + "\n")) + getString(R.string.conversation_info_to) + " " + Utils.getFormattedPhoneNumber(message.getDid()) + "\n" + getString(R.string.conversation_info_from) + " " + Utils.getFormattedPhoneNumber(message.getContact()) + "\n" + getString(R.string.conversation_info_date) + " " + dateFormat.format(message.getDate()); } else { dialogText = (message.getVoipId() == null ? "" : (getString(R.string.conversation_info_id) + " " + message.getVoipId() + "\n")) + getString(R.string.conversation_info_to) + " " + Utils.getFormattedPhoneNumber(message.getContact()) + "\n" + getString(R.string.conversation_info_from) + " " + Utils.getFormattedPhoneNumber(message.getDid()) + "\n" + getString(R.string.conversation_info_date) + " " + dateFormat.format(message.getDate()); } Utils.showAlertDialog(this, getString(R.string.conversation_info_title), dialogText, getString(R.string.ok), null, null, null); } actionMode.finish(); return true; } else if (menuItem.getItemId() == R.id.copy_button) { Message message = null; for (int i = 0; i < adapter.getItemCount(); i++) { if (adapter.isItemChecked(i)) { message = adapter.getItem(i); break; } } if (message != null) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Text message", message.getText()); clipboard.setPrimaryClip(clip); } actionMode.finish(); return true; } else if (menuItem.getItemId() == R.id.share_button) { Message message = null; for (int i = 0; i < adapter.getItemCount(); i++) { if (adapter.isItemChecked(i)) { message = adapter.getItem(i); break; } } if (message != null) { Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(android.content.Intent.EXTRA_TEXT, message.getText()); startActivity(Intent.createChooser(intent, null)); } actionMode.finish(); return true; } else if (menuItem.getItemId() == R.id.delete_button) { List<Long> databaseIds = new ArrayList<>(); for (int i = 0; i < adapter.getItemCount(); i++) { if (adapter.isItemChecked(i)) { databaseIds.add(adapter.getItem(i).getDatabaseId()); } } Long[] databaseIdsArray = new Long[databaseIds.size()]; databaseIds.toArray(databaseIdsArray); deleteMessages(databaseIdsArray); actionMode.finish(); return true; } else { return false; } }
From source file:com.krayzk9s.imgurholo.tools.ImageUtils.java
public static void copyImageURL(Fragment fragment, JSONParcelable imageData) { final Activity activity = fragment.getActivity(); final JSONParcelable data = imageData; final Fragment frag = fragment; String[] copyTypes = fragment.getResources().getStringArray(R.array.copyTypes); try {/*from w w w . ja va 2s . com*/ copyTypes[0] = copyTypes[0] + "\nhttp://imgur.com/" + imageData.getJSONObject().getString("id"); copyTypes[1] = copyTypes[1] + "\n" + imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK); copyTypes[2] = copyTypes[2] + "\n<a href=\"http://imgur.com/" + imageData.getJSONObject().getString("id") + "\"><img src=\"" + imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "\" title=\"Hosted by imgur.com\"/></a>"; copyTypes[3] = copyTypes[3] + "\n[IMG]" + imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "[/IMG]"; copyTypes[4] = copyTypes[4] + "\n[URL=http://imgur.com/" + imageData.getJSONObject().getString("id") + "][IMG]" + imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "[/IMG][/URL]"; copyTypes[5] = copyTypes[5] + "\n[Imgur](http://i.imgur.com/" + imageData.getJSONObject().getString("id") + ")"; } catch (JSONException e) { Log.e("Error!", e.toString()); } new AlertDialog.Builder(activity).setTitle("Set Link Type to Copy") .setItems(copyTypes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { ClipboardManager clipboard = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); try { String link = ""; switch (whichButton) { case 0: link = "http://imgur.com/" + data.getJSONObject().getString("id"); break; case 1: link = data.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK); break; case 2: link = "<a href=\"http://imgur.com/" + data.getJSONObject().getString("id") + "\"><img src=\"" + data.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "\" title=\"Hosted by imgur.com\"/></a>"; break; case 3: link = "[IMG]" + data.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "[/IMG]"; break; case 4: link = "[URL=http://imgur.com/" + data.getJSONObject().getString("id") + "][IMG]" + data.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "[/IMG][/URL]"; break; case 5: link = "[Imgur](http://i.imgur.com/" + data.getJSONObject().getString("id") + ")"; break; default: break; } int duration = Toast.LENGTH_SHORT; Toast toast; toast = Toast.makeText(frag.getActivity(), "URL Copied!", duration); toast.show(); ClipData clip = ClipData.newPlainText("imgur Link", link); clipboard.setPrimaryClip(clip); } catch (JSONException e) { Log.e("Error!", "No link in image data!"); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); }
From source file:de.baumann.hhsmoodle.fragmentsMain.FragmentBrowser.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.action_help: helper_main.switchToActivity(getActivity(), FragmentBrowser_Help.class, false); return true; case R.id.action_bookmark: helper_main.switchToActivity(getActivity(), Popup_bookmarks.class, false); return true; case R.id.action_saveBookmark: final Bookmarks_DbAdapter db = new Bookmarks_DbAdapter(getActivity()); db.open();/* www . j av a 2s . co m*/ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); edit_title.setHint(R.string.bookmark_edit_title); edit_title.setText(mWebView.getTitle()); builder.setView(dialogView); builder.setTitle(R.string.bookmark_edit_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(getActivity(), edit_title); dialog2.getButton(android.app.AlertDialog.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Do stuff, possibly set wantToCloseDialog to true then... String inputTag = edit_title.getText().toString().trim(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(edit_title, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG) .show(); } else { db.insert(inputTag, mWebView.getUrl(), "04", "", createDate()); dialog2.dismiss(); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } }); return true; case R.id.menu_share_screenshot: screenshot(); if (shareFile.exists()) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); Uri bmpUri = Uri.fromFile(shareFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_screenshot)))); } return true; case R.id.menu_save_screenshot: screenshot(); return true; case R.id.menu_share_link: Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link)))); return true; case R.id.menu_share_link_browser: String url = mWebView.getUrl(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); getActivity().startActivity(intent); return true; case R.id.menu_share_link_copy: String url2 = mWebView.getUrl(); ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url2)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_LONG).show(); return true; } return false; }
From source file:cn.zhangls.android.weibo.ui.details.comment.CommentActivity.java
/** * ?// w w w .ja v a 2s . c om */ private void createDialog(final Comment comment) { mAlertDialog = new AlertDialog.Builder(CommentActivity.this).setTitle(comment.getUser().getScreen_name()) .setMessage(comment.getText()).setCancelable(true) .setPositiveButton(getResources().getString(R.string.fg_comment_reply), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { EditActivity.actionStart(CommentActivity.this, mWeiboStatus, EditActivity.TYPE_CONTENT_REPLY, comment); } }) .setNegativeButton(getResources().getString(R.string.fg_comment_repost), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { EditActivity.actionStart(CommentActivity.this, mWeiboStatus, EditActivity.TYPE_CONTENT_REPOST, comment); } }) .setNeutralButton(getResources().getString(R.string.fg_comment_copy), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ClipboardManager service = (ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); service.setPrimaryClip(ClipData.newPlainText(null, comment.getText())); ToastUtil.showShortToast(CommentActivity.this, "???"); } }) .create(); mAlertDialog.show(); }