diff --git a/res/layout/message_compose.xml b/res/layout/message_compose.xml index d99db7e84..abb53509b 100644 --- a/res/layout/message_compose.xml +++ b/res/layout/message_compose.xml @@ -28,13 +28,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ededed"> - - 0) { actionBar.removeAllTabs(); } @@ -1787,30 +1783,19 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus createAndAddTab(R.string.reply_all_action, ACTION_REPLY_ALL); createAndAddTab(R.string.forward_action, ACTION_FORWARD); - actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); } else { // Spinner based mode switching. if (mActionSpinnerAdapter == null) { mActionSpinnerAdapter = new ActionSpinnerAdapter(this); - mActionSpinner.setAdapter(mActionSpinnerAdapter); - mActionSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { - @Override - public void onItemSelected( - AdapterView parent, View view, int position, long id) { - setAction(ActionSpinnerAdapter.getAction(position)); - } - - @Override - public void onNothingSelected(AdapterView parent) { - // Should not happen. - } - }); + actionBar.setListNavigationCallbacks( + mActionSpinnerAdapter, ACTION_SPINNER_LISTENER); } - int position = mActionSpinnerAdapter.getPosition(mAction); - mActionSpinner.setSelection(position); - mActionSpinner.setVisibility(View.VISIBLE); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); + actionBar.setSelectedNavigationItem( + ActionSpinnerAdapter.getActionPosition(mAction)); } + actionBar.setDisplayShowTitleEnabled(false); } private final TabListener ACTION_TAB_LISTENER = new TabListener() { @@ -1824,6 +1809,14 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus } }; + private final OnNavigationListener ACTION_SPINNER_LISTENER = new OnNavigationListener() { + @Override + public boolean onNavigationItemSelected(int itemPosition, long itemId) { + setAction(ActionSpinnerAdapter.getAction(itemPosition)); + return true; + } + }; + private static class ActionSpinnerAdapter extends ArrayAdapter { public ActionSpinnerAdapter(final Context context) { super(context, @@ -1872,6 +1865,17 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus } } + public static int getActionPosition(String action) { + if (ACTION_REPLY.equals(action)) { + return 0; + } else if (ACTION_REPLY_ALL.equals(action)) { + return 1; + } else if (ACTION_FORWARD.equals(action)) { + return 2; + } + throw new IllegalArgumentException("Invalid action type for spinner"); + } + } private Tab createAndAddTab(int labelResource, final String action) {