Commit d57f723e authored by maxwen's avatar maxwen Committed by LuK1337

Gallery2: Change all share intents to chooser style

Change-Id: Ie4387846ad65dcb7a655630dd86047d5ad63bcb9
parent a1bb50b9
<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 -->
......
......@@ -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>
......@@ -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>
......@@ -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"
......
......@@ -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" -->
......
......@@ -34,7 +34,6 @@ import android.view.MenuItem;
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 @@ public class GalleryActionBar {
// }
private Menu mActionBarMenu;
private ShareActionProvider mSharePanoramaActionProvider;
private ShareActionProvider mShareActionProvider;
private Intent mSharePanoramaIntent;
private Intent mShareIntent;
......@@ -416,20 +413,32 @@ public class GalleryActionBar {
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 @@ public class GalleryActionBar {
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() {
......
......@@ -62,7 +62,6 @@ import android.view.Window;
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 @@ public class MovieActivity extends AbstractPermissionActivity {
private Knob mVirtualizerKnob;
private SharedPreferences mPrefs;
private ShareActionProvider mShareProvider;
private IMovieItem mMovieItem;
private IActivityHooker mMovieHooker;
private KeyguardManager mKeyguardManager;
......@@ -131,6 +129,8 @@ public class MovieActivity extends AbstractPermissionActivity {
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 @@ public class MovieActivity extends AbstractPermissionActivity {
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 @@ public class MovieActivity extends AbstractPermissionActivity {
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()));
}
}
......
......@@ -43,7 +43,6 @@ import android.view.ViewGroup;
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 java.util.Locale;
//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 @@ public abstract class PhotoPage extends ActivityState implements
private int mLastSystemUiVis = 0;
private ShareActionProvider mShareActionProvider;
private Intent mShareIntent;
//use for saving the original height and padding of toolbar
......@@ -399,7 +397,7 @@ public abstract class PhotoPage extends ActivityState implements
}
Intent shareIntent = createShareIntent(mCurrentPhoto);
if (shareIntent != null) {
mActionBar.setShareIntents(panoramaIntent, shareIntent, PhotoPage.this);
mActionBar.setShareIntents(panoramaIntent, shareIntent);
}
setNfcBeamPushUri(contentUri);
}
......@@ -1811,19 +1809,6 @@ public abstract class PhotoPage extends ActivityState implements
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";
......
......@@ -81,8 +81,6 @@ import android.widget.ImageButton;
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.detect.FaceInfo;
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 @@ DialogInterface.OnDismissListener, PopupMenu.OnDismissListener{
private final Vector<ImageShow> mImageViews = new Vector<ImageShow>();
private ShareActionProvider mShareActionProvider;
private File mSharedOutputFile = null;
private boolean mSharingImage = false;
......@@ -2039,8 +2036,7 @@ DialogInterface.OnDismissListener, PopupMenu.OnDismissListener{
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 @@ DialogInterface.OnDismissListener, PopupMenu.OnDismissListener{
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 @@ DialogInterface.OnDismissListener, PopupMenu.OnDismissListener{
//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 @@ DialogInterface.OnDismissListener, PopupMenu.OnDismissListener{
@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();
}
......
......@@ -30,9 +30,7 @@ import android.view.Menu;
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 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
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 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
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 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
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 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
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 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
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 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
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;
}
}
});
......
......@@ -28,8 +28,6 @@ import android.view.Menu;
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.ArrayList;
import java.util.List;
public class MultiChoiceManager implements MultiChoiceModeListener,
OnShareTargetSelectedListener, SelectionManager.SelectedUriSource {
SelectionManager.SelectedUriSource {
public interface Provider {
public MultiChoiceManager getMultiChoiceManager();
......@@ -61,7 +59,6 @@ public class MultiChoiceManager implements MultiChoiceModeListener,
}
private SelectionManager mSelectionManager;
private ShareActionProvider mShareActionProvider;
private ActionMode mActionMode;
private Context mContext;
private Delegate mDelegate;
......@@ -122,7 +119,7 @@ public class MultiChoiceManager implements MultiChoiceModeListener,
}
}
mSelectionManager.onItemSelectedStateChanged(mShareActionProvider,
mSelectionManager.onItemSelectedStateChanged(
mDelegate.getItemMediaType(item),
supported,
checked);
......@@ -155,8 +152,21 @@ public class MultiChoiceManager implements MultiChoiceModeListener,
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 @@ public class MultiChoiceManager implements MultiChoiceModeListener,
mSelectedShareableUrisArray = new ArrayList<Uri>();
mSelectionManager.onClearSelection();
mSelectionManager.setSelectedUriSource(null);
mShareActionProvider = null;
mActionMode = null;
}
......@@ -179,12 +188,6 @@ public class MultiChoiceManager implements MultiChoiceModeListener,
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;
......
......@@ -23,7 +23,6 @@ import android.nfc.NfcAdapter;
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 @@ public class SelectionManager {
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 @@ public class SelectionManager {
}
}
}
share.setShareIntent(mShareIntent);
}
public int getSupportedOperations() {
......@@ -181,4 +179,8 @@ public class SelectionManager {
mShareIntent.removeExtra(Intent.EXTRA_STREAM);
mShareIntent.setAction(null).setType(null);
}
public Intent getShareIntent() {
return mShareIntent;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment