List of usage examples for android.content ClipData newPlainText
static public ClipData newPlainText(CharSequence label, CharSequence text)
From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvShareFragment.java
private void shareFingerprint(boolean toClipboard) { Activity activity = getActivity();/* w ww .j a v a 2 s . com*/ if (activity == null || mFingerprint == null) { return; } String content; String fingerprint = KeyFormattingUtils.convertFingerprintToHex(mFingerprint); if (!toClipboard) { content = Constants.FINGERPRINT_SCHEME + ":" + fingerprint; } else { content = fingerprint; } if (toClipboard) { ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); if (clipMan == null) { Notify.create(activity, R.string.error_clipboard_copy, Style.ERROR); return; } ClipData clip = ClipData.newPlainText(Constants.CLIPBOARD_LABEL, content); clipMan.setPrimaryClip(clip); Notify.create(activity, R.string.fingerprint_copied_to_clipboard, Notify.Style.OK).show(); return; } // let user choose application Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, content); sendIntent.setType("text/plain"); String title = getString(R.string.title_share_fingerprint_with); Intent shareChooser = Intent.createChooser(sendIntent, title); startActivity(shareChooser); }
From source file:de.baumann.browser.popups.Popup_readLater.java
private void setReadLaterList() { //display data final int layoutstyle = R.layout.list_item; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "readLater_title", "readLater_content", "readLater_creation" }; final Cursor row = db.fetchAllData(this); adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0); //display data by filter final String note_search = sharedPref.getString("filter_readLaterBY", "readLater_title"); sharedPref.edit().putString("filter_readLaterBY", "readLater_title").apply(); editText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { }/*from ww w. j a v a2s .co m*/ public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); listView.setAdapter(adapter); //onClick function listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row = (Cursor) listView.getItemAtPosition(position); final String readLater_content = row.getString(row.getColumnIndexOrThrow("readLater_content")); sharedPref.edit().putString("openURL", readLater_content).apply(); finish(); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String readLater_title = row2.getString(row2.getColumnIndexOrThrow("readLater_title")); final String readLater_content = row2.getString(row2.getColumnIndexOrThrow("readLater_content")); final String readLater_icon = row2.getString(row2.getColumnIndexOrThrow("readLater_icon")); final String readLater_attachment = row2 .getString(row2.getColumnIndexOrThrow("readLater_attachment")); final String readLater_creation = row2.getString(row2.getColumnIndexOrThrow("readLater_creation")); final CharSequence[] options = { getString(R.string.menu_share), getString(R.string.menu_save), getString(R.string.bookmark_edit_title), getString(R.string.bookmark_remove_bookmark) }; new AlertDialog.Builder(Popup_readLater.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.bookmark_edit_title))) { sharedPref.edit().putString("edit_id", _id).apply(); sharedPref.edit().putString("edit_content", readLater_content).apply(); sharedPref.edit().putString("edit_icon", readLater_icon).apply(); sharedPref.edit().putString("edit_attachment", readLater_attachment).apply(); sharedPref.edit().putString("edit_creation", readLater_creation).apply(); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Popup_readLater.this, editText, 2, readLater_title, getString(R.string.bookmark_edit_title)); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(listView, R.string.bookmark_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.delete(Integer.parseInt(_id)); setReadLaterList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.menu_share))) { final CharSequence[] options = { getString(R.string.menu_share_link), getString(R.string.menu_share_link_copy) }; new AlertDialog.Builder(Popup_readLater.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_share_link))) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, readLater_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, readLater_content); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link)))); } if (options[item] .equals(getString(R.string.menu_share_link_copy))) { ClipboardManager clipboard = (ClipboardManager) Popup_readLater.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip( ClipData.newPlainText("text", readLater_content)); Snackbar.make(listView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show(); } } }).show(); } if (options[item].equals(getString(R.string.menu_save))) { final CharSequence[] options = { getString(R.string.menu_save_bookmark), getString(R.string.menu_save_pass), getString(R.string.menu_createShortcut) }; new AlertDialog.Builder(Popup_readLater.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_save_pass))) { helper_editText.editText_savePass(Popup_readLater.this, listView, readLater_title, readLater_content); } if (options[item] .equals(getString(R.string.menu_save_bookmark))) { DbAdapter_Bookmarks db = new DbAdapter_Bookmarks( Popup_readLater.this); db.open(); if (db.isExist(readLater_content)) { Snackbar.make(listView, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(readLater_title, readLater_content, "", "", helper_main.createDate()); Snackbar.make(listView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } if (options[item] .equals(getString(R.string.menu_createShortcut))) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setClassName(Popup_readLater.this, "de.baumann.browser.Browser_left"); i.setData(Uri.parse(readLater_content)); Intent shortcut = new Intent(); shortcut.putExtra("android.intent.extra.shortcut.INTENT", i); shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, readLater_content); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext( Popup_readLater.this .getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction( "com.android.launcher.action.INSTALL_SHORTCUT"); Popup_readLater.this.sendBroadcast(shortcut); Snackbar.make(listView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show(); } } }).show(); } } }).show(); return true; } }); listView.post(new Runnable() { public void run() { listView.setSelection(listView.getCount() - 1); } }); }
From source file:de.msal.shoutemo.fragments.ChatFragment.java
@Override public void onItemLongClicked(int position, final Post post) { DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { @Override//from w w w. ja va 2 s . c o m public void onClick(DialogInterface dialog, int which) { @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("d. MMM, HH:mm", Locale.ENGLISH); String shareString = getString(R.string.clipboard_post, sdf.format(post.getDate()), post.getAuthor(), post.getMessage().getText()); switch (which) { case DialogInterface.BUTTON_NEGATIVE: break; case 0: // clipboard ClipData clip = ClipData.newPlainText(shareString, shareString); ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(clip); Toast.makeText(getActivity(), R.string.dialog_copied, Toast.LENGTH_SHORT).show(); break; case 1: // share Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_TEXT, shareString); startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_title))); break; case 2: // user profile String url = "http://www.autemo.com/profiles/?id="; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url + post.getAuthor())); startActivity(i); break; } } }; AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); @SuppressWarnings("unchecked") final Pair<String, Integer>[] items = new Pair[] { new Pair<>(getString(R.string.dialog_post_clipboard), R.drawable.ic_content_copy_white_24dp), new Pair<>(getString(R.string.dialog_post_share), R.drawable.ic_share_white_24dp), new Pair<>( getString(R.string.dialog_post_user, post.getAuthor()), R.drawable.ic_person_white_24dp) }; builder.setAdapter(new ArrayAdapter<Pair<String, Integer>>(getActivity(), R.layout.row_dialog_listitem, R.id.text, items) { public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); // text TextView tv = (TextView) v.findViewById(R.id.text); tv.setText(items[position].first); // icon ImageView iv = (ImageView) v.findViewById(R.id.icon); iv.setImageResource(items[position].second); return v; } }, listener).setNegativeButton(android.R.string.cancel, listener); AlertDialog dialog = builder.create(); dialog.show(); }
From source file:com.technoxist.fragment.EntryFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mEntriesIds != null) { Activity activity = getActivity(); switch (item.getItemId()) { case R.id.menu_star: { mFavorite = !mFavorite;//from w w w. j ava 2 s. c o m if (mFavorite) { item.setIcon(R.drawable.rating_important); } else { item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important); } final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentValues values = new ContentValues(); values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0); ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, values, null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }.start(); break; } case R.id.menu_share: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); String link = cursor.getString(mLinkPos); if (link != null) { String title = cursor.getString(mTitlePos); startActivity(Intent.createChooser( new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title) .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN), getString(R.string.menu_share))); } break; } case R.id.menu_full_screen: { setImmersiveFullScreen(true); break; } case R.id.menu_copy_clipboard: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); String link = cursor.getString(mLinkPos); ClipboardManager clipboard = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Copied Text", link); clipboard.setPrimaryClip(clip); Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show(); break; } case R.id.menu_mark_as_unread: { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, FeedData.getUnreadContentValues(), null, null); } }.start(); activity.finish(); break; } } } return true; }
From source file:layout.FragmentBoardItemList.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); if (info.targetView.getParent() == listViewBoardItems) { BoardItem bi = boardItems.get(info.position); switch (item.getItemId()) { case R.id.menu_copy: System.out.println("Post copiado"); ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); ClipData cd = ClipData.newPlainText("Reply", boardItems.get(info.position).getMessage()); cm.setPrimaryClip(cd);/*from w w w. ja v a2 s . co m*/ break; case R.id.menu_reply: Intent in = new Intent(getActivity().getApplicationContext(), ResponseActivity.class); Bundle b = new Bundle(); b.putParcelable("theReply", boardItems.get(info.position)); b.putBoolean("quoting", true); in.putExtras(b); getActivity().startActivity(in); break; case R.id.menu_savereply: try { File txt = new File(Environment.getExternalStorageDirectory().getPath() + "/Bai/" + bi.getParentBoard().getBoardDir() + "_" + bi.getId() + ".txt"); FileOutputStream stream = new FileOutputStream(txt); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(stream); outputStreamWriter.write(bi.getMessage()); outputStreamWriter.close(); stream.close(); Toast.makeText(getContext(), bi.getParentBoard().getBoardDir() + "_" + bi.getId() + ".txt guardado.", Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } break; case R.id.menu_delpost: deletePost(false, bi); break; case R.id.menu_delimage: deletePost(true, bi); break; } } return super.onContextItemSelected(item); }
From source file:com.z299studio.pb.EditFragment.java
@Override public boolean onLongClick(View v) { ClipData not_used_clip = ClipData.newPlainText("", ""); v.startDrag(not_used_clip, new View.DragShadowBuilder(v), v, 0); // DragEvent.ACTION_DRAG_STARTED not called in drag event dispatch. // Handle it here. mDragListener.startDrag(v);/*from w ww . j a v a 2s . c o m*/ return true; }
From source file:com.android.talkback.SpeechController.java
/** * Copies the last phrase spoken by TalkBack to clipboard *//*from ww w. j a v a2 s. c o m*/ public boolean copyLastUtteranceToClipboard(FeedbackItem item) { if (item == null) { return false; } final ClipboardManager clipboard = (ClipboardManager) mService.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(null, item.getAggregateText()); clipboard.setPrimaryClip(clip); // Verify that we actually have the utterance on the clipboard clip = clipboard.getPrimaryClip(); if (clip != null && clip.getItemCount() > 0 && clip.getItemAt(0).getText() != null) { speak(mService.getString(R.string.template_text_copied, clip.getItemAt(0).getText().toString()) /* text */, QUEUE_MODE_INTERRUPT /* queue mode */, 0 /* flags */, null /* speech params */); return true; } else { return false; } }
From source file:info.papdt.blacklight.support.Utility.java
public static void copyToClipboard(Context context, String data) { ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData cd = ClipData.newPlainText("msg", data); cm.setPrimaryClip(cd);// ww w .j a v a 2 s .c om // Inform the user Toast.makeText(context, R.string.copied, Toast.LENGTH_SHORT).show(); }
From source file:com.app.uafeed.fragment.EntryFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mEntriesIds != null) { Activity activity = getActivity(); switch (item.getItemId()) { case R.id.menu_star: { mFavorite = !mFavorite;/*from w ww .ja v a 2 s . c o m*/ if (mFavorite) { item.setTitle(R.string.menu_unstar).setIcon(R.drawable.rating_important); } else { item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important); } final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentValues values = new ContentValues(); values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0); ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, values, null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }.start(); break; } case R.id.menu_share: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); String link = cursor.getString(mLinkPos); if (link != null) { String title = cursor.getString(mTitlePos); startActivity(Intent.createChooser( new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title) .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN), getString(R.string.menu_share))); } break; } case R.id.menu_full_screen: { toggleFullScreen(); break; } case R.id.menu_copy_clipboard: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); String link = cursor.getString(mLinkPos); ClipboardManager clipboard = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Copied Text", link); clipboard.setPrimaryClip(clip); Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show(); break; } case R.id.menu_mark_as_unread: { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, FeedData.getUnreadContentValues(), null, null); } }.start(); activity.finish(); break; } } } return true; }
From source file:de.baumann.browser.popups.Popup_bookmarks.java
private void setBookmarksList() { //display data final int layoutstyle = R.layout.list_item; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "bookmarks_title", "bookmarks_content", "bookmarks_creation" }; final Cursor row = db.fetchAllData(this); adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0) { @Override/* www . j a v a 2 s.co m*/ public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String bookmarks_title = row2.getString(row2.getColumnIndexOrThrow("bookmarks_title")); final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content")); final String bookmarks_icon = row2.getString(row2.getColumnIndexOrThrow("bookmarks_icon")); final String bookmarks_attachment = row2 .getString(row2.getColumnIndexOrThrow("bookmarks_attachment")); final String bookmarks_creation = row2.getString(row2.getColumnIndexOrThrow("bookmarks_creation")); View v = super.getView(position, convertView, parent); final ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes); switch (bookmarks_attachment) { case "": iv_attachment.setVisibility(View.VISIBLE); iv_attachment.setImageResource(R.drawable.star_outline); break; default: iv_attachment.setVisibility(View.VISIBLE); iv_attachment.setImageResource(R.drawable.star_grey); break; } iv_attachment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (bookmarks_attachment.equals("")) { if (db.isExistFav("true")) { Snackbar.make(listView, R.string.bookmark_setFav_not, Snackbar.LENGTH_LONG).show(); } else { iv_attachment.setImageResource(R.drawable.star_grey); db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon, "true", bookmarks_creation); setBookmarksList(); sharedPref.edit().putString("startURL", bookmarks_content).apply(); Snackbar.make(listView, R.string.bookmark_setFav, Snackbar.LENGTH_LONG).show(); } } else { iv_attachment.setImageResource(R.drawable.star_outline); db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon, "", bookmarks_creation); setBookmarksList(); } } }); return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_bookmarksBY", "bookmarks_title"); sharedPref.edit().putString("filter_bookmarksBY", "bookmarks_title").apply(); editText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); listView.setAdapter(adapter); //onClick function listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row = (Cursor) listView.getItemAtPosition(position); final String bookmarks_content = row.getString(row.getColumnIndexOrThrow("bookmarks_content")); sharedPref.edit().putString("openURL", bookmarks_content).apply(); finish(); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String bookmarks_title = row2.getString(row2.getColumnIndexOrThrow("bookmarks_title")); final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content")); final String bookmarks_icon = row2.getString(row2.getColumnIndexOrThrow("bookmarks_icon")); final String bookmarks_attachment = row2 .getString(row2.getColumnIndexOrThrow("bookmarks_attachment")); final String bookmarks_creation = row2.getString(row2.getColumnIndexOrThrow("bookmarks_creation")); final CharSequence[] options = { getString(R.string.menu_share), getString(R.string.menu_save), getString(R.string.bookmark_edit_title), getString(R.string.bookmark_remove_bookmark) }; new AlertDialog.Builder(Popup_bookmarks.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.bookmark_edit_title))) { sharedPref.edit().putString("edit_id", _id).apply(); sharedPref.edit().putString("edit_content", bookmarks_content).apply(); sharedPref.edit().putString("edit_icon", bookmarks_icon).apply(); sharedPref.edit().putString("edit_attachment", bookmarks_attachment).apply(); sharedPref.edit().putString("edit_creation", bookmarks_creation).apply(); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Popup_bookmarks.this, editText, 2, bookmarks_title, getString(R.string.bookmark_edit_title)); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(listView, R.string.bookmark_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.delete(Integer.parseInt(_id)); setBookmarksList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.menu_share))) { final CharSequence[] options = { getString(R.string.menu_share_link), getString(R.string.menu_share_link_copy) }; new AlertDialog.Builder(Popup_bookmarks.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_share_link))) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, bookmarks_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, bookmarks_content); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link)))); } if (options[item] .equals(getString(R.string.menu_share_link_copy))) { ClipboardManager clipboard = (ClipboardManager) Popup_bookmarks.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip( ClipData.newPlainText("text", bookmarks_content)); Snackbar.make(listView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show(); } } }).show(); } if (options[item].equals(getString(R.string.menu_save))) { final CharSequence[] options = { getString(R.string.menu_save_readLater), getString(R.string.menu_save_pass), getString(R.string.menu_createShortcut) }; new AlertDialog.Builder(Popup_bookmarks.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_save_pass))) { helper_editText.editText_savePass(Popup_bookmarks.this, listView, bookmarks_title, bookmarks_content); } if (options[item] .equals(getString(R.string.menu_save_readLater))) { DbAdapter_ReadLater db = new DbAdapter_ReadLater( Popup_bookmarks.this); db.open(); if (db.isExist(bookmarks_content)) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(bookmarks_title, bookmarks_content, "", "", helper_main.createDate()); Snackbar.make(listView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } if (options[item] .equals(getString(R.string.menu_createShortcut))) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setClassName(Popup_bookmarks.this, "de.baumann.browser.Browser_left"); i.setData(Uri.parse(bookmarks_content)); Intent shortcut = new Intent(); shortcut.putExtra("android.intent.extra.shortcut.INTENT", i); shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, bookmarks_title); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext( Popup_bookmarks.this .getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction( "com.android.launcher.action.INSTALL_SHORTCUT"); Popup_bookmarks.this.sendBroadcast(shortcut); Snackbar.make(listView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show(); } } }).show(); } } }).show(); return true; } }); }