Example usage for android.widget ShareActionProvider setShareIntent

List of usage examples for android.widget ShareActionProvider setShareIntent

Introduction

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

Prototype

public void setShareIntent(Intent shareIntent) 

Source Link

Document

Sets an intent with information about the share action.

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;
        if (!(itemProvider instanceof ShareActionProvider)) {
            provider = new ShareActionProvider(mActivity);
        } else {// w ww .j  a  v  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) {
                LOGD("Tracker", "Shared: " + title);
                return false;
            }
        });

        menuItem.setActionProvider(provider);
    }
}

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));
    }/*from www . ja v a  2s . c o m*/
}

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 av a  2 s  .co m*/
            .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;
        if (!(itemProvider instanceof ShareActionProvider)) {
            provider = new ShareActionProvider(mActivity);
        } else {/*  www.java2  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) {
                EasyTracker.getTracker().sendEvent("Session", "Shared", title, 0L);
                LOGD("Tracker", "Shared: " + title);
                return false;
            }
        });

        menuItem.setActionProvider(provider);
    }
}

From source file:com.deliciousdroid.fragment.ViewBookmarkFragment.java

@Override
@TargetApi(14)//from   w w w  .  j a  v a2  s  .  c o m
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.view_menu, menu);

    if (android.os.Build.VERSION.SDK_INT >= 14) {
        Log.d("bookmark", Boolean.toString(bookmark == null));
        if (bookmark != null) {
            if (isMyself() && bookmark.getId() != 0) {
                try {
                    int id = bookmark.getId();
                    bookmark = BookmarkManager.GetById(id, base);

                    ShareActionProvider shareActionProvider = (ShareActionProvider) menu
                            .findItem(R.id.menu_view_sendbookmark).getActionProvider();
                    shareActionProvider.setShareIntent(
                            IntentHelper.SendBookmark(bookmark.getUrl(), bookmark.getDescription()));
                } catch (ContentNotFoundException e) {
                }
            }
        }
    }
}

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 {//  ww w.ja  v  a2s  . c om
        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:pl.bcichecki.rms.client.android.fragments.DevicesListFragment.java

private void performActionShare(final ActionMode mode, MenuItem item, final Device selectedDevice) {
    ShareActionProvider shareActionProvider = (ShareActionProvider) item.getActionProvider();
    if (shareActionProvider != null) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType(AppConstants.CONTENT_TEXT_PLAIN);
        intent.putExtra(Intent.EXTRA_TEXT,
                new DeviceTextPrettyPrinterPrinter(getActivity()).print(selectedDevice));
        shareActionProvider.setShareHistoryFileName(null);
        shareActionProvider.setShareIntent(intent);

        Log.d(TAG, "Device " + selectedDevice + " was succesfully shared.");
    }//from   w  w  w.  j a v  a2s.co m
}

From source file:com.joravasal.comicagg.ComicDetailFragment.java

@TargetApi(14)
@Override//  www . ja  v a  2s.c  om
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    Log.d(TAG, "OnCreateOptionsMenu");
    inflater.inflate(R.menu.comic_selected_extra, menu);
    // if (!((ComicListActivity) getActivity()).showUnread)
    // menu.findItem(R.id.menu_show_all).setTitle(
    // R.string.menu_show_unread);

    ShareActionProvider mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_share)
            .getActionProvider();

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    // Uri uri = Uri.parse(comicItem.url);
    shareIntent.putExtra(Intent.EXTRA_STREAM, comicItem.url);
    mShareActionProvider.setShareIntent(shareIntent);
}

From source file:pl.bcichecki.rms.client.android.fragments.EventsListFragment.java

private void performActionShare(ActionMode mode, MenuItem item, Event selectedEvent) {
    ShareActionProvider shareActionProvider = (ShareActionProvider) item.getActionProvider();
    if (shareActionProvider != null) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType(AppConstants.CONTENT_TEXT_PLAIN);
        intent.putExtra(android.content.Intent.EXTRA_TEXT,
                new EventTextPrettyPrinter(getActivity()).print(selectedEvent));
        shareActionProvider.setShareHistoryFileName(null);
        shareActionProvider.setShareIntent(intent);

        Log.d(TAG, "Event " + selectedEvent + " was succesfully shared.");
    }/*ww w .j a  va  2s .c o m*/
}

From source file:com.svpino.longhorn.fragments.StockListFragment.java

@TargetApi(14)
@Override//from  w ww .  j  a  v a2s . com
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);
}