Example usage for android.view MenuItem setActionProvider

List of usage examples for android.view MenuItem setActionProvider

Introduction

In this page you can find the example usage for android.view MenuItem setActionProvider.

Prototype

public MenuItem setActionProvider(ActionProvider actionProvider);

Source Link

Document

Sets the ActionProvider responsible for creating an action view if the item is placed on the action bar.

Usage

From source file:com.esri.android.mapsapp.tools.MeasuringTool.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    mMode = mode;/*from   ww  w .  jav  a2  s  . c o  m*/
    init();
    MenuItem item;
    item = menu.add(Menu.NONE, MENU_UNDO, 1, "undo");
    item.setIcon(android.R.drawable.ic_menu_revert);
    item.setVisible(false);

    item = menu.add(Menu.NONE, MENU_DELETE, 2, "clear");
    item.setIcon(android.R.drawable.ic_menu_delete);
    item.setVisible(false);

    item = menu.add(Menu.NONE, MENU_PREF, 3, "preferences");
    item.setIcon(android.R.drawable.ic_menu_manage);
    item.setActionProvider(new Preferences(mContext));
    return true;
}

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;/*from  w  w w.j a va2 s . c  o 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.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;//ww w  . jav  a2  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);
    }
}