From 2ec97235ec1ee7ab6161e6dc576a4ae06bf61e7b Mon Sep 17 00:00:00 2001 From: Sander Bogaert Date: Mon, 16 Jul 2012 09:22:42 -0400 Subject: [PATCH] Split bar on Messagelist activity and some code styling. --- AndroidManifest.xml | 1 + .../actionbar_indeterminate_progress.xml | 32 ++++ res/layout/actionbar_spinner.xml | 28 ++++ res/layout/actionbar_top_custom.xml | 16 ++ res/menu/folder_list_option.xml | 2 + res/menu/message_list_option.xml | 24 ++- src/com/fsck/k9/activity/FolderList.java | 140 ++++++++-------- .../k9/activity/K9PreferenceActivity.java | 4 +- src/com/fsck/k9/activity/MessageList.java | 151 ++++++++++++++---- 9 files changed, 279 insertions(+), 119 deletions(-) create mode 100644 res/layout/actionbar_indeterminate_progress.xml create mode 100644 res/layout/actionbar_spinner.xml create mode 100644 res/layout/actionbar_top_custom.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 028847637..862ff25e5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -208,6 +208,7 @@ android:name="com.fsck.k9.activity.MessageList" android:launchMode="singleTask" android:configChanges="locale" + android:uiOptions="splitActionBarWhenNarrow" > diff --git a/res/layout/actionbar_indeterminate_progress.xml b/res/layout/actionbar_indeterminate_progress.xml new file mode 100644 index 000000000..e4263adb4 --- /dev/null +++ b/res/layout/actionbar_indeterminate_progress.xml @@ -0,0 +1,32 @@ + + + + + + \ No newline at end of file diff --git a/res/layout/actionbar_spinner.xml b/res/layout/actionbar_spinner.xml new file mode 100644 index 000000000..54508d848 --- /dev/null +++ b/res/layout/actionbar_spinner.xml @@ -0,0 +1,28 @@ + + + + + + + + \ No newline at end of file diff --git a/res/layout/actionbar_top_custom.xml b/res/layout/actionbar_top_custom.xml new file mode 100644 index 000000000..ebb40daae --- /dev/null +++ b/res/layout/actionbar_top_custom.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/res/menu/folder_list_option.xml b/res/menu/folder_list_option.xml index 6af522cfd..8e4638fb7 100644 --- a/res/menu/folder_list_option.xml +++ b/res/menu/folder_list_option.xml @@ -5,6 +5,7 @@ android:alphabeticShortcut="c" android:title="@string/compose_action" android:icon="@drawable/ic_menu_compose" + android:showAsAction="always" /> - + android:icon="@drawable/ic_menu_set_sort" + android:showAsAction="always" > + - - + android:icon="@drawable/ic_menu_preferences" + android:showAsAction="ifRoom"> diff --git a/src/com/fsck/k9/activity/FolderList.java b/src/com/fsck/k9/activity/FolderList.java index 2c2eadbfb..7d9930216 100644 --- a/src/com/fsck/k9/activity/FolderList.java +++ b/src/com/fsck/k9/activity/FolderList.java @@ -26,7 +26,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.view.Window; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; @@ -42,6 +41,7 @@ import android.widget.Toast; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; +import com.actionbarsherlock.view.Window; import com.fsck.k9.Account; import com.fsck.k9.Account.FolderMode; import com.fsck.k9.AccountStats; @@ -266,7 +266,6 @@ public class FolderList extends K9ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); - setContentView(R.layout.folder_list); mListView = getListView(); mListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET); @@ -395,8 +394,7 @@ public class FolderList extends K9ListActivity { public boolean onKeyDown(int keyCode, KeyEvent event) { //Shortcuts that work no matter what is selected switch (keyCode) { - case KeyEvent.KEYCODE_Q: - { + case KeyEvent.KEYCODE_Q: { onAccounts(); return true; } @@ -676,59 +674,63 @@ public class FolderList extends K9ListActivity { @Override public Dialog onCreateDialog(int id) { switch (id) { - case DIALOG_MARK_ALL_AS_READ: - return ConfirmationDialog.create(this, id, R.string.mark_all_as_read_dlg_title, - getString(R.string.mark_all_as_read_dlg_instructions_fmt, - mSelectedContextFolder.displayName), - R.string.okay_action, R.string.cancel_action, - new Runnable() { - @Override - public void run() { - markAllAsRead(); - } - }); - case DIALOG_FIND_FOLDER: { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.filter_folders_action); + case DIALOG_MARK_ALL_AS_READ: + return ConfirmationDialog.create(this, id, R.string.mark_all_as_read_dlg_title, + getString(R.string.mark_all_as_read_dlg_instructions_fmt, + mSelectedContextFolder.displayName), + R.string.okay_action, R.string.cancel_action, + new Runnable() { + @Override + public void run() { + markAllAsRead(); + } + }); + case DIALOG_FIND_FOLDER: { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.filter_folders_action); - final EditText input = new EditText(this); - input.setId(R.id.filter_folders); - input.setHint(R.string.folder_list_filter_hint); - input.addTextChangedListener(new TextWatcher() { - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - mAdapter.getFilter().filter(input.getText()); - } + final EditText input = new EditText(this); + input.setId(R.id.filter_folders); + input.setHint(R.string.folder_list_filter_hint); + input.addTextChangedListener(new TextWatcher() { + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + mAdapter.getFilter().filter(input.getText()); + } - @Override - public void beforeTextChanged(CharSequence s, int start, int count, - int after) { /* not used */ } + @Override + public void beforeTextChanged(CharSequence s, int start, int count, + int after) { + /* not used */ + } - @Override - public void afterTextChanged(Editable s) { /* not used */ } - }); + @Override + public void afterTextChanged(Editable s) { + /* not used */ + } + }); - builder.setView(input); + builder.setView(input); - builder.setPositiveButton(getString(R.string.okay_action), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - String value = input.getText().toString(); - mAdapter.getFilter().filter(value); - } - }); + builder.setPositiveButton(getString(R.string.okay_action), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + String value = input.getText().toString(); + mAdapter.getFilter().filter(value); + } + }); - builder.setNegativeButton(getString(R.string.cancel_action), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - mAdapter.getFilter().filter(null); - } - }); + builder.setNegativeButton(getString(R.string.cancel_action), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + mAdapter.getFilter().filter(null); + } + }); - return builder.create(); - } + return builder.create(); + } } return super.onCreateDialog(id); @@ -737,27 +739,27 @@ public class FolderList extends K9ListActivity { @Override public void onPrepareDialog(int id, Dialog dialog) { switch (id) { - case DIALOG_MARK_ALL_AS_READ: { - AlertDialog alertDialog = (AlertDialog) dialog; - alertDialog.setMessage(getString(R.string.mark_all_as_read_dlg_instructions_fmt, - mSelectedContextFolder.displayName)); - break; - } - case DIALOG_FIND_FOLDER: { - AlertDialog alertDialog = (AlertDialog) dialog; - EditText input = (EditText) alertDialog.findViewById(R.id.filter_folders); + case DIALOG_MARK_ALL_AS_READ: { + AlertDialog alertDialog = (AlertDialog) dialog; + alertDialog.setMessage(getString(R.string.mark_all_as_read_dlg_instructions_fmt, + mSelectedContextFolder.displayName)); + break; + } + case DIALOG_FIND_FOLDER: { + AlertDialog alertDialog = (AlertDialog) dialog; + EditText input = (EditText) alertDialog.findViewById(R.id.filter_folders); - // Populate the EditText with the current search term - FolderListFilter filter = (FolderListFilter) mAdapter.getFilter(); - input.setText(filter.getSearchTerm()); + // Populate the EditText with the current search term + FolderListFilter filter = (FolderListFilter) mAdapter.getFilter(); + input.setText(filter.getSearchTerm()); - // Place the cursor at the end of the text - input.setSelection(input.getText().length()); - break; - } - default: { - super.onPrepareDialog(id, dialog); - } + // Place the cursor at the end of the text + input.setSelection(input.getText().length()); + break; + } + default: { + super.onPrepareDialog(id, dialog); + } } } diff --git a/src/com/fsck/k9/activity/K9PreferenceActivity.java b/src/com/fsck/k9/activity/K9PreferenceActivity.java index 3ad26718d..5fa44cb76 100644 --- a/src/com/fsck/k9/activity/K9PreferenceActivity.java +++ b/src/com/fsck/k9/activity/K9PreferenceActivity.java @@ -19,8 +19,8 @@ public class K9PreferenceActivity extends SherlockPreferenceActivity { // which causes PreferenceScreens to have a black background. // http://code.google.com/p/android/issues/detail?id=4611 setTheme(K9.getK9ThemeResourceId(K9.THEME_DARK)); - }else{ - setTheme(K9.getK9ThemeResourceId()); + } else { + setTheme(K9.getK9ThemeResourceId()); } super.onCreate(icicle); diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index b0aa96701..2d20fa742 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -13,6 +13,7 @@ import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences.Editor; +import android.database.DataSetObserver; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; @@ -30,18 +31,16 @@ import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector; import android.view.KeyEvent; import android.view.LayoutInflater; -import com.actionbarsherlock.view.Menu; -import com.actionbarsherlock.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.view.Window; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; +import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -49,9 +48,15 @@ import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageButton; import android.widget.ListView; import android.widget.ProgressBar; +import android.widget.SpinnerAdapter; import android.widget.TextView; import android.widget.Toast; +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.ActionBar.OnNavigationListener; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuItem; +import com.actionbarsherlock.view.Window; import com.fsck.k9.Account; import com.fsck.k9.Account.SortType; import com.fsck.k9.AccountStats; @@ -83,7 +88,7 @@ import com.fsck.k9.mail.store.StorageManager; */ public class MessageList extends K9Activity - implements OnClickListener, AdapterView.OnItemClickListener, AnimationListener { + implements OnClickListener, AdapterView.OnItemClickListener, AnimationListener, OnNavigationListener { /** * Reverses the result of a {@link Comparator}. @@ -232,6 +237,10 @@ public class MessageList private static final String EXTRA_LIST_POSITION = "listPosition"; private static final String EXTRA_RETURN_FROM_MESSAGE_VIEW = "returnFromMessageView"; + private static final Long AB_NAVIGATION_INBOX = 0l; + private static final Long AB_NAVIGATION_FOLDERS = 1l; + private static final Long AB_NAVIGATION_ACCOUNTS = 2l; + /** * Maps a {@link SortType} to a {@link Comparator} implementation. */ @@ -308,6 +317,9 @@ public class MessageList private FontSizes mFontSizes = K9.getFontSizes(); + private MenuItem mRefreshMenuItem; + private View mActionBarProgressView; + private Bundle mState = null; /** @@ -515,7 +527,7 @@ public class MessageList } } - getWindow().setFeatureInt(Window.FEATURE_PROGRESS, level); + setSupportProgress(level); } private void setWindowTitle() { @@ -543,7 +555,17 @@ public class MessageList } private void progress(final boolean progress) { - showProgressIndicator(progress); + // Make sure we don't try this before the menu is initialized + // this could happen while the activity is initialized. + if (mRefreshMenuItem == null) { + return; + } + + if (progress) { + mRefreshMenuItem.setActionView(mActionBarProgressView); + } else { + mRefreshMenuItem.setActionView(null); + } } /** @@ -636,7 +658,7 @@ public class MessageList } public static void actionHandle(Context context, String title, - SearchSpecification searchSpecification) { + SearchSpecification searchSpecification) { Intent intent = actionHandleAccountIntent(context, title, searchSpecification); context.startActivity(intent); } @@ -666,6 +688,7 @@ public class MessageList super.onCreate(savedInstanceState); mInflater = getLayoutInflater(); + initializeActionBar(); initializeLayout(); // Only set "touchable" when we're first starting up the activity. @@ -687,7 +710,7 @@ public class MessageList private void initializeMessageList(Intent intent, boolean create) { boolean returnFromMessageView = intent.getBooleanExtra( - EXTRA_RETURN_FROM_MESSAGE_VIEW, false); + EXTRA_RETURN_FROM_MESSAGE_VIEW, false); if (!create && returnFromMessageView) { // We're returning from the MessageView activity with "Manage back button" enabled. @@ -879,9 +902,23 @@ public class MessageList refreshTitle(); } - private void initializeLayout() { - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + private void initializeActionBar() { requestWindowFeature(Window.FEATURE_PROGRESS); + + ActionBar actionBar = getSupportActionBar(); + actionBar.setCustomView(R.layout.actionbar_top_custom); + actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, + ActionBar.DISPLAY_SHOW_CUSTOM); + actionBar.setDisplayShowTitleEnabled(false); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); + actionBar.setListNavigationCallbacks( + new MessageListNavigationSpinner(this, + new String[] {"Inbox", "Folders", "Accounts"}, + new Long[] {AB_NAVIGATION_INBOX, AB_NAVIGATION_FOLDERS, AB_NAVIGATION_ACCOUNTS }), + this); + } + + private void initializeLayout() { setContentView(R.layout.message_list); mListView = (ListView) findViewById(R.id.message_list); @@ -913,6 +950,62 @@ public class MessageList mBatchMoveButton.setVisibility(K9.batchButtonsMove() ? View.VISIBLE : View.GONE); mBatchFlagButton.setVisibility(K9.batchButtonsFlag() ? View.VISIBLE : View.GONE); mBatchDoneButton.setVisibility(K9.batchButtonsUnselect() ? View.VISIBLE : View.GONE); + + mActionBarProgressView = mInflater.inflate(R.layout.actionbar_indeterminate_progress, null); + } + + private class MessageListNavigationSpinner extends ArrayAdapter implements SpinnerAdapter { + + private String mTitle = ""; + private String mSubTitle = ""; + + private Long[] mIds; + + public MessageListNavigationSpinner(Context context, String[] objects, Long[] ids) { + super(context, R.layout.actionbar_spinner, + android.R.id.text1, objects); + setDropDownViewResource(android.R.layout.simple_list_item_1); + mIds = new Long[ids.length]; + mIds = ids; + } + + public boolean setTitle(String title) { + if (!title.equals(mTitle)) { + mTitle = title; + notifyDataSetChanged(); + return true; + } else { + return false; + } + } + + public boolean setSubTitle(String subtitle) { + if (!subtitle.equals(mSubTitle)) { + mSubTitle = subtitle; + notifyDataSetChanged(); + return true; + } else { + return false; + } + } + + @Override + public View getDropDownView(int position, View convertView, + ViewGroup parent) { + // TODO Auto-generated method stub + return super.getDropDownView(position, convertView, parent); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + // TODO Auto-generated method stub + return super.getView(position, convertView, parent); + } + + @Override + public long getItemId(int position) { + return mIds[position]; + } } /** @@ -1463,10 +1556,6 @@ public class MessageList onCompose(); return true; } - case R.id.accounts: { - onAccounts(); - return true; - } case R.id.set_sort_date: { changeSort(SortType.SORT_DATE); return true; @@ -1549,10 +1638,6 @@ public class MessageList mController.sendPendingMessages(mAccount, mAdapter.mListener); return true; } - case R.id.list_folders: { - onShowFolderList(); - return true; - } case R.id.mark_all_as_read: { if (mFolderName != null) { onMarkAllAsRead(mAccount, mFolderName); @@ -1678,7 +1763,7 @@ public class MessageList public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getSupportMenuInflater().inflate(R.menu.message_list_option, menu); - + mRefreshMenuItem = menu.findItem(R.id.check_mail); return true; } @@ -1766,21 +1851,6 @@ public class MessageList mController.sendAlternate(this, account, holder.message); } - public void showProgressIndicator(boolean status) { - setProgressBarIndeterminateVisibility(status); - ProgressBar bar = (ProgressBar)mListView.findViewById(R.id.message_list_progress); - if (bar == null) { - return; - } - - bar.setIndeterminate(true); - if (status) { - bar.setVisibility(ProgressBar.VISIBLE); - } else { - bar.setVisibility(ProgressBar.INVISIBLE); - } - } - @Override protected void onSwipeRightToLeft(final MotionEvent e1, final MotionEvent e2) { // Handle right-to-left as an un-select @@ -3102,4 +3172,17 @@ public class MessageList return account; } + + @Override + public boolean onNavigationItemSelected(int itemPosition, long itemId) { + if (itemId == AB_NAVIGATION_FOLDERS) { + onShowFolderList(); + return true; + } else if (itemId == AB_NAVIGATION_ACCOUNTS) { + onAccounts(); + return true; + } + + return false; + } }