1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-11 21:58:35 -05:00

Split bar on Messagelist activity and some code styling.

This commit is contained in:
Sander Bogaert 2012-07-16 09:22:42 -04:00 committed by Andrew Chen
parent 4293914855
commit 2ec97235ec
9 changed files with 279 additions and 119 deletions

View File

@ -208,6 +208,7 @@
android:name="com.fsck.k9.activity.MessageList" android:name="com.fsck.k9.activity.MessageList"
android:launchMode="singleTask" android:launchMode="singleTask"
android:configChanges="locale" android:configChanges="locale"
android:uiOptions="splitActionBarWhenNarrow"
> >
<intent-filter> <intent-filter>
<!-- This action is only to allow an entry point for launcher shortcuts --> <!-- This action is only to allow an entry point for launcher shortcuts -->

View File

@ -0,0 +1,32 @@
<!--
Copyright 2011 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingRight="12dp"
android:paddingLeft="12dp">
<!-- FrameLayout ignores margins so we use this padding
to make sure the total is the same width as the icon we
replace and no visual shifting occurs -->
<ProgressBar android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_gravity="center"
style="?android:attr/indeterminateProgressStyle" />
</FrameLayout>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- android:gravity="fill_horizontal" -->
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="-4dip"
android:text="Inbox"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/actionbar_title_sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@android:id/text1"
android:text="Refreshing"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:layout_alignParentRight="true"
android:src="@drawable/ic_menu_refresh" />
</RelativeLayout>

View File

@ -5,6 +5,7 @@
android:alphabeticShortcut="c" android:alphabeticShortcut="c"
android:title="@string/compose_action" android:title="@string/compose_action"
android:icon="@drawable/ic_menu_compose" android:icon="@drawable/ic_menu_compose"
android:showAsAction="always"
/> />
<item <item
android:title="@string/folder_list_display_mode_label" android:title="@string/folder_list_display_mode_label"
@ -60,6 +61,7 @@
android:alphabeticShortcut="r" android:alphabeticShortcut="r"
android:title="@string/check_mail_action" android:title="@string/check_mail_action"
android:icon="@drawable/ic_menu_refresh" android:icon="@drawable/ic_menu_refresh"
android:showAsAction="always"
/> />
<item <item
android:id="@+id/settings" android:id="@+id/settings"

View File

@ -5,11 +5,13 @@
android:alphabeticShortcut="c" android:alphabeticShortcut="c"
android:title="@string/compose_action" android:title="@string/compose_action"
android:icon="@drawable/ic_menu_compose" android:icon="@drawable/ic_menu_compose"
android:showAsAction="always"
/> />
<item <item
android:id="@+id/set_sort" android:id="@+id/set_sort"
android:title="@string/sort_by" android:title="@string/sort_by"
android:icon="@drawable/ic_menu_set_sort"> android:icon="@drawable/ic_menu_set_sort"
android:showAsAction="always" >
<menu> <menu>
<item <item
android:id="@+id/set_sort_date" android:id="@+id/set_sort_date"
@ -45,6 +47,7 @@
android:id="@+id/select_all" android:id="@+id/select_all"
android:title="@string/batch_select_all" android:title="@string/batch_select_all"
android:icon="@drawable/ic_menu_select_all" android:icon="@drawable/ic_menu_select_all"
android:showAsAction="always"
/> />
<item <item
android:id="@+id/batch_ops" android:id="@+id/batch_ops"
@ -107,12 +110,6 @@
/> />
</menu> </menu>
</item> </item>
<item
android:id="@+id/list_folders"
android:alphabeticShortcut="f"
android:title="@string/list_folders_action"
android:icon="@drawable/ic_menu_navigate"
/>
<item <item
android:id="@+id/send_messages" android:id="@+id/send_messages"
android:alphabeticShortcut="r" android:alphabeticShortcut="r"
@ -124,21 +121,19 @@
android:alphabeticShortcut="r" android:alphabeticShortcut="r"
android:title="@string/check_mail_action" android:title="@string/check_mail_action"
android:icon="@drawable/ic_menu_refresh" android:icon="@drawable/ic_menu_refresh"
/> android:showAsAction="always"
<item
android:id="@+id/accounts"
android:title="@string/accounts_action"
android:icon="@drawable/ic_menu_account_list"
/> />
<item <item
android:id="@+id/mark_all_as_read" android:id="@+id/mark_all_as_read"
android:title="@string/mark_all_as_read_action" android:title="@string/mark_all_as_read_action"
android:icon="@drawable/ic_menu_inbox" android:icon="@drawable/ic_menu_inbox"
android:showAsAction="always"
/> />
<item <item
android:id="@+id/settings" android:id="@+id/settings"
android:title="@string/preferences_action" android:title="@string/preferences_action"
android:icon="@drawable/ic_menu_preferences"> android:icon="@drawable/ic_menu_preferences"
android:showAsAction="ifRoom">
<menu> <menu>
<item <item
android:id="@+id/folder_settings" android:id="@+id/folder_settings"
@ -160,5 +155,6 @@
<item <item
android:id="@+id/expunge" android:id="@+id/expunge"
android:title="@string/expunge_action" android:title="@string/expunge_action"
android:showAsAction="ifRoom"
/> />
</menu> </menu>

