List of usage examples for android.content ClipboardManager setPrimaryClip
public void setPrimaryClip(@NonNull ClipData clip)
From source file:io.github.marktony.espresso.mvp.packages.PackagesFragment.java
/** * Copy the package number to clipboard. *//*from w w w . j a va 2 s.com*/ @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:me.acristoffers.tracker.fragments.PackageDetailsFragment.java
private void setupUI() { final Activity activity = getActivity(); final View view = getView(); if (activity == null || view == null) { return;/*w w w . java2s . c o m*/ } String code = null; final Bundle arguments = getArguments(); if (arguments != null) { code = arguments.getString(PackageDetailsActivity.PACKAGE_CODE); } if (code == null || code.isEmpty()) { final Intent intent = activity.getIntent(); if (intent != null) { code = intent.getStringExtra(PackageDetailsActivity.PACKAGE_CODE); } } if (code == null || code.isEmpty()) { return; } final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.steps); final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(activity); recyclerView.setLayoutManager(layoutManager); pkg = new Package(code, getActivity(), null); final StepListAdapter stepListAdapter = new StepListAdapter(pkg, activity); recyclerView.setAdapter(stepListAdapter); TextView textView = (TextView) view.findViewById(R.id.name); textView.setText(pkg.getName()); textView = (TextView) view.findViewById(R.id.code); textView.setText(pkg.getCod()); textView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { final ClipboardManager clipboardManager = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); if (clipboardManager != null) { final String code = pkg.getCod(); final ClipData clipData = ClipData.newPlainText(code, code); clipboardManager.setPrimaryClip(clipData); final Toast toast = Toast.makeText(activity, R.string.code_copied, Toast.LENGTH_SHORT); toast.show(); return true; } return false; } }); if (!pkg.getSteps().isEmpty()) { textView = (TextView) view.findViewById(R.id.emptyStepView); textView.setVisibility(View.INVISIBLE); } final NotificationManager nm = (NotificationManager) activity .getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(pkg.getId()); }
From source file:de.syss.MifareClassicTool.Common.java
/** * Copy a text to the Android clipboard. * @param text The text that should by stored on the clipboard. * @param context Context of the SystemService * (and the Toast message that will by shown). *//* ww w. j a va 2 s . co m*/ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static void copyToClipboard(String text, Context context) { if (!text.equals("")) { if (Build.VERSION.SDK_INT >= 11) { // Android API level 11+. android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("mifare classic tool data", text); clipboard.setPrimaryClip(clip); } else { // Android API level 10. android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(text); } Toast.makeText(context, R.string.info_copied_to_clipboard, Toast.LENGTH_SHORT).show(); } }
From source file:net.zjy.zxcardumper.Common.java
/** * Copy a text to the Android clipboard. * @param text The text that should by stored on the clipboard. * @param context Context of the SystemService * (and the Toast message that will by shown). *///from w w w . j a va 2s . c o m @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static void copyToClipboard(String text, Context context) { if (!text.equals("")) { if (Build.VERSION.SDK_INT >= 11) { // Android API level 11+. android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("MIFARE classic tool data", text); clipboard.setPrimaryClip(clip); } else { // Android API level 10. android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(text); } Toast.makeText(context, R.string.info_copied_to_clipboard, Toast.LENGTH_SHORT).show(); } }
From source file:arun.com.chameleonskinforkwlp.MainActivity.java
public void onFormulaClicked(View view) { if (view instanceof TextView) { TextView textView = (TextView) view; final ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); final CharSequence textToCopy = textView.getText(); final ClipData clip = ClipData.newPlainText("formula", textToCopy); Snackbar.make(binding.coordinatorLayout, String.format(getString(R.string.copied_alert), textToCopy), Snackbar.LENGTH_SHORT).show(); clipboard.setPrimaryClip(clip); }//from w ww.j a va 2 s .co m }
From source file:com.example.linhdq.test.documents.viewing.single.DocumentActivity.java
@SuppressLint("NewApi") private void copyTextToClipboardNewApi(final String text) { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(getString(R.string.app_name), text); clipboard.setPrimaryClip(clip); }
From source file:cn.zhangls.android.weibo.ui.details.comment.CommentActivity.java
/** * ?//from w w w . j a v a 2 s. c o m */ 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(); }
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 source file:com.artemchep.horario.ui.fragments.details.TeacherDetailsFragment.java
@Override protected ViewGroup onCreateContentView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @NonNull List<ContentItem<Teacher>> contentItems, @Nullable Bundle savedInstanceState) { getToolbar().inflateMenu(R.menu.details_teacher); ViewGroup vg = (ViewGroup) inflater.inflate(R.layout.fragment_details_teacher, container, false); initWithFab(R.id.action_edit, R.drawable.ic_pencil_white_24dp); mNoteContainer = vg.findViewById(R.id.info_container); mPhoneContainer = vg.findViewById(R.id.phone_container); mPhoneContainer.setOnClickListener(new View.OnClickListener() { @Override// w w w . j a va 2 s . com public void onClick(View view) { if (TextUtils.isEmpty(mModel.phone)) { Timber.tag(TAG).w("Tried to copy an empty phone!"); return; } // Copy email to clipboard ClipboardManager clipboard = (ClipboardManager) getContext() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(mModel.phone, mModel.phone); // TODO: More informative description of the clip clipboard.setPrimaryClip(clip); // Show toast message String msg = getString(R.string.details_phone_clipboard, mModel.phone); Toasty.info(getContext(), msg).show(); } }); mEmailContainer = vg.findViewById(R.id.email_container); mEmailContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (TextUtils.isEmpty(mModel.email)) { Timber.tag(TAG).w("Tried to copy an empty email!"); return; } // Copy email to clipboard ClipboardManager clipboard = (ClipboardManager) getContext() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(mModel.email, mModel.email); // TODO: More informative description of the clip clipboard.setPrimaryClip(clip); // Show toast message String msg = getString(R.string.details_email_clipboard, mModel.email); Toasty.info(getContext(), msg).show(); } }); mPhoneButton = (Button) mPhoneContainer.findViewById(R.id.phone_send); mPhoneButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (TextUtils.isEmpty(mModel.phone)) { Timber.tag(TAG).w("Tried to call an empty phone!"); return; } Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:" + mModel.phone)); try { startActivity(intent); } catch (ActivityNotFoundException ignored) { } } }); mEmailButton = (Button) mEmailContainer.findViewById(R.id.email_send); mEmailButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (TextUtils.isEmpty(mModel.email)) { Timber.tag(TAG).w("Tried to send to an empty email!"); return; } String[] recipients = { mModel.email }; Intent intent = new Intent().putExtra(Intent.EXTRA_EMAIL, recipients); intent.setAction(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:")); // only email apps should handle it try { startActivity(intent); } catch (ActivityNotFoundException e) { // TODO:!!!!! String msg = "No email app"; //getString(R.string.feedback_error_no_app); Toasty.info(getContext(), msg).show(); } } }); mNoteTextView = (TextView) mNoteContainer.findViewById(R.id.info); mEmailTextView = (TextView) mEmailContainer.findViewById(R.id.email); mPhoneTextView = (TextView) mPhoneContainer.findViewById(R.id.phone); // Note contentItems.add(new ContentItem<Teacher>() { @Override public void onSet(@Nullable Teacher model) { if (model == null || TextUtils.isEmpty(model.info)) { mNoteContainer.setVisibility(View.GONE); } else { mNoteContainer.setVisibility(View.VISIBLE); mNoteTextView.setText(model.info); } } @Override public boolean hasChanged(@Nullable Teacher old, @Nullable Teacher model) { String a = old != null ? old.info : null; String b = model != null ? model.info : null; return !TextUtils.equals(a, b); } }); // Email contentItems.add(new ContentItem<Teacher>() { @Override public void onSet(@Nullable Teacher model) { if (model == null || TextUtils.isEmpty(model.email)) { mEmailContainer.setVisibility(View.GONE); } else { mEmailContainer.setVisibility(View.VISIBLE); mEmailTextView.setText(model.info); if (PatternUtils.isEmail(model.email)) { mEmailButton.setVisibility(View.VISIBLE); } else mEmailButton.setVisibility(View.GONE); } } @Override public boolean hasChanged(@Nullable Teacher old, @Nullable Teacher model) { String a = old != null ? old.email : null; String b = model != null ? model.email : null; return !TextUtils.equals(a, b); } }); // Phone contentItems.add(new ContentItem<Teacher>() { @Override public void onSet(@Nullable Teacher model) { if (model == null || TextUtils.isEmpty(model.phone)) { mPhoneContainer.setVisibility(View.GONE); } else { mPhoneContainer.setVisibility(View.VISIBLE); mPhoneTextView.setText(model.phone); if (PatternUtils.isPhone(model.phone)) { mPhoneButton.setVisibility(View.VISIBLE); } else mPhoneButton.setVisibility(View.GONE); } } @Override public boolean hasChanged(@Nullable Teacher old, @Nullable Teacher model) { String a = old != null ? old.phone : null; String b = model != null ? model.phone : null; return !TextUtils.equals(a, b); } }); return vg; }
From source file:com.android.browser.BookmarksPageCallbacks.java
private void copy(CharSequence text) { ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); cm.setPrimaryClip(ClipData.newRawUri(null, Uri.parse(text.toString()))); }