List of usage examples for android.widget ShareActionProvider setOnShareTargetSelectedListener
public void setOnShareTargetSelectedListener(OnShareTargetSelectedListener listener)
From source file:com.github.jobs.ui.fragment.JobDetailsFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); Context themedContext = getActivity().getActionBar().getThemedContext(); ShareActionProvider shareActionProvider = new ShareActionProvider(themedContext); shareActionProvider .setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() { @Override/*from w ww . ja va 2 s .co m*/ public boolean onShareTargetSelected(ShareActionProvider shareActionProvider, Intent intent) { getTracker(getActivity()).trackEvent(CATEGORY_JOBS, ACTION_SHARE, intent.getComponent().getPackageName()); return false; } }); menu.add(0, SHARE, 0, R.string.share).setActionProvider(shareActionProvider) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); // Set file with share history to the provider and set the share intent. MenuItem actionItem = menu.findItem(SHARE); ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider(); actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME); actionProvider.setShareIntent(ShareHelper.getShareIntent(mJob)); }
From source file:ua.org.gdg.devfest.iosched.util.SessionsHelper.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void tryConfigureShareMenuItem(MenuItem menuItem, int messageTemplateResId, final String title, String hashtags, String url) { if (UIUtils.hasICS()) { ActionProvider itemProvider = menuItem.getActionProvider(); ShareActionProvider provider; if (!(itemProvider instanceof ShareActionProvider)) { provider = new ShareActionProvider(mActivity); } else {//from www.jav a2 s . c o m provider = (ShareActionProvider) itemProvider; } provider.setShareIntent(createShareIntent(messageTemplateResId, title, hashtags, url)); provider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() { @Override public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) { LOGD("Tracker", "Shared: " + title); return false; } }); menuItem.setActionProvider(provider); } }
From source file:com.gdgdevfest.android.apps.devfestbcn.util.SessionsHelper.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void tryConfigureShareMenuItem(MenuItem menuItem, int messageTemplateResId, final String title, String hashtags, String url) { if (UIUtils.hasICS()) { ActionProvider itemProvider = menuItem.getActionProvider(); ShareActionProvider provider; if (!(itemProvider instanceof ShareActionProvider)) { provider = new ShareActionProvider(mActivity); } else {/*from w w w. jav a 2 s.c om*/ provider = (ShareActionProvider) itemProvider; } provider.setShareIntent(createShareIntent(messageTemplateResId, title, hashtags, url)); provider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() { @Override public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) { EasyTracker.getTracker().sendEvent("Session", "Shared", title, 0L); LOGD("Tracker", "Shared: " + title); return false; } }); menuItem.setActionProvider(provider); } }
From source file:com.svpino.longhorn.fragments.StockListFragment.java
@TargetApi(14) @Override// w ww .jav a2 s. c o m public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragment_stock_list, menu); this.searchMenuItem = menu.findItem(R.id.menu_item_add); if (isIceCreamSandwichOrLater()) { SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); this.searchView = (SearchView) this.searchMenuItem.getActionView(); this.searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); this.searchView.setSubmitButtonEnabled(false); this.searchView.setIconifiedByDefault(true); final ShareActionProvider shareActionProvider = (ShareActionProvider) menu .findItem(R.id.menu_item_share).getActionProvider(); shareActionProvider.setShareIntent(getDefaultShareIntent(null)); shareActionProvider.setOnShareTargetSelectedListener(new OnShareTargetSelectedListener() { @Override public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) { Intent defaultShareIntent = getDefaultShareIntent(null); shareActionProvider.setShareIntent(defaultShareIntent); return false; } }); } super.onCreateOptionsMenu(menu, inflater); }