View File

@ -26,7 +26,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
@ -42,6 +41,7 @@ import android.widget.Toast;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.fsck.k9.Account; import com.fsck.k9.Account;
import com.fsck.k9.Account.FolderMode; import com.fsck.k9.Account.FolderMode;
import com.fsck.k9.AccountStats; import com.fsck.k9.AccountStats;
@ -266,7 +266,6 @@ public class FolderList extends K9ListActivity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.folder_list); setContentView(R.layout.folder_list);
mListView = getListView(); mListView = getListView();
mListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET); mListView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET);
@ -395,8 +394,7 @@ public class FolderList extends K9ListActivity {
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
//Shortcuts that work no matter what is selected //Shortcuts that work no matter what is selected
switch (keyCode) { switch (keyCode) {
case KeyEvent.KEYCODE_Q: case KeyEvent.KEYCODE_Q: {
{
onAccounts(); onAccounts();
return true; return true;
} }
@ -702,10 +700,14 @@ public class FolderList extends K9ListActivity {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, public void beforeTextChanged(CharSequence s, int start, int count,
int after) { /* not used */ } int after) {
/* not used */
}
@Override @Override
public void afterTextChanged(Editable s) { /* not used */ } public void afterTextChanged(Editable s) {
/* not used */
}
}); });
builder.setView(input); builder.setView(input);

View File

@ -19,7 +19,7 @@ public class K9PreferenceActivity extends SherlockPreferenceActivity {
// which causes PreferenceScreens to have a black background. // which causes PreferenceScreens to have a black background.
// http://code.google.com/p/android/issues/detail?id=4611 // http://code.google.com/p/android/issues/detail?id=4611
setTheme(K9.getK9ThemeResourceId(K9.THEME_DARK)); setTheme(K9.getK9ThemeResourceId(K9.THEME_DARK));
}else{ } else {
setTheme(K9.getK9ThemeResourceId()); setTheme(K9.getK9ThemeResourceId());
} }

View File

