Gallery2: Change all share intents to chooser style

Change-Id: Ie4387846ad65dcb7a655630dd86047d5ad63bcb9
diff --git a/res/menu/filtershow_activity_menu.xml b/res/menu/filtershow_activity_menu.xml
index d52c003..7fde667 100644
--- a/res/menu/filtershow_activity_menu.xml
+++ b/res/menu/filtershow_activity_menu.xml
@@ -1,9 +1,7 @@
 <menu xmlns:android="http://schemas.android.com/apk/res/android" >
     <item
         android:id="@+id/menu_share"
-        android:actionProviderClass="android.widget.ShareActionProvider"
         android:showAsAction="never"
-        android:enabled="false"
         android:visible="false"
         android:title="@string/share"/>
 <!--     <item -->
diff --git a/res/menu/gallery_multiselect.xml b/res/menu/gallery_multiselect.xml
index d9365c1..685ae6b 100644
--- a/res/menu/gallery_multiselect.xml
+++ b/res/menu/gallery_multiselect.xml
@@ -12,8 +12,7 @@
     <item android:id="@+id/menu_share"
           android:title="@string/share"
           android:showAsAction="ifRoom"
-          android:visible="false"
-          android:actionProviderClass="android.widget.ShareActionProvider" />
+          android:visible="false" />
     <item android:id="@+id/menu_crop"
             android:title="@string/crop_action"
             android:visible="false"
@@ -30,4 +29,4 @@
             android:title="@string/set_as"
             android:visible="false"
             android:showAsAction="never" />
-</menu>
\ No newline at end of file
+</menu>
diff --git a/res/menu/movie.xml b/res/menu/movie.xml
index fde235c..ce3a100 100644
--- a/res/menu/movie.xml
+++ b/res/menu/movie.xml
@@ -18,6 +18,5 @@
             android:icon="@drawable/ic_menu_share_holo_light"
             android:title="@string/share"
             android:enabled="true"
-            android:actionProviderClass="android.widget.ShareActionProvider"
             android:showAsAction="ifRoom" />
 </menu>
diff --git a/res/menu/operation.xml b/res/menu/operation.xml
index 2429c48..0647cad 100644
--- a/res/menu/operation.xml
+++ b/res/menu/operation.xml
@@ -26,7 +26,6 @@
             android:icon="@drawable/ic_menu_share_holo_light"
             android:title="@string/share_panorama"
             android:visible="false"
-            android:actionProviderClass="android.widget.ShareActionProvider"
             android:showAsAction="ifRoom">
     </item>
     <item android:id="@+id/action_share"
diff --git a/res/menu/photo.xml b/res/menu/photo.xml
index d02a8c9..b388d08 100644
--- a/res/menu/photo.xml
+++ b/res/menu/photo.xml
@@ -26,13 +26,11 @@
 <!--             android:icon="@drawable/ic_menu_share_holo_light" -->
 <!--             android:title="@string/share_panorama" -->
 <!--             android:visible="false" -->
-<!--             android:actionProviderClass="android.widget.ShareActionProvider" -->
 <!--             android:showAsAction="ifRoom" /> -->
 <!--     <item android:id="@+id/action_share" -->
 <!--             android:icon="@drawable/ic_menu_share_holo_light" -->
 <!--             android:title="@string/share" -->
 <!--             android:visible="false" -->
-<!--             android:actionProviderClass="android.widget.ShareActionProvider" -->
 <!--             android:showAsAction="never" /> -->
 <!--     <item android:id="@+id/action_delete" -->
 <!--             android:icon="@drawable/ic_menu_trash_holo_light" -->
diff --git a/src/com/android/gallery3d/app/GalleryActionBar.java b/src/com/android/gallery3d/app/GalleryActionBar.java
index b2ce2b2..7565303 100644
--- a/src/com/android/gallery3d/app/GalleryActionBar.java
+++ b/src/com/android/gallery3d/app/GalleryActionBar.java
@@ -34,7 +34,6 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
-import android.widget.ShareActionProvider;
 import android.widget.TextView;
 import android.widget.Toolbar;
 import android.widget.TwoLineListItem;
