Example usage for android.widget ShareActionProvider ShareActionProvider

List of usage examples for android.widget ShareActionProvider ShareActionProvider

Introduction

In this page you can find the example usage for android.widget ShareActionProvider ShareActionProvider.

Prototype

public ShareActionProvider(Context context) 

Source Link

Document

Creates a new instance.

Usage

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 v  a2s .com
        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;//www  .java  2s  .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) {
                EasyTracker.getTracker().sendEvent("Session", "Shared", title, 0L);
                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 .com
            .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:ru.gkpromtech.exhibition.media.FullImageActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate menu resource file.
    getMenuInflater().inflate(R.menu.menu_fullscreen_image, menu);

    MenuItem itemSave = menu.findItem(R.id.menu_item_save);
    MenuItem shareItem = menu.findItem(R.id.menu_item_share);

    itemSave.setVisible(mode == SHOW_FILES_MODE ? false : true);

    // Fetch and store ShareActionProvider
    mShareActionProvider = (ShareActionProvider) shareItem.getActionProvider();
    if (mShareActionProvider == null) {
        // Following http://stackoverflow.com/questions/19358510/why-menuitemcompat-getactionprovider-returns-null
        mShareActionProvider = new ShareActionProvider(this);
    }/*ww w .  j a  v  a 2s.com*/

    final ViewPager pager = (ViewPager) findViewById(R.id.pager);
    int index = pager.getCurrentItem();
    Object mediaItem = getMediaItem(index);

    shareIntent = getShareIntent();
    setShareIntentMedia(shareIntent, mediaItem);
    setShareIntent(shareIntent);

    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            Object item = getMediaItem(position);
            setShareIntentMedia(shareIntent, item);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });

    return true;
}