From d5b2da371654e3a74702f2b7a2036762c339232f Mon Sep 17 00:00:00 2001 From: Andrew Stadler Date: Mon, 28 Jun 2010 23:17:27 -0700 Subject: [PATCH] Add ActionBar to MailboxList Note: This does not appear in UX wireframes, this activity is going away eventually, but it's a good testbed for ActionBar to be tried out. Open issues: 1. Waiting for progress indicator support, using unattractive hack 2. Subtitle doesn't seem to work so putting account name in title (which is the wrong font size for phone portrait mode). Change-Id: Iee3cac7d4f30ea210bd8f3838b69ed12cd498375 --- AndroidManifest.xml | 2 +- res/layout/mailbox_list.xml | 1 - res/menu/mailbox_list_option.xml | 14 ++- .../android/email/activity/MailboxList.java | 85 +++++++++---------- 4 files changed, 46 insertions(+), 56 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 0a7d380a8..ecbefed77 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -160,7 +160,7 @@ + android:theme="@android:style/Theme.WithActionBar" > - - - mLoadAccountNameTask; + private AsyncTask mLoadAccountNameTask; /** * Open a specific account. @@ -92,18 +88,17 @@ public class MailboxList extends Activity implements OnClickListener, MailboxLis mControllerCallback = new ControllerResultUiThreadWrapper( new Handler(), new ControllerResults()); - mProgressIcon = (ProgressBar) findViewById(R.id.title_progress_icon); + mActionBar = getActionBar(); mErrorBanner = (TextView) findViewById(R.id.connection_error_text); mListFragment = (MailboxListFragment) findFragmentById(android.R.id.list); - ((Button) findViewById(R.id.account_title_button)).setOnClickListener(this); - ((TextView)findViewById(R.id.title_left_text)).setText(R.string.mailbox_list_title); + mActionBar.setStandardNavigationMode(this.getText(R.string.mailbox_list_title)); mListFragment.bindActivityInfo(mAccountId, this); // Go to the database for the account name - mLoadAccountNameTask = new AsyncTask() { + mLoadAccountNameTask = new AsyncTask() { @Override - protected Object[] doInBackground(Void... params) { + protected String[] doInBackground(Void... params) { String accountName = null; Uri uri = ContentUris.withAppendedId(Account.CONTENT_URI, mAccountId); Cursor c = MailboxList.this.getContentResolver().query( @@ -115,12 +110,11 @@ public class MailboxList extends Activity implements OnClickListener, MailboxLis } finally { c.close(); } - int nAccounts = EmailContent.count(MailboxList.this, Account.CONTENT_URI, null, null); - return new Object[] {accountName, nAccounts}; + return new String[] { accountName }; } @Override - protected void onPostExecute(Object[] result) { + protected void onPostExecute(String[] result) { if (result == null) { return; } @@ -130,9 +124,12 @@ public class MailboxList extends Activity implements OnClickListener, MailboxLis // something is wrong with this account finish(); } - - final int nAccounts = (Integer) result[1]; - setTitleAccountName(accountName, nAccounts > 1); + // STOPSHIP this doesn't work - the subtitle doesn't work - bug 2805131 +// mActionBar.setStandardNavigationMode( +// MailboxList.this.getText(R.string.mailbox_list_title), +// accountName); + // STOPSHIP - so, for temp fix, show the account name (since it's the dynamic value) + mActionBar.setStandardNavigationMode(accountName); } }.execute(); @@ -166,14 +163,6 @@ public class MailboxList extends Activity implements OnClickListener, MailboxLis mLoadAccountNameTask = null; } - public void onClick(View v) { - switch (v.getId()) { - case R.id.account_title_button: - onAccounts(); - break; - } - } - @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); @@ -181,15 +170,29 @@ public class MailboxList extends Activity implements OnClickListener, MailboxLis return true; } + // STOPSHIP - this is a placeholder if/until there's support for progress in actionbar + // Remove it, or replace with a better icon + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + MenuItem item = menu.findItem(R.id.refresh); + if (mProgressRunning) { + item.setIcon(android.R.drawable.progress_indeterminate_horizontal); + } else { + item.setIcon(R.drawable.ic_menu_refresh); + } + return true; + } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case android.R.id.home: + onAccounts(); + return true; case R.id.refresh: onRefresh(-1); return true; - case R.id.accounts: - onAccounts(); - return true; case R.id.compose: onCompose(); return true; @@ -246,22 +249,12 @@ public class MailboxList extends Activity implements OnClickListener, MailboxLis MessageCompose.actionCompose(this, mAccountId); } - private void setTitleAccountName(String accountName, boolean showAccountsButton) { - TextView accountsButton = (TextView) findViewById(R.id.account_title_button); - TextView textPlain = (TextView) findViewById(R.id.title_right_text); - if (showAccountsButton) { - accountsButton.setVisibility(View.VISIBLE); - textPlain.setVisibility(View.GONE); - accountsButton.setText(accountName); - } else { - accountsButton.setVisibility(View.GONE); - textPlain.setVisibility(View.VISIBLE); - textPlain.setText(accountName); - } - } - private void showProgressIcon(boolean show) { - mProgressIcon.setVisibility(show ? View.VISIBLE : View.GONE); + // STOPSHIP: This doesn't work, pending fix is bug b/2802962 + //setProgressBarIndeterminateVisibility(show); + // STOPSHIP: This is a hack used to replace the refresh icon with a spinner + mProgressRunning = show; + invalidateOptionsMenu(); } private void showErrorBanner(String message) {