@@ -405,8 +404,6 @@
 //    }
 
     private Menu mActionBarMenu;
-    private ShareActionProvider mSharePanoramaActionProvider;
-    private ShareActionProvider mShareActionProvider;
     private Intent mSharePanoramaIntent;
     private Intent mShareIntent;
 
@@ -416,20 +413,32 @@
 
         MenuItem item = menu.findItem(R.id.action_share_panorama);
         if (item != null) {
-            mSharePanoramaActionProvider = (ShareActionProvider)
-                item.getActionProvider();
-            mSharePanoramaActionProvider
-                .setShareHistoryFileName("panorama_share_history.xml");
-            mSharePanoramaActionProvider.setShareIntent(mSharePanoramaIntent);
+            item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+                @Override
+                public boolean onMenuItemClick(MenuItem item) {
+                    if (mSharePanoramaIntent != null) {
+                        Intent intent = Intent.createChooser(mSharePanoramaIntent, null);
+                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                        mContext.startActivity(intent);
+                    }
+                    return true;
+                }
+            });
         }
 
         item = menu.findItem(R.id.action_share);
         if (item != null) {
-            mShareActionProvider = (ShareActionProvider)
-                item.getActionProvider();
-            mShareActionProvider
-                .setShareHistoryFileName("share_history.xml");
-            mShareActionProvider.setShareIntent(mShareIntent);
+            item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+                @Override
+                public boolean onMenuItemClick(MenuItem item) {
+                    if (mShareIntent != null) {
+                        Intent intent = Intent.createChooser(mShareIntent, null);
+                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                        mContext.startActivity(intent);
+                    }
+                    return true;
+                }
+            });
         }
     }
 
@@ -437,18 +446,9 @@
         return mActionBarMenu;
     }
 
