Search in sources :

Example 6 with ShareActionProvider

use of android.support.v7.widget.ShareActionProvider in project AisenWeiBo by wangdan.

the class AisenUtils method setStatusShareMenu.

public static void setStatusShareMenu(MenuItem shareItem, StatusContent status) {
    String url = null;
    if (status.getPic_urls() != null && status.getPic_urls().length > 0) {
        url = status.getPic_urls()[0].getThumbnail_pic();
    } else if (!TextUtils.isEmpty(status.getThumbnail_pic())) {
        url = status.getThumbnail_pic();
    }
    if (!TextUtils.isEmpty(url)) {
        File file = BitmapLoader.getInstance().getCacheFile(url.replace("thumbnail", "large"));
        if (file.exists()) {
            url = url.replace("thumbnail", "large");
        } else {
            file = BitmapLoader.getInstance().getCacheFile(url.replace("thumbnail", "bmiddle"));
            if (file.exists()) {
                url = url.replace("thumbnail", "bmiddle");
            }
        }
    }
    Intent shareIntent = Utils.getShareIntent(status.getText(), status.getText(), url);
    ShareActionProvider shareProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
    shareProvider.setShareHistoryFileName("channe_share.xml");
    shareProvider.setShareIntent(shareIntent);
}
Also used : Intent(android.content.Intent) ShareActionProvider(android.support.v7.widget.ShareActionProvider) File(java.io.File)

Example 7 with ShareActionProvider

use of android.support.v7.widget.ShareActionProvider in project wh-app-android by WhiteHouse.

the class VideoPlayerFragment method configureOverflow.

private void configureOverflow(boolean favorited) {
    MenuItem favoriteItem, unfavoriteItem, shareItem;
    ShareActionProvider shareAction;
    Intent shareIntent;
    favoriteItem = mMenu.findItem(R.id.action_favorite);
    unfavoriteItem = mMenu.findItem(R.id.action_unfavorite);
    shareItem = mMenu.findItem(R.id.action_share);
    if (favoriteItem == null || unfavoriteItem == null || shareItem == null) {
        return;
    }
    favoriteItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    favoriteItem.setVisible(!favorited);
    unfavoriteItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    unfavoriteItem.setVisible(favorited);
    shareAction = ((ShareActionProvider) MenuItemCompat.getActionProvider(shareItem));
    shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, mFeedItem.title());
    shareIntent.putExtra(Intent.EXTRA_TEXT, mFeedItem.link());
    shareIntent.setType("text/plain");
    shareAction.setShareIntent(shareIntent);
}
Also used : MenuItem(android.view.MenuItem) Intent(android.content.Intent) ShareActionProvider(android.support.v7.widget.ShareActionProvider)

Example 8 with ShareActionProvider

use of android.support.v7.widget.ShareActionProvider in project apps-android-commons by commons-app.

the class MediaDetailPagerFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (!editable) {
        // Disable menu options for editable views
        // see http://stackoverflow.com/a/8495697/17865
        menu.clear();
        inflater.inflate(R.menu.fragment_image_detail, menu);
        if (pager != null) {
            MediaDetailProvider provider = (MediaDetailProvider) getActivity();
            Media m = provider.getMediaAtPosition(pager.getCurrentItem());
            if (m != null) {
                // Enable default set of actions, then re-enable different set of actions only if it is a failed contrib
                menu.findItem(R.id.menu_retry_current_image).setEnabled(false).setVisible(false);
                menu.findItem(R.id.menu_cancel_current_image).setEnabled(false).setVisible(false);
                menu.findItem(R.id.menu_browser_current_image).setEnabled(true).setVisible(true);
                menu.findItem(R.id.menu_share_current_image).setEnabled(true).setVisible(true);
                menu.findItem(R.id.menu_download_current_image).setEnabled(true).setVisible(true);
                // Set ShareActionProvider Intent
                ShareActionProvider mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menu.findItem(R.id.menu_share_current_image));
                // https://github.com/commons-app/apps-android-commons/issues/413
                if (mShareActionProvider != null) {
                    Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(Intent.EXTRA_TEXT, m.getDisplayTitle() + " \n" + m.getDescriptionUrl());
                    mShareActionProvider.setShareIntent(shareIntent);
                }
                if (m instanceof Contribution) {
                    Contribution c = (Contribution) m;
                    switch(c.getState()) {
                        case Contribution.STATE_FAILED:
                            menu.findItem(R.id.menu_retry_current_image).setEnabled(true).setVisible(true);
                            menu.findItem(R.id.menu_cancel_current_image).setEnabled(true).setVisible(true);
                            menu.findItem(R.id.menu_browser_current_image).setEnabled(false).setVisible(false);
                            menu.findItem(R.id.menu_share_current_image).setEnabled(false).setVisible(false);
                            menu.findItem(R.id.menu_download_current_image).setEnabled(false).setVisible(false);
                            break;
                        case Contribution.STATE_IN_PROGRESS:
                        case Contribution.STATE_QUEUED:
                            menu.findItem(R.id.menu_retry_current_image).setEnabled(false).setVisible(false);
                            menu.findItem(R.id.menu_cancel_current_image).setEnabled(false).setVisible(false);
                            menu.findItem(R.id.menu_browser_current_image).setEnabled(false).setVisible(false);
                            menu.findItem(R.id.menu_share_current_image).setEnabled(false).setVisible(false);
                            menu.findItem(R.id.menu_download_current_image).setEnabled(false).setVisible(false);
                            break;
                        case Contribution.STATE_COMPLETED:
                            // Default set of menu items works fine. Treat same as regular media object
                            break;
                    }
                }
            }
        }
    }
}
Also used : Media(fr.free.nrw.commons.Media) Intent(android.content.Intent) ShareActionProvider(android.support.v7.widget.ShareActionProvider) Contribution(fr.free.nrw.commons.contributions.Contribution)

Aggregations

ShareActionProvider (android.support.v7.widget.ShareActionProvider)8 Intent (android.content.Intent)7 MenuItem (android.view.MenuItem)6 Media (fr.free.nrw.commons.Media)1 Contribution (fr.free.nrw.commons.contributions.Contribution)1 File (java.io.File)1