|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.actionbarsherlock.view.ActionProvider
com.actionbarsherlock.widget.ShareActionProvider
public class ShareActionProvider
This is a provider for a share action. It is responsible for creating views that enable data sharing and also to show a sub menu with sharing activities if the hosting item is placed on the overflow menu.
Here is how to use the action provider with custom backing file in a MenuItem:
// In Activity#onCreateOptionsMenu
public boolean onCreateOptionsMenu(Menu menu) {
// Get the menu item.
MenuItem menuItem = menu.findItem(R.id.my_menu_item);
// Get the provider and hold onto it to set/change the share intent.
mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider();
// Set history different from the default before getting the action
// view since a call to MenuItem.getActionView() calls
// ActionProvider.onCreateActionView() which uses the backing file name. Omit this
// line if using the default share history file is desired.
mShareActionProvider.setShareHistoryFileName("custom_share_history.xml");
. . .
}
// Somewhere in the application.
public void doShare(Intent shareIntent) {
// When you want to share set the share intent.
mShareActionProvider.setShareIntent(shareIntent);
}
Note: While the sample snippet demonstrates how to use this provider in the context of a menu item, the use of the provider is not limited to menu items.
ActionProvider| Nested Class Summary | |
|---|---|
static interface |
ShareActionProvider.OnShareTargetSelectedListener
Listener for the event of selecting a share target. |
| Nested classes/interfaces inherited from class com.actionbarsherlock.view.ActionProvider |
|---|
ActionProvider.SubUiVisibilityListener |
| Field Summary | |
|---|---|
static String |
DEFAULT_SHARE_HISTORY_FILE_NAME
The default name for storing share history. |
| Constructor Summary | |
|---|---|
ShareActionProvider(android.content.Context context)
Creates a new instance. |
|
| Method Summary | |
|---|---|
boolean |
hasSubMenu()
Determines if this ActionProvider has a submenu associated with it. |
android.view.View |
onCreateActionView()
Factory method for creating new action views. |
void |
onPrepareSubMenu(SubMenu subMenu)
Called to prepare an associated submenu for the menu item backed by this ActionProvider. |
void |
setOnShareTargetSelectedListener(ShareActionProvider.OnShareTargetSelectedListener listener)
Sets a listener to be notified when a share target has been selected. |
void |
setShareHistoryFileName(String shareHistoryFile)
Sets the file name of a file for persisting the share history which history will be used for ordering share targets. |
void |
setShareIntent(android.content.Intent shareIntent)
Sets an intent with information about the share action. |
| Methods inherited from class com.actionbarsherlock.view.ActionProvider |
|---|
onPerformDefaultAction, setSubUiVisibilityListener, subUiVisibilityChanged |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String DEFAULT_SHARE_HISTORY_FILE_NAME
| Constructor Detail |
|---|
public ShareActionProvider(android.content.Context context)
context - Context for accessing resources.| Method Detail |
|---|
public void setOnShareTargetSelectedListener(ShareActionProvider.OnShareTargetSelectedListener listener)
Note: If you choose the backing share history file you will still be notified in this callback.
listener - The listener.public android.view.View onCreateActionView()
onCreateActionView in class ActionProviderpublic boolean hasSubMenu()
Associated submenus will be shown when an action view is not. This
provider instance will receive a call to ActionProvider.onPrepareSubMenu(SubMenu)
after the call to ActionProvider.onPerformDefaultAction() and before a submenu is
displayed to the user.
hasSubMenu in class ActionProviderpublic void onPrepareSubMenu(SubMenu subMenu)
if ActionProvider.hasSubMenu() returns true, this method will be called when the
menu item is selected to prepare the submenu for presentation to the user. Apps
may use this to create or alter submenu content right before display.
onPrepareSubMenu in class ActionProvidersubMenu - Submenu that will be displayedpublic void setShareHistoryFileName(String shareHistoryFile)
onCreateActionView(). Defaults to
DEFAULT_SHARE_HISTORY_FILE_NAME. Set to null
if share history should not be persisted between sessions.
Note: The history file name can be set any time, however
only the action views created by onCreateActionView() after setting
the file name will be backed by the provided file.
shareHistoryFile - The share history file name.public void setShareIntent(android.content.Intent shareIntent)
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
Uri uri = Uri.fromFile(new File(getFilesDir(), "foo.jpg"));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri.toString());
shareIntent - The share intent.Intent.ACTION_SEND,
Intent.ACTION_SEND_MULTIPLE
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||