-    public void setShareIntents(Intent sharePanoramaIntent, Intent shareIntent,
-        ShareActionProvider.OnShareTargetSelectedListener onShareListener) {
+    public void setShareIntents(Intent sharePanoramaIntent, Intent shareIntent) {
         mSharePanoramaIntent = sharePanoramaIntent;
-        if (mSharePanoramaActionProvider != null) {
-            mSharePanoramaActionProvider.setShareIntent(sharePanoramaIntent);
-        }
         mShareIntent = shareIntent;
-        if (mShareActionProvider != null) {
-            mShareActionProvider.setShareIntent(shareIntent);
-            mShareActionProvider.setOnShareTargetSelectedListener(
-                onShareListener);
-        }
     }
 
     public void setBackGroundTransparent() {
diff --git a/src/com/android/gallery3d/app/MovieActivity.java b/src/com/android/gallery3d/app/MovieActivity.java
index 708507b..2babbe7 100644
--- a/src/com/android/gallery3d/app/MovieActivity.java
+++ b/src/com/android/gallery3d/app/MovieActivity.java
@@ -62,7 +62,6 @@
 import android.view.WindowManager;
 import android.widget.CompoundButton;
 import android.widget.ImageView;
-import android.widget.ShareActionProvider;
 import android.widget.ToggleButton;
 import android.widget.Toast;
 
@@ -122,7 +121,6 @@
     private Knob        mVirtualizerKnob;
 
     private SharedPreferences   mPrefs;
-    private ShareActionProvider mShareProvider;
     private IMovieItem          mMovieItem;
     private IActivityHooker     mMovieHooker;
     private KeyguardManager     mKeyguardManager;
@@ -131,6 +129,8 @@
     private boolean mResumed        = false;
     private boolean mControlResumed = false;
 
+    private Intent mShareIntent;
+
     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(final Context context, final Intent intent) {
@@ -359,11 +359,18 @@
         getMenuInflater().inflate(R.menu.movie, menu);
         MenuItem shareMenu = menu.findItem(R.id.action_share);
         shareMenu.setVisible(false);
-        ShareActionProvider provider = (ShareActionProvider) shareMenu.getActionProvider();
-        mShareProvider = provider;
-        if (mShareProvider != null) {
-            // share provider is singleton, we should refresh our history file.
-            mShareProvider.setShareHistoryFileName(SHARE_HISTORY_FILE);
+        if (shareMenu != null) {
+            shareMenu.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+                @Override
+                public boolean onMenuItemClick(MenuItem item) {
+                    if (mShareIntent != null) {
+                        Intent intent = Intent.createChooser(mShareIntent, null);
+                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                        getApplicationContext().startActivity(mShareIntent);
+                    }
+                    return true;
+                }
+            });
         }
 
         final MenuItem mi = menu.add(R.string.audio_effects);
@@ -799,16 +806,13 @@
 
     private void refreshShareProvider(IMovieItem info) {
         // we only share the video if it's "content:".
-        if (mShareProvider != null) {
-            Intent intent = new Intent(Intent.ACTION_SEND);
-            if (MovieUtils.isLocalFile(info.getUri(), info.getMimeType())) {
-                intent.setType("video/*");
-                intent.putExtra(Intent.EXTRA_STREAM, info.getUri());
-            } else {
-                intent.setType("text/plain");
-                intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(info.getUri()));
-            }
-            mShareProvider.setShareIntent(intent);
+        mShareIntent = new Intent(Intent.ACTION_SEND);
+        if (MovieUtils.isLocalFile(info.getUri(), info.getMimeType())) {
+            mShareIntent.setType("video/*");
+            mShareIntent.putExtra(Intent.EXTRA_STREAM, info.getUri());
+        } else {
+            mShareIntent.setType("text/plain");
+            mShareIntent.putExtra(Intent.EXTRA_TEXT, String.valueOf(info.getUri()));
         }
     }
 
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index 793b1d7..6d4a3e9 100755
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -43,7 +43,6 @@
 import android.view.Window;
 import android.view.WindowManager;
 import android.widget.RelativeLayout;
-import android.widget.ShareActionProvider;
 import android.widget.Toast;
 import android.widget.Toolbar;
 
@@ -89,8 +88,8 @@
 //import android.drm.DrmHelper;
 
 public abstract class PhotoPage extends ActivityState implements
-        PhotoView.Listener, AppBridge.Server, ShareActionProvider.OnShareTargetSelectedListener,
-        PhotoPageBottomControls.Delegate, ThreeDButton.Delegate{
+        PhotoView.Listener, AppBridge.Server, PhotoPageBottomControls.Delegate,
+        ThreeDButton.Delegate {
     private static final String TAG = "PhotoPage";
 
     private static final int MSG_HIDE_BARS = 1;
@@ -209,7 +208,6 @@
 
     private int mLastSystemUiVis = 0;
 
-    private ShareActionProvider mShareActionProvider;
     private Intent mShareIntent;
 
     //use for saving the original height and padding of toolbar
@@ -399,7 +397,7 @@
                             }
                             Intent shareIntent = createShareIntent(mCurrentPhoto);
                             if (shareIntent != null) {
-                                mActionBar.setShareIntents(panoramaIntent, shareIntent, PhotoPage.this);
+                                mActionBar.setShareIntents(panoramaIntent, shareIntent);
                             }
                             setNfcBeamPushUri(contentUri);
                         }
@@ -1811,19 +1809,6 @@
         refreshBottomControlsWhenReady();
     }
 
-    @Override
-    public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
-        final long timestampMillis = mCurrentPhoto.getDateInMs();
-        final String mediaType = getMediaTypeString(mCurrentPhoto);
-        UsageStatistics.onEvent(UsageStatistics.COMPONENT_GALLERY,
-                UsageStatistics.ACTION_SHARE,
-                mediaType,
-                        timestampMillis > 0
-                        ? System.currentTimeMillis() - timestampMillis
-                        : -1);
-        return false;
-    }
-
     private static String getMediaTypeString(MediaItem item) {
         if (item.getMediaType() == MediaObject.MEDIA_TYPE_VIDEO) {
             return "Video";
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index 7e0f3ca..8229250 100755
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -81,8 +81,6 @@
 import android.widget.LinearLayout;
 import android.widget.PopupMenu;
 import android.widget.RelativeLayout;
-import android.widget.ShareActionProvider;
-import android.widget.ShareActionProvider.OnShareTargetSelectedListener;
 import android.widget.Toast;
 
 import org.codeaurora.gallery.R;
@@ -160,8 +158,8 @@
 import com.thundersoft.hz.selfportrait.makeup.engine.MakeupEngine;
 
 public class FilterShowActivity extends AbstractPermissionActivity implements OnItemClickListener,
-OnShareTargetSelectedListener, DialogInterface.OnShowListener,
-DialogInterface.OnDismissListener, PopupMenu.OnDismissListener{
+        DialogInterface.OnShowListener,
+        DialogInterface.OnDismissListener, PopupMenu.OnDismissListener {
 
     private String mAction = "";
     MasterImage mMasterImage = null;
@@ -190,7 +188,6 @@
 
     private final Vector<ImageShow> mImageViews = new Vector<ImageShow>();
 
-    private ShareActionProvider mShareActionProvider;
     private File mSharedOutputFile = null;
 
     private boolean mSharingImage = false;
@@ -2039,8 +2036,7 @@
         finish();
     }
 
-    @Override
-    public boolean onShareTargetSelected(ShareActionProvider arg0, Intent arg1) {
+    private boolean onShareTargetSelected() {
         // First, let's tell the SharedImageProvider that it will need to wait
         // for the image
         Uri uri = Uri.withAppendedPath(SharedImageProvider.CONTENT_URI,
@@ -2072,10 +2068,20 @@
     public boolean onPrepareOptionsMenu(Menu menu) {
         menu.clear();
         getMenuInflater().inflate(R.menu.filtershow_activity_menu, menu);
-        mShareActionProvider = (ShareActionProvider) menu.findItem(
-                R.id.menu_share).getActionProvider();
-        mShareActionProvider.setShareIntent(getDefaultShareIntent());
-        mShareActionProvider.setOnShareTargetSelectedListener(this);
+        MenuItem item = menu.findItem(R.id.menu_share);
+        if (item != null) {
+            item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+                @Override
+                public boolean onMenuItemClick(MenuItem item) {
+                    final Intent shareIntent = getDefaultShareIntent();
+                    onShareTargetSelected();
+                    Intent intent = Intent.createChooser(shareIntent, null);
+                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    FilterShowActivity.this.startActivity(intent);
+                    return true;
+                }
+            });
+        }
         mMenu = menu;
         setupMenu();
 
@@ -2092,6 +2098,7 @@
         //MenuItem undoItem = mMenu.findItem(R.id.undoButton);
         //MenuItem redoItem = mMenu.findItem(R.id.redoButton);
         MenuItem resetItem = mMenu.findItem(R.id.resetHistoryButton);
+        MenuItem shareItem = mMenu.findItem(R.id.menu_share);
         //mMasterImage.getHistory().setMenuItems(undoItem, redoItem, resetItem);
         if (!mMasterImage.hasModifications()) {
             mMenu.removeItem(R.id.resetHistoryButton);
@@ -2101,17 +2108,11 @@
     @Override
     public void onPause() {
         super.onPause();
-        if (mShareActionProvider != null) {
-            mShareActionProvider.setOnShareTargetSelectedListener(null);
-        }
     }
 
     @Override
     public void onResume() {
         super.onResume();
-        if (mShareActionProvider != null) {
-            mShareActionProvider.setOnShareTargetSelectedListener(this);
-        }
         if (SimpleMakeupImageFilter.HAS_TS_MAKEUP) {
             MakeupEngine.getMakeupObj();
         }
diff --git a/src/com/android/gallery3d/ui/ActionModeHandler.java b/src/com/android/gallery3d/ui/ActionModeHandler.java
index 0b367d7..b78b034 100644
--- a/src/com/android/gallery3d/ui/ActionModeHandler.java
+++ b/src/com/android/gallery3d/ui/ActionModeHandler.java
@@ -30,9 +30,7 @@
 import android.view.MenuItem;
 import android.view.View;
 import android.widget.Button;
-import android.widget.ShareActionProvider;
 import android.widget.Toolbar;
-import android.widget.ShareActionProvider.OnShareTargetSelectedListener;
 
 import org.codeaurora.gallery.R;
 import com.android.gallery3d.app.AbstractGalleryActivity;
@@ -76,8 +74,6 @@
     private Menu mMenu;
     private MenuItem mSharePanoramaMenuItem;
     private MenuItem mShareMenuItem;
-    private Intent shareIntent;
-    private ShareActionProvider mSharePanoramaActionProvider;
     private SelectionMenu mSelectionMenu;
     private ActionModeListener mListener;
     private Future<?> mMenuTask;
@@ -85,6 +81,8 @@
     private ActionMode mActionMode;
     private boolean mShareMaxDialog = false;
     private Toolbar mToolbar;
+    private Intent mShareIntent;
+    private Intent mSharePanoramaIntent;
 
     private static class GetAllPanoramaSupports implements PanoramaSupportCallback {
         private int mNumInfoRequired;
@@ -198,7 +196,7 @@
                 String shareTitle = mActivity.getResources().
                         getString(R.string.share_dialogue_title);
                 mActivity.startActivity(Intent.createChooser(
-                        shareIntent, shareTitle));
+                        mShareIntent, shareTitle));
                 return true;
             }
             mMenuExecutor.onMenuClicked(item, confirmMsg, listener);
@@ -239,15 +237,6 @@
         mSelectionMenu.updateSelectAllMode(mSelectionManager.inSelectAllMode());
     }
 
-    private final OnShareTargetSelectedListener mShareTargetSelectedListener =
-            new OnShareTargetSelectedListener() {
-        @Override
-        public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
-            mSelectionManager.leaveSelectionMode();
-            return false;
-        }
-    };
-
     @Override
     public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
         return false;
@@ -261,11 +250,19 @@
         mMenu = menu;
         mSharePanoramaMenuItem = menu.findItem(R.id.action_share_panorama);
         if (mSharePanoramaMenuItem != null) {
-            mSharePanoramaActionProvider = (ShareActionProvider) mSharePanoramaMenuItem
-                .getActionProvider();
-            mSharePanoramaActionProvider.setOnShareTargetSelectedListener(
-                    mShareTargetSelectedListener);
-            mSharePanoramaActionProvider.setShareHistoryFileName("panorama_share_history.xml");
+            mSharePanoramaMenuItem.setOnMenuItemClickListener(
+                    new MenuItem.OnMenuItemClickListener() {
+                @Override
+                public boolean onMenuItemClick(MenuItem item) {
+                    mSelectionManager.leaveSelectionMode();
+                    if (mSharePanoramaIntent != null) {
+                        Intent intent = Intent.createChooser(mSharePanoramaIntent, null);
+                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                        mActivity.startActivity(intent);
+                    }
+                    return true;
+                }
+            });
         }
         mShareMenuItem = menu.findItem(R.id.action_share);
         return true;
@@ -547,14 +544,14 @@
                                 mShareMenuItem.setTitle(
                                     mActivity.getResources().getString(R.string.share));
                             }
-                            mSharePanoramaActionProvider.setShareIntent(share_panorama_intent);
+                            mSharePanoramaIntent = share_panorama_intent;
                         }
                         if (mShareMenuItem != null) {
                             showShareMaxDialogIfNeed(canShare);
 
                             mShareMenuItem.setEnabled(canShare);
                             isThreadComplete = true;
-                            shareIntent = share_intent;
+                            mShareIntent = share_intent;
                         }
                     }
                 });
