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;
}
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;
}
});
}
Aggregations