List of usage examples for android.view MenuItem getActionProvider
public ActionProvider getActionProvider();
From source file:com.chale22.ico01.ThemeActivity.java
public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.share_menu, menu); MenuItem item = menu.findItem(R.id.menu_item_share); mShareActionProvider = (ShareActionProvider) item.getActionProvider(); // Create the share Intent String playStoreLink = " https://play.google.com/store/apps/details?id=" + getPackageName(); String yourShareText = getString(R.string.share_this) + playStoreLink; Intent shareIntent = ShareCompat.IntentBuilder.from(this).setType("text/plain").setText(yourShareText) .getIntent();/* w w w .j a v a 2s . com*/ // Set the share Intent mShareActionProvider.setShareIntent(shareIntent); return true; }
From source file:com.chale22.ico01.IconActivity.java
public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.share_menu, menu); MenuItem item = menu.findItem(R.id.menu_item_share); mShareActionProvider = (ShareActionProvider) item.getActionProvider(); // Create the share Intent String playStoreLink = "https://play.google.com/store/apps/details?id=" + getPackageName(); String yourShareText = getString(R.string.share_this) + playStoreLink; Intent shareIntent = ShareCompat.IntentBuilder.from(this).setType("text/plain").setText(yourShareText) .getIntent();/* www .j a va 2s . c o m*/ // Set the share Intent mShareActionProvider.setShareIntent(shareIntent); return true; }
From source file:com.github.riotopsys.shoppinglist.fragment.ShoppingListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.shopping_list_fragment, menu); MenuItem item = menu.findItem(R.id.menu_share); ShareActionProvider shareActionProvider = (ShareActionProvider) item.getActionProvider(); IConfigurations confs = new Configurations(); Intent shareIntent = new Intent(Intent.ACTION_SEND); try {/* w w w. j ava 2 s . co m*/ shareIntent.putExtra(Intent.EXTRA_TEXT, String.format("%s%s", confs.shareUrlBase(), mList.getGuid().toString())); } catch (MalformedURLException e) { throw new RuntimeException(e); } shareIntent.setType("text/plain"); shareActionProvider.setShareIntent(shareIntent); super.onCreateOptionsMenu(menu, inflater); }
From source file:com.zephyrteam.costituzione.DetailedActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.actionbar_details, menu); if (list == null) return false; mEntry = list.get(vp.getCurrentItem()); updateFavoriteButton(menu.findItem(R.id.favourite_status)); MenuItem shareItem = menu.findItem(R.id.menu_item_share); mShareProvider = (ShareActionProvider) shareItem.getActionProvider(); mShareProvider.setShareIntent(getShareIntent()); return true;// ww w.j a va 2 s . c om }
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;/* www . jav a2 s. co m*/ if (!(itemProvider instanceof ShareActionProvider)) { provider = new ShareActionProvider(mActivity); } else { 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.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//from w w w . j a v a2 s . c om .setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() { @Override 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: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;/*from w ww .ja va2 s . c om*/ if (!(itemProvider instanceof ShareActionProvider)) { provider = new ShareActionProvider(mActivity); } else { 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.gnufabio.costituzione.DetailedActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.actionbar_details, menu); MenuItem shareItem = menu.findItem(R.id.menu_item_share); mShareProvider = (ShareActionProvider) shareItem.getActionProvider(); if (list == null || listNotes == null) return false; mEntry = list.get(vp.getCurrentItem()); mShareProvider.setShareIntent(getShareIntent()); mNote = listNotes.get(vp.getCurrentItem()); updateFavoriteButton(menu.findItem(R.id.favourite_status)); return true;//from w ww . ja v a 2 s . c o m }
From source file:com.jackie.appbar.MainActivity.java
/** * Initialize the contents of the Activity's standard options menu. You * should place your menu items in to <var>menu</var>. * <p/>/*www. j a v a2s . c o m*/ * <p>This is only called once, the first time the options menu is * displayed. To update the menu every time it is displayed, see * {@link #onPrepareOptionsMenu}. * <p/> * <p>The default implementation populates the menu with standard system * menu items. These are placed in the {@link Menu#CATEGORY_SYSTEM} group so that * they will be correctly ordered with application-defined menu items. * Deriving classes should always call through to the base implementation. * <p/> * <p>You can safely hold on to <var>menu</var> (and any items created * from it), making modifications to it as desired, until the next * time onCreateOptionsMenu() is called. * <p/> * <p>When you add items to the menu, you can implement the Activity's * {@link #onOptionsItemSelected} method to handle them there. * * @param menu The options menu in which you place your items. * @return You must return true for the menu to be displayed; * if you return false it will not be shown. * @see #onPrepareOptionsMenu * @see #onOptionsItemSelected */ @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate menu resource file getMenuInflater().inflate(R.menu.sample_actions, menu); Log.i(TAG, "onOptionsItemSelected: click share"); Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send"); sendIntent.setType("text/plain"); MenuItem item = menu.findItem(R.id.action_share); if (SDKUtils.IS_ICE_CREAM_SANDWICH) { android.widget.ShareActionProvider shareActionProvider = (android.widget.ShareActionProvider) item .getActionProvider(); shareActionProvider.setShareIntent(sendIntent); } else { ShareActionProvider shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item); shareActionProvider.setShareIntent(sendIntent); } // Return true to display menu return true; }
From source file:com.darizotas.metadatastrip.FileDetailFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.detail_menu, menu); // Gets the share action provider and initializes it. // http://developer.android.com/training/sharing/shareaction.html MenuItem item = menu.findItem(R.id.share); ShareActionProvider provider = (ShareActionProvider) item.getActionProvider(); if (provider != null && mFileMetadata != null) { provider.setShareIntent(getShareIntent(mFileMetadata)); }//w w w . j a v a2 s . c o m }