diff --git a/src/com/android/photos/MultiChoiceManager.java b/src/com/android/photos/MultiChoiceManager.java
index 99685cb..137898c 100644
--- a/src/com/android/photos/MultiChoiceManager.java
+++ b/src/com/android/photos/MultiChoiceManager.java
@@ -28,8 +28,6 @@
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.widget.AbsListView.MultiChoiceModeListener;
-import android.widget.ShareActionProvider;
-import android.widget.ShareActionProvider.OnShareTargetSelectedListener;
 
 import org.codeaurora.gallery.R;
 import com.android.gallery3d.app.TrimVideo;
@@ -42,7 +40,7 @@
 import java.util.List;
 
 public class MultiChoiceManager implements MultiChoiceModeListener,
-    OnShareTargetSelectedListener, SelectionManager.SelectedUriSource {
+    SelectionManager.SelectedUriSource {
 
     public interface Provider {
         public MultiChoiceManager getMultiChoiceManager();
@@ -61,7 +59,6 @@
     }
 
     private SelectionManager mSelectionManager;
-    private ShareActionProvider mShareActionProvider;
     private ActionMode mActionMode;
     private Context mContext;
     private Delegate mDelegate;
@@ -122,7 +119,7 @@
             }
         }
 
-        mSelectionManager.onItemSelectedStateChanged(mShareActionProvider,
+        mSelectionManager.onItemSelectedStateChanged(
                 mDelegate.getItemMediaType(item),
                 supported,
                 checked);
@@ -155,8 +152,21 @@
         MenuInflater inflater = mode.getMenuInflater();
         inflater.inflate(R.menu.gallery_multiselect, menu);
         MenuItem menuItem = menu.findItem(R.id.menu_share);
-        mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider();
-        mShareActionProvider.setOnShareTargetSelectedListener(this);
+        if (menuItem != null) {
+            menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
+                @Override
+                public boolean onMenuItemClick(MenuItem item) {
+                    mActionMode.finish();
+                    Intent shareIntent = mSelectionManager.getShareIntent();
+                    if (shareIntent != null) {
+                        Intent intent = Intent.createChooser(shareIntent, null);
+                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                        mContext.startActivity(intent);
+                    }
+                    return true;
+                }
+            });
+        }
         updateSelectedTitle(mode);
         return true;
     }
