List of usage examples for android.content Context CLIPBOARD_SERVICE
String CLIPBOARD_SERVICE
To view the source code for android.content Context CLIPBOARD_SERVICE.
Click Source Link
From source file:com.wellsandwhistles.android.redditsp.adapters.MainMenuListingManager.java
private void onSubredditActionMenuItemSelected(String subredditCanonicalName, AppCompatActivity activity, SubredditAction action) {//w ww .j av a2 s. co m try { final String url = "https://" + SubredditPostListURL.getSubreddit(subredditCanonicalName).humanReadableUrl(); RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager.getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount()); List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(mActivity, PreferenceManager.getDefaultSharedPreferences(mActivity)); List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(mActivity, PreferenceManager.getDefaultSharedPreferences(mActivity)); switch (action) { case SHARE: final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_TEXT, url); activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share))); break; case COPY_URL: ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); manager.setText(url); break; case EXTERNAL: final Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); activity.startActivity(intent); break; case PIN: if (!pinnedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_pinned_subreddits_add(mActivity, PreferenceManager.getDefaultSharedPreferences(mActivity), subredditCanonicalName); } else { Toast.makeText(mActivity, R.string.mainmenu_toast_subscribed, Toast.LENGTH_SHORT).show(); } break; case UNPIN: if (pinnedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_pinned_subreddits_remove(mActivity, PreferenceManager.getDefaultSharedPreferences(mActivity), subredditCanonicalName); } else { Toast.makeText(mActivity, R.string.mainmenu_toast_not_pinned, Toast.LENGTH_SHORT).show(); } break; case BLOCK: if (!blockedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_blocked_subreddits_add(mActivity, PreferenceManager.getDefaultSharedPreferences(mActivity), subredditCanonicalName); } else { Toast.makeText(mActivity, R.string.mainmenu_toast_blocked, Toast.LENGTH_SHORT).show(); } break; case UNBLOCK: if (blockedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_blocked_subreddits_remove(mActivity, PreferenceManager.getDefaultSharedPreferences(mActivity), subredditCanonicalName); } else { Toast.makeText(mActivity, R.string.mainmenu_toast_not_blocked, Toast.LENGTH_SHORT).show(); } break; case SUBSCRIBE: if (subMan.getSubscriptionState( subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.NOT_SUBSCRIBED) { subMan.subscribe(subredditCanonicalName, activity); setPinnedSubreddits(); setBlockedSubreddits(); Toast.makeText(mActivity, R.string.options_subscribing, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(mActivity, R.string.mainmenu_toast_subscribed, Toast.LENGTH_SHORT).show(); } break; case UNSUBSCRIBE: if (subMan.getSubscriptionState( subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.SUBSCRIBED) { subMan.unsubscribe(subredditCanonicalName, activity); setPinnedSubreddits(); setBlockedSubreddits(); Toast.makeText(mActivity, R.string.options_unsubscribing, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(mActivity, R.string.mainmenu_toast_not_subscribed, Toast.LENGTH_SHORT).show(); } break; } } catch (RedditSubreddit.InvalidSubredditNameException ex) { throw new RuntimeException(ex); } }
From source file:com.gmail.taneza.ronald.carbs.main.MainActivity.java
@SuppressWarnings("deprecation") private void copyMealTotalToClipboard() { String mealTotalValue = String.format(Locale.getDefault(), "%.1f", mTotalCarbsInGrams); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("Carbs meal total", mealTotalValue);//from w w w . j a va 2 s.com clipboard.setPrimaryClip(clip); } else { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); clipboard.setText(mealTotalValue); } String message = String.format(Locale.US, getResources().getString(R.string.meal_total_copied_to_clipboard), mealTotalValue); Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); }
From source file:onion.chat.MainActivity.java
@SuppressWarnings("StatementWithEmptyBody") @Override/*from ww w . jav a2s. c o m*/ public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.changealias) { changeName(); return true; } if (id == R.id.qr_show) { showQR(); return true; } if (id == R.id.qr_scan) { scanQR(); } if (id == R.id.share_id) { inviteFriend(); } if (id == R.id.password) { changePassword(); } if (id == R.id.copy_id) { ((android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE)).setText(tor.getID()); snack(getString(R.string.id_copied_to_clipboard) + tor.getID()); return true; } if (id == R.id.about) { showAbout(); } if (id == R.id.enter_id) { addContact(); } if (id == R.id.settings) { startActivity(new Intent(this, SettingsActivity.class)); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
From source file:de.baumann.browser.Browser_left.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); final WebView.HitTestResult result = mWebView.getHitTestResult(); final String url = result.getExtra(); if (result.getType() == WebView.HitTestResult.IMAGE_TYPE) { final CharSequence[] options = { getString(R.string.context_saveImage), getString(R.string.context_shareImage), getString(R.string.context_readLater), getString(R.string.context_right) }; new AlertDialog.Builder(Browser_left.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); }/* ww w. j a va 2s .co m*/ }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.context_saveImage))) { if (url != null) { try { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, helper_main.newFileName()); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName(), Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } } } if (options[item].equals(getString(R.string.context_shareImage))) { if (url != null) { shareString = helper_main.newFileName(); shareFile = helper_main.newFile(mWebView); try { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, shareString); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName(), Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } registerReceiver(onComplete2, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } } if (options[item].equals(getString(R.string.context_readLater))) { if (url != null) { if (Uri.parse(url).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(url).getHost(); } String domain2 = domain.substring(0, 1).toUpperCase() + domain.substring(1); DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_left.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(domain2, url, "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG) .show(); } } } if (options[item].equals(getString(R.string.context_right))) { if (url != null) { helper_main.switchToActivity(Browser_left.this, Browser_right.class, url, false); } } } }).show(); } else if (result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) { final CharSequence[] options = { getString(R.string.menu_share_link_copy), getString(R.string.menu_share_link), getString(R.string.context_readLater), getString(R.string.context_right) }; new AlertDialog.Builder(Browser_left.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_copy))) { if (url != null) { ClipboardManager clipboard = (ClipboardManager) Browser_left.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT) .show(); } } if (options[item].equals(getString(R.string.menu_share_link))) { if (url != null) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, url); sendIntent.setType("text/plain"); Browser_left.this.startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.app_share_link))); } } if (options[item].equals(getString(R.string.context_readLater))) { if (url != null) { if (Uri.parse(url).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(url).getHost(); } String domain2 = domain.substring(0, 1).toUpperCase() + domain.substring(1); DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_left.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(domain2, url, "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG) .show(); } } } if (options[item].equals(getString(R.string.context_right))) { if (url != null) { helper_main.switchToActivity(Browser_left.this, Browser_right.class, url, false); } } } }).show(); } }
From source file:com.amaze.filemanager.utils.files.FileUtils.java
public static boolean copyToClipboard(Context context, String text) { try {//w w w . j a v a2 s . c o m android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData .newPlainText(context.getString(R.string.clipboard_path_copy), text); clipboard.setPrimaryClip(clip); return true; } catch (Exception e) { return false; } }
From source file:org.lol.reddit.fragments.CommentListingFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); if (info.position <= 0) { return false; }/* w ww . j av a2 s .c om*/ final Object selectedObject = lv.getAdapter().getItem(info.position); if (!(selectedObject instanceof RedditCommentListItem) || !((RedditCommentListItem) selectedObject).isComment()) { return false; } final Action action = Action.values()[item.getItemId()]; final RedditPreparedComment comment = ((RedditCommentListItem) selectedObject).asComment(); switch (action) { case UPVOTE: comment.action(getSupportActivity(), RedditAPI.RedditAction.UPVOTE); break; case DOWNVOTE: comment.action(getSupportActivity(), RedditAPI.RedditAction.DOWNVOTE); break; case UNVOTE: comment.action(getSupportActivity(), RedditAPI.RedditAction.UNVOTE); break; case SAVE: comment.action(getSupportActivity(), RedditAPI.RedditAction.SAVE); break; case UNSAVE: comment.action(getSupportActivity(), RedditAPI.RedditAction.UNSAVE); break; case REPORT: new AlertDialog.Builder(getSupportActivity()).setTitle(R.string.action_report) .setMessage(R.string.action_report_sure) .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { comment.action(getSupportActivity(), RedditAPI.RedditAction.REPORT); } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case REPLY: { final Intent intent = new Intent(getSupportActivity(), CommentReplyActivity.class); intent.putExtra("parentIdAndType", comment.idAndType); startActivity(intent); break; } case EDIT: { final Intent intent = new Intent(getSupportActivity(), CommentEditActivity.class); intent.putExtra("commentIdAndType", comment.idAndType); intent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(comment.src.body)); startActivity(intent); break; } case COMMENT_LINKS: final HashSet<String> linksInComment = comment.computeAllLinks(); if (linksInComment.isEmpty()) { General.quickToast(getSupportActivity(), R.string.error_toast_no_urls_in_comment); } else { final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]); final AlertDialog.Builder builder = new AlertDialog.Builder(getSupportActivity()); builder.setItems(linksArr, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { LinkHandler.onLinkClicked(getSupportActivity(), linksArr[which], false); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_comment_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; case SHARE: final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comment by " + comment.src.author + " on Reddit"); // TODO this currently just dumps the markdown mailer.putExtra(Intent.EXTRA_TEXT, StringEscapeUtils.unescapeHtml4(comment.src.body)); startActivityForResult( Intent.createChooser(mailer, getSupportActivity().getString(R.string.action_share)), 1); break; case COPY: ClipboardManager manager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); // TODO this currently just dumps the markdown manager.setText(StringEscapeUtils.unescapeHtml4(comment.src.body)); break; case COLLAPSE: if (comment.getBoundView() != null) { handleCommentVisibilityToggle(comment.getBoundView()); } else { General.quickToast(getSupportActivity(), "Error: Comment is no longer visible."); } break; case USER_PROFILE: LinkHandler.onLinkClicked(getSupportActivity(), new UserProfileURL(comment.src.author).toString()); break; case PROPERTIES: CommentPropertiesDialog.newInstance(comment.src).show(getSupportActivity()); break; case GO_TO_COMMENT: { PostCommentListingURL url = new PostCommentListingURL(null, comment.src.link_id, comment.idAlone, null, null, null); LinkHandler.onLinkClicked(getSupportActivity(), url.toString()); break; } case CONTEXT: { PostCommentListingURL url = new PostCommentListingURL(null, comment.src.link_id, comment.idAlone, 3, null, null); LinkHandler.onLinkClicked(getSupportActivity(), url.toString()); break; } } return true; }
From source file:com.jungle.base.utils.MiscUtils.java
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB) public static void copyTextToClipboard(String data) { ClipboardManager clipboardManager = (ClipboardManager) AppCore.getApplicationContext() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("text", data); clipboardManager.setPrimaryClip(clipData); }
From source file:maimeng.yodian.app.client.android.chat.activity.ChatActivity.java
private void setUpView() { iv_emoticons_normal.setOnClickListener(this); // position = getIntent().getIntExtra("position", -1); clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo"); Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList(); if (robotMap != null && robotMap.containsKey(toChatUsername)) { isRobot = true;/* w w w .ja v a 2s.c o m*/ } // for chatroom type, we only init conversation and create view adapter on success onConversationInit(); onListViewCreation(); // show forward message if the message is not null String forward_msg_id = getIntent().getStringExtra("forward_msg_id"); if (forward_msg_id != null) { // ????? forwardMessage(forward_msg_id); } }
From source file:com.dwdesign.tweetings.fragment.StatusFragment.java
@SuppressLint({ "NewApi", "NewApi", "NewApi" }) @Override/*from w w w. ja v a2 s.c om*/ public boolean onMenuItemClick(final MenuItem item) { if (mStatus == null) return false; final String text_plain = mStatus.text_plain; final String screen_name = mStatus.screen_name; final String name = mStatus.name; switch (item.getItemId()) { case MENU_SHARE: { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "@" + mStatus.screen_name + ": " + text_plain); startActivity(Intent.createChooser(intent, getString(R.string.share))); break; } case MENU_RETWEET: { if (isMyRetweet(mStatus)) { mService.destroyStatus(mAccountId, mStatus.retweet_id); } else { final long id_to_retweet = mStatus.is_retweet && mStatus.retweet_id > 0 ? mStatus.retweet_id : mStatus.status_id; mService.retweetStatus(mAccountId, id_to_retweet); } break; } case MENU_TRANSLATE: { translate(mStatus); break; } case MENU_QUOTE_REPLY: { final Intent intent = new Intent(INTENT_ACTION_COMPOSE); final Bundle bundle = new Bundle(); bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId); bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, mStatusId); bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, screen_name); bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, name); bundle.putBoolean(INTENT_KEY_IS_QUOTE, true); bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), screen_name, text_plain)); intent.putExtras(bundle); startActivity(intent); break; } case MENU_QUOTE: { final Intent intent = new Intent(INTENT_ACTION_COMPOSE); final Bundle bundle = new Bundle(); bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId); bundle.putBoolean(INTENT_KEY_IS_QUOTE, true); bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), screen_name, text_plain)); intent.putExtras(bundle); startActivity(intent); break; } case MENU_ADD_TO_BUFFER: { final Intent intent = new Intent(INTENT_ACTION_COMPOSE); final Bundle bundle = new Bundle(); bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId); bundle.putBoolean(INTENT_KEY_IS_BUFFER, true); bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), screen_name, text_plain)); intent.putExtras(bundle); startActivity(intent); break; } case MENU_REPLY: { final Intent intent = new Intent(INTENT_ACTION_COMPOSE); final Bundle bundle = new Bundle(); final List<String> mentions = new Extractor().extractMentionedScreennames(text_plain); mentions.remove(screen_name); mentions.add(0, screen_name); bundle.putStringArray(INTENT_KEY_MENTIONS, mentions.toArray(new String[mentions.size()])); bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId); bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, mStatusId); bundle.putString(INTENT_KEY_IN_REPLY_TO_TWEET, text_plain); bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, screen_name); bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, name); intent.putExtras(bundle); startActivity(intent); break; } case MENU_FAV: { if (mStatus.is_favorite) { mService.destroyFavorite(mAccountId, mStatusId); } else { mService.createFavorite(mAccountId, mStatusId); } break; } case MENU_COPY_CLIPBOARD: { final String textToCopy = "@" + mStatus.screen_name + ": " + mStatus.text_plain; int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); clipboard.setText(textToCopy); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("Status", textToCopy); clipboard.setPrimaryClip(clip); } Toast.makeText(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT).show(); break; } case MENU_DELETE: { mService.destroyStatus(mAccountId, mStatusId); break; } case MENU_EXTENSIONS: { final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_STATUS); final Bundle extras = new Bundle(); extras.putParcelable(INTENT_KEY_STATUS, mStatus); intent.putExtras(extras); startActivity(Intent.createChooser(intent, getString(R.string.open_with_extensions))); break; } case MENU_MUTE_SOURCE: { final String source = HtmlEscapeHelper.unescape(mStatus.source); if (source == null) return false; final Uri uri = Filters.Sources.CONTENT_URI; final ContentValues values = new ContentValues(); final SharedPreferences.Editor editor = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE).edit(); final ContentResolver resolver = getContentResolver(); values.put(Filters.TEXT, source); resolver.delete(uri, Filters.TEXT + " = '" + source + "'", null); resolver.insert(uri, values); editor.putBoolean(PREFERENCE_KEY_ENABLE_FILTER, true).commit(); Toast.makeText(getActivity(), getString(R.string.source_muted, source), Toast.LENGTH_SHORT).show(); break; } case MENU_SET_COLOR: { final Intent intent = new Intent(INTENT_ACTION_SET_COLOR); startActivityForResult(intent, REQUEST_SET_COLOR); break; } case MENU_CLEAR_COLOR: { clearUserColor(getActivity(), mStatus.user_id); updateUserColor(); break; } case MENU_RECENT_TWEETS: { openUserTimeline(getActivity(), mAccountId, mStatus.user_id, mStatus.screen_name); break; } case MENU_FIND_RETWEETS: { openUserRetweetedStatus(getActivity(), mStatus.account_id, mStatus.retweet_id > 0 ? mStatus.retweet_id : mStatus.status_id); break; } default: return false; } return super.onOptionsItemSelected(item); }
From source file:com.forrestguice.suntimeswidget.LocationConfigView.java
public void copyLocationToClipboard(Context context, boolean silent) { WidgetSettings.Location location = getLocation(); String clipboardText = location.toString(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("lat, lon", clipboardText); clipboard.setPrimaryClip(clip);/*from w w w . j a va2s .c o m*/ } else { @SuppressWarnings("deprecation") android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(clipboardText); } if (!silent) { Toast copiedMsg = Toast.makeText(context, Html.fromHtml(context.getString(R.string.location_dialog_toast_copied, clipboardText)), Toast.LENGTH_LONG); copiedMsg.show(); } }