本文整理汇总了Java中android.support.v7.widget.ShareActionProvider类的典型用法代码示例。如果您正苦于以下问题:Java ShareActionProvider类的具体用法?Java ShareActionProvider怎么用?Java ShareActionProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShareActionProvider类属于android.support.v7.widget包,在下文中一共展示了ShareActionProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onOptionsItemSelected
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
startActivity(new Intent(App.getAppContext(),Settings.class));
return true;
}else if (id == R.id.action_favorite) {
favourite(post);
}else if (id == R.id.action_share) {
shareTextUrl();
}
return super.onOptionsItemSelected(item);
}
示例2: onCreateOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.share, menu);
MenuItem item = menu.findItem(R.id.action_share);
ShareActionProvider shareAction = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
Intent send = new Intent();
send.setAction(Intent.ACTION_SEND);
send.putExtra(Intent.EXTRA_TEXT, text.toString());
send.setType("text/plain");
if(shareAction != null) {
shareAction.setShareIntent(send);
}
return super.onCreateOptionsMenu(menu);
}
示例3: onCreateOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.ride_menu, menu);
// store action provider
shareMenuItem = menu.findItem(R.id.menu_item_share);
shareMenuItem.setVisible(false);
shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareMenuItem);
// Create share intent
shareFileIntent = new Intent();
shareFileIntent.setAction(Intent.ACTION_SEND);
shareFileIntent.setType("text/csv");
shareFileIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
setShareIntent(shareFileIntent);
return true;
}
示例4: onCreateOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.poem_toolbar, menu);
favoriteItem = menu.findItem(R.id.action_addToFavorites);
if (presenter.isFavorite()){
favoriteItem.setIcon(R.drawable.ic_star_full);
}
MenuItem item = menu.findItem(R.id.action_share);
ShareActionProvider mShareActionProvider =
(ShareActionProvider) MenuItemCompat.getActionProvider(item);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, presenter.getPoemContentString());
mShareActionProvider.setShareIntent(shareIntent);
return true;
}
示例5: onCreateOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
if (getActivity() instanceof MainActivity) {
((MainActivity) getActivity()).setIntentShareMenu(createShareBookIntent(mBookSelected));
} else {
inflater.inflate(R.menu.menu_detail, menu);
MenuItem menushareItem = menu.findItem(R.id.action_share);
ShareActionProvider mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menushareItem);
if (mBookSelected != null) {
menushareItem.setVisible(true);
mShareActionProvider.setShareIntent(createShareBookIntent(mBookSelected));
}
}
}
示例6: onCreateActionMode
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
menu.add(0, R.id.select_all, 0, R.string.select_all).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(0, R.id.cut, 0, R.string.cut).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(0, R.id.copy, 0, R.string.copy).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
MenuItem pasteMenu = menu.add(0, R.id.paste, 0, R.string.paste);
pasteMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
pasteMenu.setEnabled(fileClipboard.canPaste());
renameMenu = menu.add(0, R.id.rename, 0, R.string.rename);
renameMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
shareMenu = menu.add(0, R.id.share, 0, R.string.share);
shareMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
shareActionProvider = new ShareActionProvider(context);
shareActionProvider.setOnShareTargetSelectedListener(this);
MenuItemCompat.setActionProvider(shareMenu, shareActionProvider);
menu.add(0, R.id.delete, 0, R.string.delete).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
return true;
}
示例7: onCreateOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Inflate the menu; this adds items to the action bar if it is present.
inflater.inflate(R.menu.detailfragment, menu);
// Retrieve the share menu item
MenuItem menuItem = menu.findItem(R.id.action_share);
// Get the provider and hold onto it to set/change the share intent.
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem);
// If onLoadFinished happens before this, we can go ahead and set the share intent now.
if (mForecast != null) {
mShareActionProvider.setShareIntent(createShareForecastIntent());
}
}
示例8: onCreateOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.news_activity_menu, menu);
MenuItem item = menu.findItem(R.id.action_share);
ShareActionProvider shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
shareActionProvider.setShareIntent(getDefaultShareIntent());
shareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() {
@Override
public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
String shareTarget = intent.getComponent().getPackageName();
TrackerUtils.shareNewsArticle(mNewsVo.title,shareTarget);
return false;
}
});
return super.onCreateOptionsMenu(menu);
}
示例9: onCreateOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Inflate the menu; this adds items to the action bar if it is present.
inflater.inflate(R.menu.menu_detail_fragment, menu);
// Retrieve the share menu item
MenuItem menuItem = menu.findItem(R.id.action_share);
// Get the provider and hold onto it to set/change the share intent.
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem);
// If onLoadFinished happens before this, we can go ahead and set the share intent now.
if (mForecast != null) {
mShareActionProvider.setShareIntent(createShareForecastIntent());
}
}
示例10: onCreateOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Inflate the menu; this adds items to the action bar if it is present.
inflater.inflate(R.menu.menu_detail_fragment, menu);
// Retrieve the share menu item
MenuItem menuItem = menu.findItem(R.id.action_share);
// Get the provider and hold onto it to set/change the share intent.
ShareActionProvider mShareActionProvider =
(ShareActionProvider) MenuItemCompat.getActionProvider(menuItem);
// 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.
if (mShareActionProvider != null ) {
mShareActionProvider.setShareIntent(createShareForecastIntent());
} else {
Log.d(LOG_TAG, "Share Action Provider is null?");
}
}
示例11: onCreateOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
MaterialMenuInflater.with(getActivity(), inflater)
.setDefaultColor(0xFFFFFFFF)
.inflate(R.menu.hadis, menu);
mSwitch = menu.findItem(R.id.favswitch);
mFav = menu.findItem(R.id.fav);
setCurrentPage(mPager.getCurrentItem());
MenuItem item = menu.findItem(R.id.menu_item_share);
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
item = menu.findItem(R.id.menu_search);
SearchView searchView = (SearchView) item.getActionView();
searchView.setOnQueryTextListener(this);
}
示例12: onPrepareOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
final Context context = getContext();
if(context == null || mTitle == null) {
return;
}
final MenuItem shareItem = menu.findItem(R.id.menu_share);
if(shareItem != null) {
final Intent shareIntent = EntryUtils.getShareIntent(context, mTitle, mRating);
final ShareActionProvider actionProvider =
(ShareActionProvider)MenuItemCompat.getActionProvider(shareItem);
if(actionProvider != null) {
actionProvider.setShareIntent(shareIntent);
}
}
}
示例13: onCreateActionMode
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
menu.add(0, R.id.select_all, 0, R.string.select_all).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(0, R.id.cut, 0, R.string.cut).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(0, R.id.copy, 0, R.string.copy).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
MenuItem pasteMenu = menu.add(0, R.id.paste, 0, R.string.paste);
pasteMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
pasteMenu.setEnabled(fileClipboard.canPaste());
renameMenu = menu.add(0, R.id.rename, 0, R.string.rename);
renameMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
shareMenu = menu.add(0, R.id.share, 0, R.string.share);
shareMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
shareActionProvider = new ShareActionProvider(context);
shareActionProvider.setOnShareTargetSelectedListener(this);
MenuItemCompat.setActionProvider(shareMenu, shareActionProvider);
menu.add(0, R.id.delete, 0, R.string.delete).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
copyPathMenu = menu.add(0, R.id.copy_path, 0, R.string.copy_path);
copyPathMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
return true;
}
示例14: onCreateOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem shareItem = menu.findItem(R.id.shareQuiz);
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
mShareActionProvider.setShareIntent(getDefaultIntent());
mShareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() {
@Override
public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
// startActivity(intent);
return false;
}
});
return true;
}
示例15: onCreateOptionsMenu
import android.support.v7.widget.ShareActionProvider; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
this.getMenuInflater().inflate(R.menu.toolbar_menu, menu);
menu.findItem(R.id.packet_number_entry).setVisible(false);
menu.findItem(R.id.clear_btn).setVisible(false);
menu.findItem(R.id.scan_btn).setVisible(false);
menu.findItem(R.id.state_bt_btn).setVisible(false);
menu.findItem(R.id.reset_snoop_file).setVisible(false);
menu.findItem(R.id.filter_btn).setVisible(false);
menu.findItem(R.id.refresh).setVisible(false);
MenuItem item = menu.findItem(R.id.share);
if (item != null) {
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
setSharedIntent();
}
return super.onCreateOptionsMenu(menu);
}