@ -13,6 +13,7 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.database.DataSetObserver;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -30,18 +31,16 @@ import android.view.ContextMenu.ContextMenuInfo;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener; import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
@ -49,9 +48,15 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.SpinnerAdapter;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; 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;
import com.fsck.k9.Account.SortType; import com.fsck.k9.Account.SortType;
import com.fsck.k9.AccountStats; import com.fsck.k9.AccountStats;
@ -83,7 +88,7 @@ import com.fsck.k9.mail.store.StorageManager;
*/ */
public class MessageList public class MessageList
extends K9Activity extends K9Activity
implements OnClickListener, AdapterView.OnItemClickListener, AnimationListener { implements OnClickListener, AdapterView.OnItemClickListener, AnimationListener, OnNavigationListener {
/** /**
* Reverses the result of a {@link Comparator}. * 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_LIST_POSITION = "listPosition";
private static final String EXTRA_RETURN_FROM_MESSAGE_VIEW = "returnFromMessageView"; 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. * Maps a {@link SortType} to a {@link Comparator} implementation.
*/ */
@ -308,6 +317,9 @@ public class MessageList
private FontSizes mFontSizes = K9.getFontSizes(); private FontSizes mFontSizes = K9.getFontSizes();
private MenuItem mRefreshMenuItem;
private View mActionBarProgressView;
private Bundle mState = null; private Bundle mState = null;
/** /**
@ -515,7 +527,7 @@ public class MessageList
} }
} }
getWindow().setFeatureInt(Window.FEATURE_PROGRESS, level); setSupportProgress(level);
} }
private void setWindowTitle() { private void setWindowTitle() {
@ -543,7 +555,17 @@ public class MessageList
} }
private void progress(final boolean progress) { 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);
}
} }
/** /**
@ -666,6 +688,7 @@ public class MessageList
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mInflater = getLayoutInflater(); mInflater = getLayoutInflater();
initializeActionBar();
initializeLayout(); initializeLayout();
// Only set "touchable" when we're first starting up the activity. // Only set "touchable" when we're first starting up the activity.
@ -879,9 +902,23 @@ public class MessageList
refreshTitle(); refreshTitle();
} }
private void initializeLayout() { private void initializeActionBar() {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS); 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); setContentView(R.layout.message_list);
mListView = (ListView) findViewById(R.id.message_list); mListView = (ListView) findViewById(R.id.message_list);
@ -913,6 +950,62 @@ public class MessageList
mBatchMoveButton.setVisibility(K9.batchButtonsMove() ? View.VISIBLE : View.GONE); mBatchMoveButton.setVisibility(K9.batchButtonsMove() ? View.VISIBLE : View.GONE);
mBatchFlagButton.setVisibility(K9.batchButtonsFlag() ? View.VISIBLE : View.GONE); mBatchFlagButton.setVisibility(K9.batchButtonsFlag() ? View.VISIBLE : View.GONE);
mBatchDoneButton.setVisibility(K9.batchButtonsUnselect() ? 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<String> 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(); onCompose();
return true; return true;
} }
case R.id.accounts: {
onAccounts();
return true;
}
case R.id.set_sort_date: { case R.id.set_sort_date: {
changeSort(SortType.SORT_DATE); changeSort(SortType.SORT_DATE);
return true; return true;
@ -1549,10 +1638,6 @@ public class MessageList
mController.sendPendingMessages(mAccount, mAdapter.mListener); mController.sendPendingMessages(mAccount, mAdapter.mListener);
return true; return true;
} }
case R.id.list_folders: {
onShowFolderList();
return true;
}
case R.id.mark_all_as_read: { case R.id.mark_all_as_read: {
if (mFolderName != null) { if (mFolderName != null) {
onMarkAllAsRead(mAccount, mFolderName); onMarkAllAsRead(mAccount, mFolderName);
@ -1678,7 +1763,7 @@ public class MessageList
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.menu.message_list_option, menu); getSupportMenuInflater().inflate(R.menu.message_list_option, menu);
mRefreshMenuItem = menu.findItem(R.id.check_mail);
return true; return true;
} }
@ -1766,21 +1851,6 @@ public class MessageList
mController.sendAlternate(this, account, holder.message); 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 @Override
protected void onSwipeRightToLeft(final MotionEvent e1, final MotionEvent e2) { protected void onSwipeRightToLeft(final MotionEvent e1, final MotionEvent e2) {
// Handle right-to-left as an un-select // Handle right-to-left as an un-select
@ -3102,4 +3172,17 @@ public class MessageList
return account; 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;
}
} }