/**@class android.widget.ShareActionProvider
@extends android.view.ActionProvider
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.
<p>
Here is how to use the action provider with custom backing file in a {@link MenuItem}:
</p>
<pre>
// 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 {@link MenuItem#getActionView() MenuItem.getActionView()} calls
// {@link 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);
}</pre>
<p>
<strong>Note:</strong> 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.
</p>
@see ActionProvider
*/
var ShareActionProvider = {
/** The default name for storing share history.
*/
DEFAULT_SHARE_HISTORY_FILE_NAME : "share_history.xml",
/**Sets a listener to be notified when a share target has been selected.
The listener can optionally decide to handle the selection and
not rely on the default behavior which is to launch the activity.
<p>
<strong>Note:</strong> If you choose the backing share history file
you will still be notified in this callback.
</p>
@param {Object {ShareActionProvider.OnShareTargetSelectedListener}} listener The listener.
*/
setOnShareTargetSelectedListener : function( ) {},
/**{@inheritDoc}
*/
onCreateActionView : function( ) {},
/**{@inheritDoc}
*/
hasSubMenu : function( ) {},
/**{@inheritDoc}
*/
onPrepareSubMenu : function( ) {},
/**Sets the file name of a file for persisting the share history which
history will be used for ordering share targets. This file will be used
for all view created by {@link #onCreateActionView}(). Defaults to
{@link #DEFAULT_SHARE_HISTORY_FILE_NAME}. Set to <code>null</code>
if share history should not be persisted between sessions.
<p>
<strong>Note:</strong> The history file name can be set any time, however
only the action views created by {@link #onCreateActionView}() after setting
the file name will be backed by the provided file. Therefore, if you want to
use different history files for sharing specific types of content, every time
you change the history file {@link #setShareHistoryFileName}(String) you must
call {@link android.app.Activity#invalidateOptionsMenu()} to recreate the
action view. You should <strong>not</strong> call
{@link android.app.Activity#invalidateOptionsMenu()} from
{@link android.app.Activity#onCreateOptionsMenu(Menu)}.
</p>
<pre>
private void doShare(Intent intent) {
if (IMAGE.equals(intent.getMimeType())) {
mShareActionProvider.setHistoryFileName(SHARE_IMAGE_HISTORY_FILE_NAME);
} else if (TEXT.equals(intent.getMimeType())) {
mShareActionProvider.setHistoryFileName(SHARE_TEXT_HISTORY_FILE_NAME);
}
mShareActionProvider.setIntent(intent);
invalidateOptionsMenu();
}</pre>
@param {String} shareHistoryFile The share history file name.
*/
setShareHistoryFileName : function( ) {},
/**Sets an intent with information about the share action. Here is a
sample for constructing a share intent:
<pre>
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);</pre>
@param {Object {Intent}} shareIntent The share intent.
@see Intent#ACTION_SEND
@see Intent#ACTION_SEND_MULTIPLE
*/
setShareIntent : function( ) {},
};