summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBobby Georgescu <georgescu@google.com>2012-10-01 15:50:11 -0700
committerBobby Georgescu <georgescu@google.com>2012-10-01 15:56:51 -0700
commit3cf502a91b36bf6ce633f897505b0a2c3fc53ad5 (patch)
tree23815d26f31352e088d1e0a710a6fd6d341f8880 /src
parentc58fe396fb7c6208740fa22a005e94a358b8266f (diff)
downloadandroid_packages_apps_Gallery2-3cf502a91b36bf6ce633f897505b0a2c3fc53ad5.tar.gz
android_packages_apps_Gallery2-3cf502a91b36bf6ce633f897505b0a2c3fc53ad5.tar.bz2
android_packages_apps_Gallery2-3cf502a91b36bf6ce633f897505b0a2c3fc53ad5.zip
Move grid/filmstrip switching to ActionBar title "spinner"
Bug: 7233818 Bug: 7240846 Bug: 7258973 Tapping the title of the album, whether in filmstrip or grid mode, allows switching between these modes using a menu. The album name is now displayed when viewing pictures in the filmstrip or zoomed in modes. Finally, no longer allow switching to grid mode when not appropriate. Change-Id: I4ee511feb7a74581fe185933ddd5110e5eb9feb0
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/app/AlbumPage.java36
-rw-r--r--src/com/android/gallery3d/app/GalleryActionBar.java84
-rw-r--r--src/com/android/gallery3d/app/PhotoPage.java102
3 files changed, 147 insertions, 75 deletions
diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java
index addee0ed7..ae6418cce 100644
--- a/src/com/android/gallery3d/app/AlbumPage.java
+++ b/src/com/android/gallery3d/app/AlbumPage.java
@@ -56,7 +56,7 @@ import com.android.gallery3d.util.GalleryUtils;
import com.android.gallery3d.util.MediaSetUtils;
public class AlbumPage extends ActivityState implements GalleryActionBar.ClusterRunner,
- SelectionManager.SelectionListener, MediaSet.SyncListener {
+ SelectionManager.SelectionListener, MediaSet.SyncListener, GalleryActionBar.OnAlbumModeSelectedListener {
@SuppressWarnings("unused")
private static final String TAG = "AlbumPage";
@@ -399,7 +399,9 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
boolean enableHomeButton = (mActivity.getStateManager().getStateCount() > 1) |
mParentMediaSetString != null;
- mActivity.getGalleryActionBar().setDisplayOptions(enableHomeButton, true);
+ GalleryActionBar actionBar = mActivity.getGalleryActionBar();
+ actionBar.setDisplayOptions(enableHomeButton, false);
+ actionBar.enableAlbumModeMenu(GalleryActionBar.ALBUM_GRID_MODE_SELECTED, this);
// Set the reload bit here to prevent it exit this page in clearLoadingBit().
setLoadingBit(BIT_LOADING_RELOAD);
@@ -423,6 +425,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
mAlbumDataAdapter.pause();
mAlbumView.pause();
DetailsHelper.pause();
+ mActivity.getGalleryActionBar().disableAlbumModeMenu(true);
if (mSyncTask != null) {
mSyncTask.cancel();
@@ -560,6 +563,17 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
mSlotView.getSlotRect(slotIndex, mRootPane));
}
+ private void switchToFilmstrip() {
+ if (mAlbumDataAdapter.size() < 1) return;
+ int targetPhoto = mSlotView.getVisibleStart();
+ prepareAnimationBackToFilmstrip(targetPhoto);
+ if(mLaunchedFromPhotoPage) {
+ onBackPressed();
+ } else {
+ pickPhoto(targetPhoto, true);
+ }
+ }
+
@Override
protected boolean onItemSelected(MenuItem item) {
switch (item.getItemId()) {
@@ -587,17 +601,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
SlideshowPage.class, REQUEST_SLIDESHOW, data);
return true;
}
- case R.id.action_filmstrip: {
- if (mAlbumDataAdapter.size() < 1) return true;
- int targetPhoto = mSlotView.getVisibleStart();
- prepareAnimationBackToFilmstrip(targetPhoto);
- if(mLaunchedFromPhotoPage) {
- onBackPressed();
- } else {
- pickPhoto(targetPhoto, true);
- }
- return true;
- }
case R.id.action_details: {
if (mShowDetails) {
hideDetails();
@@ -750,4 +753,11 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
}
}
}
+
+ @Override
+ public void onAlbumModeSelected(int mode) {
+ if (mode == GalleryActionBar.ALBUM_FILMSTRIP_MODE_SELECTED) {
+ switchToFilmstrip();
+ }
+ }
}
diff --git a/src/com/android/gallery3d/app/GalleryActionBar.java b/src/com/android/gallery3d/app/GalleryActionBar.java
index 2630c3e4a..6525ae542 100644
--- a/src/com/android/gallery3d/app/GalleryActionBar.java
+++ b/src/com/android/gallery3d/app/GalleryActionBar.java
@@ -22,6 +22,7 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -53,10 +54,20 @@ public class GalleryActionBar implements OnNavigationListener {
private int mCurrentIndex;
private ClusterAdapter mAdapter = new ClusterAdapter();
+ private AlbumModeAdapter mAlbumModeAdapter;
+ private OnAlbumModeSelectedListener mAlbumModeListener;
+ private CharSequence [] mAlbumModes;
+ public static final int ALBUM_FILMSTRIP_MODE_SELECTED = 0;
+ public static final int ALBUM_GRID_MODE_SELECTED = 1;
+
public interface ClusterRunner {
public void doCluster(int id);
}
+ public interface OnAlbumModeSelectedListener {
+ public void onAlbumModeSelected(int mode);
+ }
+
private static class ActionItem {
public int action;
public boolean enabled;
@@ -123,6 +134,43 @@ public class GalleryActionBar implements OnNavigationListener {
}
}
+ private class AlbumModeAdapter extends BaseAdapter {
+ @Override
+ public int getCount() {
+ return mAlbumModes.length;
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mAlbumModes[position];
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ private View getView(CharSequence label, View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ convertView = mInflater.inflate(R.layout.action_bar_text,
+ parent, false);
+ }
+ TextView view = (TextView) convertView;
+ view.setText(label);
+ return convertView;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ return getView(mActionBar.getTitle(), convertView, parent);
+ }
+
+ @Override
+ public View getDropDownView(int position, View convertView, ViewGroup parent) {
+ return getView((CharSequence) getItem(position), convertView, parent);
+ }
+ }
+
public static String getClusterByTypeString(Context context, int type) {
for (ActionItem item : sClusterItems) {
if (item.action == type) {
@@ -202,6 +250,33 @@ public class GalleryActionBar implements OnNavigationListener {
}
}
+ public void enableAlbumModeMenu(int selected, OnAlbumModeSelectedListener listener) {
+ if (mActionBar != null) {
+ if (mAlbumModeAdapter == null) {
+ // Initialize the album mode options if they haven't been already
+ Resources res = mActivity.getResources();
+ mAlbumModes = new CharSequence[] {
+ res.getString(R.string.switch_photo_filmstrip),
+ res.getString(R.string.switch_photo_grid)};
+ mAlbumModeAdapter = new AlbumModeAdapter();
+ }
+ mAlbumModeListener = null;
+ mActionBar.setListNavigationCallbacks(mAlbumModeAdapter, this);
+ mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ mActionBar.setSelectedNavigationItem(selected);
+ mAlbumModeListener = listener;
+ }
+ }
+
+ public void disableAlbumModeMenu(boolean hideMenu) {
+ if (mActionBar != null) {
+ mAlbumModeListener = null;
+ if (hideMenu) {
+ mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+ }
+ }
+ }
+
public void showClusterDialog(final ClusterRunner clusterRunner) {
createDialogData();
final ArrayList<Integer> actions = mActions;
@@ -283,12 +358,17 @@ public class GalleryActionBar implements OnNavigationListener {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
- if (itemPosition != mCurrentIndex && mClusterRunner != null) {
+ if (itemPosition != mCurrentIndex && mClusterRunner != null
+ || mAlbumModeListener != null) {
// Need to lock rendering when operations invoked by system UI (main thread) are
// modifying slot data used in GL thread for rendering.
mActivity.getGLRoot().lockRenderThread();
try {
- mClusterRunner.doCluster(sClusterItems[itemPosition].action);
+ if (mAlbumModeListener != null) {
+ mAlbumModeListener.onAlbumModeSelected(itemPosition);
+ } else {
+ mClusterRunner.doCluster(sClusterItems[itemPosition].action);
+ }
} finally {
mActivity.getGLRoot().unlockRenderThread();
}
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index 74dc7a95d..a9aa8e729 100644
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -78,7 +78,7 @@ import com.android.gallery3d.util.LightCycleHelper;
public class PhotoPage extends ActivityState implements
PhotoView.Listener, OrientationManager.Listener, AppBridge.Server,
- PhotoPageBottomControls.Delegate {
+ PhotoPageBottomControls.Delegate, GalleryActionBar.OnAlbumModeSelectedListener {
private static final String TAG = "PhotoPage";
private static final int MSG_HIDE_BARS = 1;
@@ -88,9 +88,8 @@ public class PhotoPage extends ActivityState implements
private static final int MSG_UPDATE_ACTION_BAR = 5;
private static final int MSG_UNFREEZE_GLROOT = 6;
private static final int MSG_WANT_BARS = 7;
- private static final int MSG_REFRESH_GRID_BUTTON = 8;
- private static final int MSG_REFRESH_BOTTOM_CONTROLS = 9;
- private static final int MSG_ON_CAMERA_CENTER = 10;
+ private static final int MSG_REFRESH_BOTTOM_CONTROLS = 8;
+ private static final int MSG_ON_CAMERA_CENTER = 9;
private static final int HIDE_BARS_TIMEOUT = 3500;
private static final int UNFREEZE_GLROOT_TIMEOUT = 250;
@@ -260,10 +259,6 @@ public class PhotoPage extends ActivityState implements
hideBars();
break;
}
- case MSG_REFRESH_GRID_BUTTON: {
- setGridButtonVisibility(mPhotoView.getFilmMode());
- break;
- }
case MSG_REFRESH_BOTTOM_CONTROLS: {
if (mBottomControls != null) mBottomControls.refresh();
break;
@@ -330,7 +325,6 @@ public class PhotoPage extends ActivityState implements
mStartedFromAlbumPage =
data.getInt(KEY_ALBUMPAGE_TRANSITION,
MSG_ALBUMPAGE_NONE) == MSG_ALBUMPAGE_STARTED;
- setGridButtonVisibility(!mStartedFromAlbumPage);
if (mSetPathString != null) {
mAppBridge = (AppBridge) data.getParcelable(KEY_APP_BRIDGE);
if (mAppBridge != null) {
@@ -591,7 +585,6 @@ public class PhotoPage extends ActivityState implements
}
updateMenuOperations();
- updateTitle();
if (mBottomControls != null) mBottomControls.refresh();
if (mShowDetails) {
mDetailsHelper.reloadDetails();
@@ -602,25 +595,12 @@ public class PhotoPage extends ActivityState implements
}
}
- private void updateTitle() {
- if (mCurrentPhoto == null) return;
- boolean showTitle = mActivity.getAndroidContext().getResources().getBoolean(
- R.bool.show_action_bar_title);
- if (showTitle && mCurrentPhoto.getName() != null) {
- mActionBar.setTitle(mCurrentPhoto.getName());
- } else {
- mActionBar.setTitle("");
- }
- }
-
private void updateMenuOperations() {
Menu menu = mActionBar.getMenu();
// it could be null if onCreateActionBar has not been called yet
if (menu == null) return;
- setGridButtonVisibility(mPhotoView.getFilmMode());
-
MenuItem item = menu.findItem(R.id.action_slideshow);
if (item != null) {
item.setVisible((mSecureAlbum == null) && canDoSlideShow());
@@ -800,7 +780,7 @@ public class PhotoPage extends ActivityState implements
mActionBar.createActionBarMenu(R.menu.photo, menu);
mHaveImageEditor = GalleryUtils.isEditorAvailable(mActivity, "image/*");
updateMenuOperations();
- updateTitle();
+ mActionBar.setTitle(mMediaSet != null ? mMediaSet.getName() : "");
return true;
}
@@ -826,6 +806,34 @@ public class PhotoPage extends ActivityState implements
public void onProgressStart() {}
};
+ private void switchToGrid() {
+ if (mStartedFromAlbumPage) {
+ onUpPressed();
+ } else {
+ if (mOriginalSetPathString == null) return;
+ preparePhotoFallbackView();
+ Bundle data = new Bundle(getData());
+ data.putString(AlbumPage.KEY_MEDIA_PATH, mOriginalSetPathString);
+ data.putString(AlbumPage.KEY_PARENT_MEDIA_PATH,
+ mActivity.getDataManager().getTopSetPath(
+ DataManager.INCLUDE_ALL));
+
+ // We only show cluster menu in the first AlbumPage in stack
+ // TODO: Enable this when running from the camera app
+ boolean inAlbum = mActivity.getStateManager().hasStateClass(AlbumPage.class);
+ data.putBoolean(AlbumPage.KEY_SHOW_CLUSTER_MENU, !inAlbum
+ && mAppBridge == null);
+
+ data.putBoolean(PhotoPage.KEY_APP_BRIDGE, mAppBridge != null);
+
+ // Account for live preview being first item
+ mActivity.getTransitionStore().put(KEY_RETURN_INDEX_HINT,
+ mAppBridge != null ? mCurrentIndex - 1 : mCurrentIndex);
+
+ mActivity.getStateManager().startState(AlbumPage.class, data);
+ }
+ }
+
@Override
protected boolean onItemSelected(MenuItem item) {
if (mModel == null) return true;
@@ -848,33 +856,6 @@ public class PhotoPage extends ActivityState implements
onUpPressed();
return true;
}
- case R.id.action_grid: {
- if (mStartedFromAlbumPage) {
- onUpPressed();
- } else {
- preparePhotoFallbackView();
- Bundle data = new Bundle(getData());
- data.putString(AlbumPage.KEY_MEDIA_PATH, mOriginalSetPathString);
- data.putString(AlbumPage.KEY_PARENT_MEDIA_PATH,
- mActivity.getDataManager().getTopSetPath(
- DataManager.INCLUDE_ALL));
-
- // We only show cluster menu in the first AlbumPage in stack
- // TODO: Enable this when running from the camera app
- boolean inAlbum = mActivity.getStateManager().hasStateClass(AlbumPage.class);
- data.putBoolean(AlbumPage.KEY_SHOW_CLUSTER_MENU, !inAlbum
- && mAppBridge == null);
-
- data.putBoolean(PhotoPage.KEY_APP_BRIDGE, mAppBridge != null);
-
- // Account for live preview being first item
- mActivity.getTransitionStore().put(KEY_RETURN_INDEX_HINT,
- mAppBridge != null ? mCurrentIndex - 1 : mCurrentIndex);
-
- mActivity.getStateManager().startState(AlbumPage.class, data);
- }
- return true;
- }
case R.id.action_slideshow: {
Bundle data = new Bundle();
data.putString(SlideshowPage.KEY_SET_PATH, mMediaSet.getPath().toString());
@@ -1176,6 +1157,7 @@ public class PhotoPage extends ActivityState implements
mPhotoView.pause();
mHandler.removeMessages(MSG_HIDE_BARS);
mActionBar.removeOnMenuVisibilityListener(mMenuVisibilityListener);
+ mActionBar.disableAlbumModeMenu(true);
onCommitDeleteImage();
mMenuExecutor.pause();
@@ -1187,15 +1169,7 @@ public class PhotoPage extends ActivityState implements
mActivity.getGLRoot().unfreeze();
}
- private void setGridButtonVisibility(boolean enabled) {
- Menu menu = mActionBar.getMenu();
- if (menu == null) return;
- MenuItem item = menu.findItem(R.id.action_grid);
- if (item != null) item.setVisible((mSecureAlbum == null) && enabled);
- }
-
public void onFilmModeChanged(boolean enabled) {
- mHandler.sendEmptyMessage(MSG_REFRESH_GRID_BUTTON);
mHandler.sendEmptyMessage(MSG_REFRESH_BOTTOM_CONTROLS);
if (enabled) {
mHandler.removeMessages(MSG_HIDE_BARS);
@@ -1265,8 +1239,9 @@ public class PhotoPage extends ActivityState implements
mModel.resume();
mPhotoView.resume();
mActionBar.setDisplayOptions(
- ((mSecureAlbum == null) && (mSetPathString != null)), true);
+ ((mSecureAlbum == null) && (mSetPathString != null)), false);
mActionBar.addOnMenuVisibilityListener(mMenuVisibilityListener);
+ mActionBar.enableAlbumModeMenu(GalleryActionBar.ALBUM_FILMSTRIP_MODE_SELECTED, this);
if (!mShowBars) {
mActionBar.hide();
mActivity.getGLRoot().setLightsOutMode(true);
@@ -1317,4 +1292,11 @@ public class PhotoPage extends ActivityState implements
return mModel.getCurrentIndex();
}
}
+
+ @Override
+ public void onAlbumModeSelected(int mode) {
+ if (mode == GalleryActionBar.ALBUM_GRID_MODE_SELECTED) {
+ switchToGrid();
+ }
+ }
}