Search in sources :

Example 6 with ShareActionProvider

use of android.widget.ShareActionProvider in project Meltdown by phubbard.

the class ItemDisplayActivity method onCreateOptionsMenu.

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater infl = getMenuInflater();
    infl.inflate(R.menu.activity_item, menu);
    // Get the menu item.
    MenuItem menuItem = menu.findItem(R.id.itemShare);
    // Get the provider and hold onto it to set/change the share intent.
    ShareActionProvider mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider();
    // Attach an intent to this ShareActionProvider.  You can update this at any time,
    // like when the user selects a new piece of data they might like to share.
    mShareActionProvider.setShareIntent(createShareIntent());
    return true;
}
Also used : MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) ShareActionProvider(android.widget.ShareActionProvider)

Example 7 with ShareActionProvider

use of android.widget.ShareActionProvider in project weiciyuan by qii.

the class CommentSingleChoiceModeListener method buildMenu.

protected void buildMenu(ActionMode mode, Menu menu) {
    MenuInflater inflater = mode.getMenuInflater();
    menu.clear();
    boolean isMyComment = bean.getUser().getId().equals(GlobalContext.getInstance().getCurrentAccountId());
    boolean isCommentUnderMyStatus = bean.getStatus().getUser().getId().equals(GlobalContext.getInstance().getCurrentAccountId());
    if (isMyComment || isCommentUnderMyStatus) {
        inflater.inflate(R.menu.contextual_menu_fragment_comment_listview_myself, menu);
    } else {
        inflater.inflate(R.menu.contextual_menu_fragment_comment_listview, menu);
    }
    mode.setTitle(bean.getUser().getScreen_name());
    MenuItem item = menu.findItem(R.id.menu_share);
    mShareActionProvider = (ShareActionProvider) item.getActionProvider();
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.putExtra(Intent.EXTRA_TEXT, bean.getText());
    PackageManager packageManager = getActivity().getPackageManager();
    List<ResolveInfo> activities = packageManager.queryIntentActivities(sharingIntent, 0);
    boolean isIntentSafe = activities.size() > 0;
    if (isIntentSafe && mShareActionProvider != null) {
        mShareActionProvider.setShareIntent(sharingIntent);
    }
    mShareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() {

        @Override
        public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
            finish();
            return false;
        }
    });
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) Intent(android.content.Intent) ShareActionProvider(android.widget.ShareActionProvider)

Aggregations

ShareActionProvider (android.widget.ShareActionProvider)7 Intent (android.content.Intent)4 MenuItem (android.view.MenuItem)4 MenuInflater (android.view.MenuInflater)3 ClipboardManager (android.content.ClipboardManager)2 PackageManager (android.content.pm.PackageManager)2 ResolveInfo (android.content.pm.ResolveInfo)2 ActionProvider (android.view.ActionProvider)1 BrowserCommentActivity (org.qii.weiciyuan.ui.browser.BrowserCommentActivity)1 WriteCommentActivity (org.qii.weiciyuan.ui.send.WriteCommentActivity)1 WriteReplyToCommentActivity (org.qii.weiciyuan.ui.send.WriteReplyToCommentActivity)1 WriteRepostActivity (org.qii.weiciyuan.ui.send.WriteRepostActivity)1 FavAsyncTask (org.qii.weiciyuan.ui.task.FavAsyncTask)1 UnFavAsyncTask (org.qii.weiciyuan.ui.task.UnFavAsyncTask)1