List of usage examples for android.content ClipData newPlainText
static public ClipData newPlainText(CharSequence label, CharSequence text)
From source file:im.neon.util.VectorUtils.java
/** * Copy a text to the clipboard./* w ww. j a v a 2s . c o m*/ * * @param context the context * @param text the text to copy */ public static void copyToClipboard(Context context, CharSequence text) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("", text)); Toast.makeText(context, context.getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show(); }
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//from ww w . ja v a 2 s. c o m 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:org.linphone.compatibility.ApiElevenPlus.java
public static void copyTextToClipboard(Context context, String msg) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Message", msg); clipboard.setPrimaryClip(clip);/*from www . j av a 2s . c o m*/ }
From source file:org.secuso.privacyfriendlypasswordgenerator.dialogs.UpdatePasswordDialog.java
public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = getActivity().getLayoutInflater(); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); rootView = inflater.inflate(R.layout.dialog_update_passwords, null); visibility = false;//w ww . j a v a2s . c o m spinnerOld = (ProgressBar) rootView.findViewById(R.id.oldProgressBar); spinnerOld.setVisibility(View.GONE); spinnerNew = (ProgressBar) rootView.findViewById(R.id.newProgressBar); spinnerNew.setVisibility(View.GONE); Bundle bundle = getArguments(); position = bundle.getInt("position"); bindToDevice_enabled = bundle.getBoolean("bindToDevice_enabled"); hashAlgorithm = bundle.getString("hash_algorithm"); setOldMetaData(bundle); number_iterations = bundle.getInt("number_iterations"); database = MetaDataSQLiteHelper.getInstance(getActivity()); builder.setView(rootView); builder.setIcon(R.mipmap.ic_drawer); builder.setTitle(getActivity().getString(R.string.passwords_heading)); Button displayButton = (Button) rootView.findViewById(R.id.displayButton); displayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN); displayPasswords(); } }); ImageButton copyOldButton = (ImageButton) rootView.findViewById(R.id.copyOldButton); ImageButton copyNewButton = (ImageButton) rootView.findViewById(R.id.copyNewButton); copyOldButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { TextView oldPassword = (TextView) rootView.findViewById(R.id.textViewOldPassword); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("", oldPassword.getText()); clipboard.setPrimaryClip(clip); Toast.makeText(getActivity(), getActivity().getString(R.string.copy_clipboar_old), Toast.LENGTH_SHORT).show(); } }); copyNewButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { TextView newPassword = (TextView) rootView.findViewById(R.id.textViewNewPassword); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("", newPassword.getText()); clipboard.setPrimaryClip(clip); Toast.makeText(getActivity(), getActivity().getString(R.string.copy_clipboar_new), Toast.LENGTH_SHORT).show(); } }); builder.setPositiveButton(getActivity().getString(R.string.done), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { onClickDone(); } }); visibilityButton = (ImageButton) rootView.findViewById(R.id.visibilityButton); visibilityButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editTextUpdateMasterpassword = (EditText) rootView.findViewById(R.id.editTextUpdateMasterpassword); if (!visibility) { visibilityButton.setImageResource(R.drawable.ic_visibility_off); editTextUpdateMasterpassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); editTextUpdateMasterpassword.setSelection(editTextUpdateMasterpassword.getText().length()); visibility = true; } else { visibilityButton.setImageResource(R.drawable.ic_visibility); editTextUpdateMasterpassword .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); editTextUpdateMasterpassword.setSelection(editTextUpdateMasterpassword.getText().length()); visibility = false; } } }); return builder.create(); }
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;//from ww w. java 2 s . co 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:co.dilaver.quoter.fragments.FavoriteQuotesFragment.java
private void showAlertDialog(final int pos) { CharSequence[] items = { getString(R.string.str_Delete), getString(R.string.str_Share), getString(R.string.str_Copy) }; AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { //Delete SharedPrefStorage sharedPrefStorage = new SharedPrefStorage(getActivity()); Gson gson = new Gson(); for (int i = 0; i < MyApplication.savedQuotesList.size(); i++) { if (MyApplication.savedQuotesList.get(i).getQuoteAuthor() .equals(favoriteQuotesList.get(pos).getQuoteAuthor()) && MyApplication.savedQuotesList.get(i).getQuoteText() .equals(favoriteQuotesList.get(pos).getQuoteText())) { MyApplication.savedQuotesList.remove(i); favoriteQuotesList = MyApplication.savedQuotesList; sharedPrefStorage.setSavedQuotes(gson.toJson(MyApplication.savedQuotesList)); }/*from w ww . ja va 2 s . co m*/ } quotesAdapter.setList(favoriteQuotesList); quotesAdapter.notifyDataSetChanged(); } else if (item == 1) { Intent shareIntent = new Intent(getActivity(), ShareActivity.class); shareIntent.putExtra("quote", favoriteQuotesList.get(pos).getQuoteText()); shareIntent.putExtra("author", favoriteQuotesList.get(pos).getQuoteAuthor()); startActivity(shareIntent); } else if (item == 2) { ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Activity.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Copied Text", favoriteQuotesList.get(pos).getQuoteText() + " - " + favoriteQuotesList.get(pos).getQuoteAuthor()); clipboard.setPrimaryClip(clip); Snackbar.make(rootLayout, getString(R.string.str_QuoteCopied), Snackbar.LENGTH_SHORT).show(); } } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:com.jaspersoft.android.jaspermobile.widget.DraggableViewsContainer.java
private int addDraggableNote(float x, float y) { int viewId = getChildCount(); TextView textView = new TextView(getContext()); textView.setTextColor(mColor);//from w w w .j a v a2 s . c o m textView.setTextSize(10 + mSize * 2); textView.setX(x); textView.setY(y); textView.setId(viewId); textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showTextInputDialog(v.getId(), ((TextView) v).getText().toString()); } }); textView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { ClipData data = ClipData.newPlainText(String.valueOf(v.getId()), ""); View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v); v.startDrag(data, shadowBuilder, null, 0); return true; } }); addView(textView); return viewId; }
From source file:com.torygaurnier.openpalette.MainFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved_state) { view = inflater.inflate(R.layout.main_fragment, container, false); activity = (MainActivity) getActivity(); clipboard = (ClipboardManager) activity.getSystemService(activity.CLIPBOARD_SERVICE); /**//from w w w . ja va 2 s. c om * Setup Drawer for list of Palettes */ drawer_layout = (DrawerLayout) view.findViewById(R.id.rootDrawerLayout); drawer_toggle = new ActionBarDrawerToggle(activity, drawer_layout, R.drawable.ic_navigation_drawer, R.string.drawer_open, R.string.drawer_close) { // Called when drawer closes public void onDrawerClosed(View view) { super.onDrawerClosed(view); activity.refresh(); } // Called when drawer opens public void onDrawerOpened(View drawer_view) { super.onDrawerOpened(drawer_view); activity.refresh(); } }; drawer_layout.setDrawerListener(drawer_toggle); // Set onclick listeners for 'new palette' buttons view.findViewById(R.id.createFirstPaletteButton).setOnClickListener(new View.OnClickListener() { public void onClick(View view) { new EditPaletteDialog(activity).show(); } }); view.findViewById(R.id.newPaletteButton).setOnClickListener(new View.OnClickListener() { public void onClick(View view) { new EditPaletteDialog(activity).show(); } }); // Get palette list view by it's ID, setup PaletteList palette_list_view = (ListView) view.findViewById(R.id.paletteListView); palette_list = PaletteList.getInstance(); palette_list_view.setAdapter(palette_list.getAdapter()); // Set on click listener for palette list view palette_list_view.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapter_view, View view, int position, long id) { // User clicked a list item, select it palette_list.setSelectedPosition(position); } }); /** * Setup list view for current Palette */ // Get palette view by its ID palette_view = (DragSortListView) view.findViewById(R.id.paletteView); palette_view.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapter_view, View view, int position, long id) { String hex = ((HexColor) adapter_view.getItemAtPosition(position)).getHex(); ClipData clip = ClipData.newPlainText("hex", hex); clipboard.setPrimaryClip(clip); Msg.log(Msg.INFO, "palette_view->onItemClick()", hex + " copied to clipboard"); } }); // Register context menu for color actions registerForContextMenu(palette_view); activity.getActionBar().setDisplayHomeAsUpEnabled(true); activity.getActionBar().setHomeButtonEnabled(true); activity.refresh(); return view; }
From source file:com.coinblesk.client.TransactionDetailActivity.java
private void copyTx() { Log.d(TAG, "Copy Transaction Hash: " + transactionHash); Log.d(TAG, "Transaction Details:\n" + walletServiceBinder.getTransaction(transactionHash).toString()); ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Your TX", transactionHash); clipboard.setPrimaryClip(clip);//from ww w . j a va 2 s . co m View root = findViewById(android.R.id.content); if (root != null) { Snackbar.make(root, UIUtils.toFriendlySnackbarString(this, getString(R.string.snackbar_address_copied)), Snackbar.LENGTH_LONG).setActionTextColor(ContextCompat.getColor(this, R.color.colorAccent)) .setAction("Action", null).show(); } }
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 ww w . j av a 2s .c o 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); } }