List of usage examples for android.content ClipboardManager setPrimaryClip
public void setPrimaryClip(@NonNull ClipData clip)
From source file:io.github.marktony.espresso.mvp.packagedetails.PackageDetailsFragment.java
/** * Copy the package number(id) to clipboard. * @param packageId The package number.//from ww w .ja v a 2 s . c o m */ @Override public void copyPackageNumber(@NonNull String packageId) { ClipboardManager manager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = ClipData.newPlainText("text", packageId); manager.setPrimaryClip(data); Snackbar.make(fab, R.string.package_number_copied, Snackbar.LENGTH_SHORT).show(); }
From source file:com.kobi.metalsexchange.app.CalculateFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_copy) { // Gets a handle to the clipboard service. ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); String price = Utility.getFormattedCurrency(calculateFragmentViewHelper.getPriceResult(), Utility.getPreferredCurrency(getActivity()), getActivity(), false); ClipData clip = ClipData.newPlainText("rate", price); clipboard.setPrimaryClip(clip); Toast toast = Toast.makeText(getActivity().getBaseContext(), getString(R.string.copy_to_clipboard_toast, price), Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();//from w w w . ja v a 2 s. c om } return super.onOptionsItemSelected(item); }
From source file:com.z299studio.pb.DetailFragment.java
private void copyToClipboard(String label, String text) { ClipboardManager clipboardManager = (ClipboardManager) (getActivity() .getSystemService(Context.CLIPBOARD_SERVICE)); ClipData clipData = ClipData.newPlainText(label, text); clipboardManager.setPrimaryClip(clipData); Application.showToast(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT); }
From source file:com.wowza.gocoder.sdk.sampleapp.InfoActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_share: String uriText = "mailto:support@wowza.com" + "?subject=" + Uri.encode("GoCoder SDK Support Information") + "&body=" + Uri.encode(shareContents()); Uri uri = Uri.parse(uriText);//from w w w . j av a2s. co m Intent sendIntent = new Intent(Intent.ACTION_SENDTO); sendIntent.setData(uri); startActivity(Intent.createChooser(sendIntent, "Send to Wowza Support")); return true; case R.id.action_copy: ClipboardManager myClipboard; myClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData myClip; myClip = ClipData.newPlainText("text", shareContents()); myClipboard.setPrimaryClip(myClip); Toast.makeText(this, "Copied to clipboard", Toast.LENGTH_SHORT).show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.softminds.matrixcalculator.OperationFragments.NormFreb.java
@Override public void onListItemClick(ListView L, View V, int position, long id) { final int pos = position; final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getContext());/* www .j a v a 2 s . co m*/ builder.setPositiveButton(R.string.copy, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ClipboardManager clipboardManager = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("NORM_FREB_RES", GetText(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(pos) .getNormFrobenious())); clipboardManager.setPrimaryClip(clipData); if (clipboardManager.hasPrimaryClip()) { Toast.makeText(getContext(), R.string.CopyToClip, Toast.LENGTH_SHORT).show(); } else Log.d("ClipData", "Failed to set to Clip board"); dialogInterface.dismiss(); } }); builder.setNeutralButton(R.string.Done, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }); builder.setMessage("Frebenious Norm is : " + GetText(((GlobalValues) getActivity().getApplication()) .GetCompleteList().get(position).getNormFrobenious())); builder.setTitle(R.string.normFreb); builder.setCancelable(false); builder.show(); }
From source file:com.softminds.matrixcalculator.OperationFragments.NormInfinity.java
@Override public void onListItemClick(ListView L, View V, int position, long id) { final int pos = position; final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getContext());//from w w w .ja v a 2 s .c o m builder.setPositiveButton(R.string.copy, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ClipboardManager clipboardManager = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("NORM_INFINITY_RES", GetText(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(pos) .getNormInfinity())); clipboardManager.setPrimaryClip(clipData); if (clipboardManager.hasPrimaryClip()) { Toast.makeText(getContext(), R.string.CopyToClip, Toast.LENGTH_SHORT).show(); } else Log.d("ClipData", "Failed to set to Clip board"); dialogInterface.dismiss(); } }); builder.setNeutralButton(R.string.Done, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }); builder.setMessage("Infinity Norm is : " + GetText( ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(position).getNormInfinity())); builder.setTitle(R.string.normInfinity); builder.setCancelable(false); builder.show(); }
From source file:ru.valle.safetrade.BuyActivity.java
@SuppressWarnings("deprecation") private void copyTextToClipboard(String label, String text) { if (Build.VERSION.SDK_INT >= 11) { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(label, text); clipboard.setPrimaryClip(clip); } else {/*from ww w . java2 s .co m*/ android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); clipboard.setText(text); } }
From source file:com.github.dfa.diaspora_android.ui.ContextMenuWebView.java
@Override protected void onCreateContextMenu(ContextMenu menu) { super.onCreateContextMenu(menu); HitTestResult result = getHitTestResult(); MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { HitTestResult result = getHitTestResult(); String url = result.getExtra(); switch (item.getItemId()) { //Save image to external memory case ID_SAVE_IMAGE: { boolean writeToStoragePermitted = true; if (android.os.Build.VERSION.SDK_INT >= 23) { int hasWRITE_EXTERNAL_STORAGE = parentActivity .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) { writeToStoragePermitted = false; if (!parentActivity.shouldShowRequestPermissionRationale( Manifest.permission.WRITE_EXTERNAL_STORAGE)) { new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image) .setPositiveButton(context.getText(android.R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (android.os.Build.VERSION.SDK_INT >= 23) parentActivity.requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE); } }) .setNegativeButton(context.getText(android.R.string.no), null).show(); }//from w ww . j a va2s.co m parentActivity.requestPermissions( new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE); } } if (writeToStoragePermitted) { if (url != null) { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); File destinationFile = new File(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png"); request.setDestinationUri(Uri.fromFile(destinationFile)); ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request); Toast.makeText(context, context.getText(R.string.share__toast_saved_image_to_location) + " " + destinationFile.getAbsolutePath(), Toast.LENGTH_LONG).show(); } } } break; case ID_SHARE_IMAGE: if (url != null) { boolean writeToStoragePermitted = true; if (android.os.Build.VERSION.SDK_INT >= 23) { int hasWRITE_EXTERNAL_STORAGE = parentActivity .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) { writeToStoragePermitted = false; if (!parentActivity.shouldShowRequestPermissionRationale( Manifest.permission.WRITE_EXTERNAL_STORAGE)) { new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image) .setPositiveButton(context.getText(android.R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (android.os.Build.VERSION.SDK_INT >= 23) parentActivity.requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE); } }) .setNegativeButton(context.getText(android.R.string.no), null).show(); } else { parentActivity.requestPermissions( new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE); } } } if (writeToStoragePermitted) { final Uri local = Uri.parse(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png"); new ImageDownloadTask(null, local.getPath()) { @Override protected void onPostExecute(Bitmap result) { Uri myUri = Uri.fromFile(new File(local.getPath())); Intent sharingIntent = new Intent(); sharingIntent.setAction(Intent.ACTION_SEND); sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri); sharingIntent.setType("image/png"); sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); context.startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.action_share_dotdotdot))); } }.execute(url); } } else { Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show(); } break; case ID_IMAGE_EXTERNAL_BROWSER: if (url != null) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); context.startActivity(intent); } break; //Copy url to clipboard case ID_COPY_LINK: if (url != null) { ClipboardManager clipboard = (ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Toast.makeText(context, R.string.share__toast_link_address_copied, Toast.LENGTH_SHORT) .show(); } break; //Try to share link to other apps case ID_SHARE_LINK: if (url != null) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, url); sendIntent.setType("text/plain"); context.startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.context_menu_share_link))); } break; } return true; } }; //Build context menu if (result.getType() == HitTestResult.IMAGE_TYPE || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { // Menu options for an image. menu.setHeaderTitle(result.getExtra()); menu.add(0, ID_SAVE_IMAGE, 0, context.getString(R.string.context_menu_save_image)) .setOnMenuItemClickListener(handler); menu.add(0, ID_IMAGE_EXTERNAL_BROWSER, 0, context.getString(R.string.context_menu_open_external_browser)) .setOnMenuItemClickListener(handler); menu.add(0, ID_SHARE_IMAGE, 0, context.getString(R.string.context_menu_share_image)) .setOnMenuItemClickListener(handler); } else if (result.getType() == HitTestResult.ANCHOR_TYPE || result.getType() == HitTestResult.SRC_ANCHOR_TYPE) { // Menu options for a hyperlink. menu.setHeaderTitle(result.getExtra()); menu.add(0, ID_COPY_LINK, 0, context.getString(R.string.context_menu_copy_link)) .setOnMenuItemClickListener(handler); menu.add(0, ID_SHARE_LINK, 0, context.getString(R.string.context_menu_share_link)) .setOnMenuItemClickListener(handler); } }
From source file:com.github.dfa.diaspora_android.web.ContextMenuWebView.java
@Override protected void onCreateContextMenu(ContextMenu menu) { super.onCreateContextMenu(menu); HitTestResult result = getHitTestResult(); MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { HitTestResult result = getHitTestResult(); String url = result.getExtra(); switch (item.getItemId()) { //Save image to external memory case ID_SAVE_IMAGE: { boolean writeToStoragePermitted = true; if (android.os.Build.VERSION.SDK_INT >= 23) { int hasWRITE_EXTERNAL_STORAGE = parentActivity .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) { writeToStoragePermitted = false; if (!parentActivity.shouldShowRequestPermissionRationale( Manifest.permission.WRITE_EXTERNAL_STORAGE)) { new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image) .setPositiveButton(context.getText(android.R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (android.os.Build.VERSION.SDK_INT >= 23) parentActivity.requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE); } }) .setNegativeButton(context.getText(android.R.string.no), null).show(); }//ww w . j a v a 2 s . com parentActivity.requestPermissions( new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE); } } if (writeToStoragePermitted) { if (url != null) { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); File destinationFile = new File(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png"); request.setDestinationUri(Uri.fromFile(destinationFile)); ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request); Toast.makeText(context, context.getText(R.string.share__toast_saved_image_to_location) + " " + destinationFile.getAbsolutePath(), Toast.LENGTH_LONG).show(); } } } break; case ID_SHARE_IMAGE: if (url != null) { boolean writeToStoragePermitted = true; if (android.os.Build.VERSION.SDK_INT >= 23) { int hasWRITE_EXTERNAL_STORAGE = parentActivity .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) { writeToStoragePermitted = false; if (!parentActivity.shouldShowRequestPermissionRationale( Manifest.permission.WRITE_EXTERNAL_STORAGE)) { new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image) .setPositiveButton(context.getText(android.R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (android.os.Build.VERSION.SDK_INT >= 23) parentActivity.requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE); } }) .setNegativeButton(context.getText(android.R.string.no), null).show(); } else { parentActivity.requestPermissions( new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE); } } } if (writeToStoragePermitted) { final Uri local = Uri.parse(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png"); new ImageDownloadTask(null, local.getPath()) { @Override protected void onPostExecute(Bitmap result) { Uri myUri = Uri.fromFile(new File(local.getPath())); Intent sharingIntent = new Intent(); sharingIntent.setAction(Intent.ACTION_SEND); sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri); sharingIntent.setType("image/png"); sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); context.startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.action_share_dotdotdot))); } }.execute(url); } } else { Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show(); } break; case ID_IMAGE_EXTERNAL_BROWSER: if (url != null) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); context.startActivity(intent); } break; //Copy url to clipboard case ID_COPY_LINK: if (url != null) { ClipboardManager clipboard = (ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Toast.makeText(context, R.string.share__toast_link_address_copied, Toast.LENGTH_SHORT) .show(); } break; //Try to share link to other apps case ID_SHARE_LINK: if (url != null) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, url); sendIntent.setType("text/plain"); context.startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.context_menu_share_link))); } break; } return true; } }; //Build context menu if (result.getType() == HitTestResult.IMAGE_TYPE || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { // Menu options for an image. menu.setHeaderTitle(result.getExtra()); menu.add(0, ID_SAVE_IMAGE, 0, context.getString(R.string.context_menu_save_image)) .setOnMenuItemClickListener(handler); menu.add(0, ID_IMAGE_EXTERNAL_BROWSER, 0, context.getString(R.string.context_menu_open_external_browser)) .setOnMenuItemClickListener(handler); menu.add(0, ID_SHARE_IMAGE, 0, context.getString(R.string.context_menu_share_image)) .setOnMenuItemClickListener(handler); } else if (result.getType() == HitTestResult.ANCHOR_TYPE || result.getType() == HitTestResult.SRC_ANCHOR_TYPE) { // Menu options for a hyperlink. menu.setHeaderTitle(result.getExtra()); menu.add(0, ID_COPY_LINK, 0, context.getString(R.string.context_menu_copy_link)) .setOnMenuItemClickListener(handler); menu.add(0, ID_SHARE_LINK, 0, context.getString(R.string.context_menu_share_link)) .setOnMenuItemClickListener(handler); } }
From source file:com.keylesspalace.tusky.fragment.SFragment.java
protected void more(final Status status, View view, final int position) { final String id = status.getActionableId(); final String accountId = status.getActionableStatus().getAccount().getId(); final String accountUsename = status.getActionableStatus().getAccount().getUsername(); final Spanned content = status.getActionableStatus().getContent(); final String statusUrl = status.getActionableStatus().getUrl(); PopupMenu popup = new PopupMenu(getContext(), view); // Give a different menu depending on whether this is the user's own toot or not. if (loggedInAccountId == null || !loggedInAccountId.equals(accountId)) { popup.inflate(R.menu.status_more); } else {/*from w w w. jav a 2 s .c o m*/ popup.inflate(R.menu.status_more_for_user); Menu menu = popup.getMenu(); if (status.getVisibility() == Status.Visibility.PRIVATE) { boolean reblogged = status.getReblogged(); if (status.getReblog() != null) reblogged = status.getReblog().getReblogged(); menu.findItem(R.id.status_reblog_private).setVisible(!reblogged); menu.findItem(R.id.status_unreblog_private).setVisible(reblogged); } } popup.setOnMenuItemClickListener(item -> { switch (item.getItemId()) { case R.id.status_share_content: { StringBuilder sb = new StringBuilder(); sb.append(status.getAccount().getUsername()); sb.append(" - "); sb.append(status.getContent().toString()); Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, sb.toString()); sendIntent.setType("text/plain"); startActivity( Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_content_to))); return true; } case R.id.status_share_link: { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, statusUrl); sendIntent.setType("text/plain"); startActivity( Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_link_to))); return true; } case R.id.status_copy_link: { ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(null, statusUrl); clipboard.setPrimaryClip(clip); return true; } case R.id.status_mute: { timelineCases().mute(accountId); return true; } case R.id.status_block: { timelineCases().block(accountId); return true; } case R.id.status_report: { openReportPage(accountId, accountUsename, id, content); return true; } case R.id.status_unreblog_private: { onReblog(false, position); return true; } case R.id.status_reblog_private: { onReblog(true, position); return true; } case R.id.status_delete: { timelineCases().delete(id); removeItem(position); return true; } } return false; }); popup.show(); }