@@ -169,7 +179,6 @@
         mSelectedShareableUrisArray = new ArrayList<Uri>();
         mSelectionManager.onClearSelection();
         mSelectionManager.setSelectedUriSource(null);
-        mShareActionProvider = null;
         mActionMode = null;
     }
 
@@ -179,12 +188,6 @@
         return false;
     }
 
-    @Override
-    public boolean onShareTargetSelected(ShareActionProvider provider, Intent intent) {
-        mActionMode.finish();
-        return false;
-    }
-
     private static class BulkDeleteTask extends AsyncTask<Void, Void, Void> {
         private Delegate mDelegate;
         private List<Object> mPaths;
diff --git a/src/com/android/photos/SelectionManager.java b/src/com/android/photos/SelectionManager.java
index 9bfb9be..1ab7691 100644
--- a/src/com/android/photos/SelectionManager.java
+++ b/src/com/android/photos/SelectionManager.java
@@ -23,7 +23,6 @@
 import android.nfc.NfcAdapter.CreateBeamUrisCallback;
 import android.nfc.NfcEvent;
 import android.provider.MediaStore.Files.FileColumns;
-import android.widget.ShareActionProvider;
 
 import com.android.gallery3d.common.ApiHelper;
 import com.android.gallery3d.data.MediaObject;
@@ -74,8 +73,8 @@
 
     private ArrayList<Uri> mCachedShareableUris = null;
 
-    public void onItemSelectedStateChanged(ShareActionProvider share,
-            int itemType, int itemSupportedOperations, boolean selected) {
+    public void onItemSelectedStateChanged(int itemType, int itemSupportedOperations,
+            boolean selected) {
         int increment = selected ? 1 : -1;
 
         mSelectedTotalCount += increment;
@@ -132,7 +131,6 @@
                 }
             }
         }
-        share.setShareIntent(mShareIntent);
     }
 
     public int getSupportedOperations() {
@@ -181,4 +179,8 @@
         mShareIntent.removeExtra(Intent.EXTRA_STREAM);
         mShareIntent.setAction(null).setType(null);
     }
+
+    public Intent getShareIntent() {
+        return mShareIntent;
+    }
 }