public static final String KEY_MEDIA_PATH = "media-path";
public static final String KEY_SET_TITLE = "set-title";
public static final String KEY_SET_SUBTITLE = "set-subtitle";
- public static final String KEY_SELECTED_TAB_TYPE = "selected-tab";
+ public static final String KEY_SELECTED_CLUSTER_TYPE = "selected-cluster";
private static final int DATA_CACHE_SIZE = 256;
private static final int REQUEST_DO_ANIMATION = 1;
private MediaSet mMediaSet;
private String mTitle;
private String mSubtitle;
- private boolean mShowClusterTabs;
+ private boolean mShowClusterMenu;
+ private int mSelectedAction;
protected SelectionManager mSelectionManager;
private AlbumSetDataAdapter mAlbumSetDataAdapter;
String newPath = FilterUtils.switchClusterPath(basePath, clusterType);
Bundle data = new Bundle(getData());
data.putString(AlbumSetPage.KEY_MEDIA_PATH, newPath);
- data.putInt(KEY_SELECTED_TAB_TYPE, clusterType);
+ data.putInt(KEY_SELECTED_CLUSTER_TYPE, clusterType);
mAlbumSetView.savePositions(PositionRepository.getInstance(mActivity));
mActivity.getStateManager().switchState(this, AlbumSetPage.class, data);
}
mDetailsSource = new MyDetailsSource();
GalleryActionBar actionBar = mActivity.getGalleryActionBar();
if (actionBar != null) {
- actionBar.setSelectedTab(data.getInt(
- AlbumSetPage.KEY_SELECTED_TAB_TYPE, FilterUtils.CLUSTER_BY_ALBUM));
+ mSelectedAction = data.getInt(
+ AlbumSetPage.KEY_SELECTED_CLUSTER_TYPE, FilterUtils.CLUSTER_BY_ALBUM);
}
startTransition();
}
mEyePosition.pause();
DetailsHelper.pause();
GalleryActionBar actionBar = mActivity.getGalleryActionBar();
- if (actionBar != null) actionBar.hideClusterTabs();
+ if (actionBar != null) actionBar.hideClusterMenu();
}
@Override
mEyePosition.resume();
mActionModeHandler.resume();
GalleryActionBar actionBar = mActivity.getGalleryActionBar();
- if (mShowClusterTabs && actionBar != null) actionBar.showClusterTabs(this);
+ if (mShowClusterMenu && actionBar != null) actionBar.showClusterMenu(mSelectedAction, this);
}
private void initializeData(Bundle data) {
inflater.inflate(R.menu.pickup, menu);
actionBar.setTitle(R.string.select_album);
} else {
- mShowClusterTabs = !inAlbum;
+ mShowClusterMenu = !inAlbum;
inflater.inflate(R.menu.albumset, menu);
if (mTitle != null) {
actionBar.setTitle(mTitle);
switch (mode) {
case SelectionManager.ENTER_SELECTION_MODE: {
- mActivity.getGalleryActionBar().hideClusterTabs();
+ mActivity.getGalleryActionBar().hideClusterMenu();
mActionMode = mActionModeHandler.startActionMode();
break;
}
case SelectionManager.LEAVE_SELECTION_MODE: {
mActionMode.finish();
- mActivity.getGalleryActionBar().showClusterTabs(this);
+ mActivity.getGalleryActionBar().showClusterMenu(mSelectedAction, this);
mRootPane.invalidate();
break;
}
import com.android.gallery3d.R;
import android.app.ActionBar;
-import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.DialogInterface;
+import android.text.TextUtils.TruncateAt;
+import android.view.Gravity;
+import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AbsListView;
+import android.widget.BaseAdapter;
import android.widget.ShareActionProvider;
+import android.widget.SpinnerAdapter;
+import android.widget.TextView;
+import android.widget.LinearLayout.LayoutParams;
import java.util.ArrayList;
-public class GalleryActionBar implements ActionBar.TabListener {
+public class GalleryActionBar implements ActionBar.OnNavigationListener {
private static final String TAG = "GalleryActionBar";
public interface ClusterRunner {
public int action;
public boolean enabled;
public boolean visible;
- public int tabTitle;
+ public int spinnerTitle;
public int dialogTitle;
public int clusterBy;
this(action, applied, enabled, title, title, clusterBy);
}
- public ActionItem(int action, boolean applied, boolean enabled, int tabTitle,
+ public ActionItem(int action, boolean applied, boolean enabled, int spinnerTitle,
int dialogTitle, int clusterBy) {
this.action = action;
this.enabled = enabled;
- this.tabTitle = tabTitle;
+ this.spinnerTitle = spinnerTitle;
this.dialogTitle = dialogTitle;
this.clusterBy = clusterBy;
this.visible = true;
R.string.group_by_tags)
};
+ private class ClusterAdapter extends BaseAdapter {
+
+ public int getCount() {
+ return sClusterItems.length;
+ }
+
+ public Object getItem(int position) {
+ return sClusterItems[position];
+ }
+
+ public long getItemId(int position) {
+ return sClusterItems[position].action;
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ convertView = (TextView) mInflater.inflate(R.layout.action_bar_text,
+ parent, false);
+ }
+ TextView view = (TextView) convertView;
+ view.setText(sClusterItems[position].spinnerTitle);
+ return convertView;
+ }
+ }
+
private ClusterRunner mClusterRunner;
private CharSequence[] mTitles;
private ArrayList<Integer> mActions;
private Context mContext;
+ private LayoutInflater mInflater;
private ActionBar mActionBar;
- // We need this because ActionBar.getSelectedTab() doesn't work when
- // ActionBar is hidden.
- private Tab mCurrentTab;
+ private int mCurrentIndex;
+ private ClusterAdapter mAdapter = new ClusterAdapter();
public GalleryActionBar(Activity activity) {
mActionBar = activity.getActionBar();
mContext = activity;
-
- for (ActionItem item : sClusterItems) {
- mActionBar.addTab(mActionBar.newTab().setText(item.tabTitle).
- setTag(item).setTabListener(this));
- }
+ mInflater = activity.getLayoutInflater();
+ mCurrentIndex = 0;
}
public static int getHeight(Activity activity) {
}
public int getClusterTypeAction() {
- if (mCurrentTab != null) {
- ActionItem item = (ActionItem) mCurrentTab.getTag();
- return item.action;
- }
- // By default, it's group-by-album
- return FilterUtils.CLUSTER_BY_ALBUM;
+ return sClusterItems[mCurrentIndex].action;
}
public static String getClusterByTypeString(Context context, int type) {
return shareActionProvider;
}
- public void showClusterTabs(ClusterRunner runner) {
- Log.v(TAG, "showClusterTabs: runner=" + runner);
- // setNavigationMode will trigger onTabSelected, so we should avoid
- // triggering any callback here
+ public void showClusterMenu(int action, ClusterRunner runner) {
+ Log.v(TAG, "showClusterMenu: runner=" + runner);
+ // Don't set cluster runner until action bar is ready.
mClusterRunner = null;
- mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+ mActionBar.setListNavigationCallbacks(mAdapter, this);
+ mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ setSelectedAction(action);
mClusterRunner = runner;
}
- public void hideClusterTabs() {
+ public void hideClusterMenu() {
mClusterRunner = null;
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
- Log.v(TAG, "hideClusterTabs: runner=" + mClusterRunner);
}
public void showClusterDialog(final ClusterRunner clusterRunner) {
return mActionBar == null ? 0 : mActionBar.getHeight();
}
- @Override
- public void onTabSelected(Tab tab, FragmentTransaction ft) {
- if (mCurrentTab == tab) return;
- mCurrentTab = tab;
- ActionItem item = (ActionItem) tab.getTag();
- Log.v(TAG, "onTabSelected: clusterrRunner=" + mClusterRunner);
- if (mClusterRunner != null) mClusterRunner.doCluster(item.action);
- }
-
- @Override
- public void onTabUnselected(Tab tab, FragmentTransaction ft) {
- }
-
- @Override
- public void onTabReselected(Tab tab, FragmentTransaction ft) {
- }
-
- public boolean setSelectedTab(int type) {
- for (int i = 0, n = sClusterItems.length; i < n; ++i) {
+ public boolean setSelectedAction(int type) {
+ for (int i = 0, n = sClusterItems.length; i < n; i++) {
ActionItem item = sClusterItems[i];
if (item.visible && item.action == type) {
- mActionBar.selectTab(mActionBar.getTabAt(i));
+ mActionBar.setSelectedNavigationItem(i);
+ mCurrentIndex = i;
return true;
}
}
return false;
}
+
+ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
+ if (itemPosition != mCurrentIndex && mClusterRunner != null) {
+ mClusterRunner.doCluster(sClusterItems[itemPosition].action);
+ }
+
+ return false;
+ }
}