diff options
author | Andrew Sapperstein <asapperstein@google.com> | 2014-07-24 20:27:37 -0700 |
---|---|---|
committer | Andrew Sapperstein <asapperstein@google.com> | 2014-07-25 14:42:49 -0700 |
commit | 2d86d1123c4183024222dd2eb60f7cbdc24953fd (patch) | |
tree | 0b0a678e7fc90eec316628eb9efc5cefbdff82ce /src | |
parent | e16e644f7ceadc3f9ae3cbab4955069169c07dca (diff) | |
download | android_packages_apps_UnifiedEmail-2d86d1123c4183024222dd2eb60f7cbdc24953fd.tar.gz android_packages_apps_UnifiedEmail-2d86d1123c4183024222dd2eb60f7cbdc24953fd.tar.bz2 android_packages_apps_UnifiedEmail-2d86d1123c4183024222dd2eb60f7cbdc24953fd.zip |
Action bar styling.
Restores back button and drawer on old versions. b/16510684
b/16167419
Change-Id: I6b48a2d350330403ebf72304d74be957b6de7cb4
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/mail/ui/AbstractActivityController.java | 41 | ||||
-rw-r--r-- | src/com/android/mail/ui/ActionBarController.java (renamed from src/com/android/mail/ui/MailActionBarView.java) | 203 | ||||
-rw-r--r-- | src/com/android/mail/ui/SearchActionBarController.java (renamed from src/com/android/mail/ui/SearchMailActionBarView.java) | 20 | ||||
-rw-r--r-- | src/com/android/mail/ui/TwoPaneController.java | 6 |
4 files changed, 47 insertions, 223 deletions
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java index 75eafbacd..b4bf2f8d8 100644 --- a/src/com/android/mail/ui/AbstractActivityController.java +++ b/src/com/android/mail/ui/AbstractActivityController.java @@ -19,7 +19,6 @@ package com.android.mail.ui; import android.animation.ValueAnimator; import android.app.ActionBar; -import android.app.ActionBar.LayoutParams; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; @@ -54,7 +53,6 @@ import android.support.v4.widget.DrawerLayout; import android.view.DragEvent; import android.view.Gravity; import android.view.KeyEvent; -import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -192,7 +190,7 @@ public abstract class AbstractActivityController implements ActivityController, protected Folder mInbox; /** True when {@link #mFolder} is first shown to the user. */ private boolean mFolderChanged = false; - protected MailActionBarView mActionBarView; + protected ActionBarController mActionBarController; protected final MailActivity mActivity; protected final Context mContext; private final FragmentManager mFragmentManager; @@ -441,7 +439,7 @@ public abstract class AbstractActivityController implements ActivityController, /** * Guaranteed to be the last loader ID used by the Fragment. Loaders are owned by Activity or * fragments, and within an activity, loader IDs need to be unique. Currently, - * {@link SectionedInboxTeaserView} is the only class that uses the + * SectionedInboxTeaserView is the only class that uses the * {@link ConversationListFragment}'s LoaderManager. */ public static final int LAST_FRAGMENT_LOADER_ID = 1000; @@ -612,17 +610,16 @@ public abstract class AbstractActivityController implements ActivityController, return; } - // be sure to inherit from the ActionBar theme when inflating - final LayoutInflater inflater = LayoutInflater.from(actionBar.getThemedContext()); final boolean isSearch = mActivity.getIntent() != null && Intent.ACTION_SEARCH.equals(mActivity.getIntent().getAction()); - mActionBarView = (MailActionBarView) inflater.inflate( - isSearch ? R.layout.search_actionbar_view : R.layout.actionbar_view, null); - mActionBarView.initialize(mActivity, this, actionBar); + mActionBarController = isSearch ? + new SearchActionBarController(mContext) : + new ActionBarController(mContext); + mActionBarController.initialize(mActivity, this, actionBar); // init the action bar to allow the 'up' affordance. // any configurations that disallow 'up' should do that later. - mActionBarView.setBackButton(); + mActionBarController.setBackButton(); } /** @@ -631,12 +628,10 @@ public abstract class AbstractActivityController implements ActivityController, private void attachActionBar() { final ActionBar actionBar = mActivity.getActionBar(); if (actionBar != null) { - actionBar.setCustomView(mActionBarView, new ActionBar.LayoutParams( - LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); - // Show a custom view and home icon, keep the title and subttitle - final int mask = ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE; + // Show a title + final int mask = ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME; actionBar.setDisplayOptions(mask, mask); - mActionBarView.setViewModeController(mViewMode); + mActionBarController.setViewModeController(mViewMode); } } @@ -1043,7 +1038,7 @@ public abstract class AbstractActivityController implements ActivityController, // We do not need to notify folder observers yet. Instead we start the loaders and // when the load finishes, we will get an updated folder. Then, we notify the // folderObservers in onLoadFinished. - mActionBarView.setFolder(mFolder); + mActionBarController.setFolder(mFolder); // Only when we switch from one folder to another do we want to restart the // folder and conversation list loaders (to trigger onCreateLoader). @@ -1402,8 +1397,8 @@ public abstract class AbstractActivityController implements ActivityController, return false; } final MenuInflater inflater = mActivity.getMenuInflater(); - inflater.inflate(mActionBarView.getOptionsMenuId(), menu); - mActionBarView.onCreateOptionsMenu(menu); + inflater.inflate(mActionBarController.getOptionsMenuId(), menu); + mActionBarController.onCreateOptionsMenu(menu); return true; } @@ -2053,7 +2048,7 @@ public abstract class AbstractActivityController implements ActivityController, @Override public boolean onPrepareOptionsMenu(Menu menu) { - return mActionBarView.onPrepareOptionsMenu(menu); + return mActionBarController.onPrepareOptionsMenu(menu); } @Override @@ -2138,7 +2133,7 @@ public abstract class AbstractActivityController implements ActivityController, intent.putExtra(ConversationListContext.EXTRA_SEARCH_QUERY, query); intent.putExtra(Utils.EXTRA_ACCOUNT, mAccount); intent.setComponent(mActivity.getComponentName()); - mActionBarView.collapseSearch(); + mActionBarController.collapseSearch(); // Call startActivityForResult here so we can tell if we have navigated to a different folder // or account from search results. mActivity.startActivityForResult(intent, CHANGE_NAVIGATION_REQUEST_CODE); @@ -2159,7 +2154,7 @@ public abstract class AbstractActivityController implements ActivityController, mDrawIdler.setRootView(null); // unregister the ViewPager's observer on the conversation cursor mPagerController.onDestroy(); - mActionBarView.onDestroy(); + mActionBarController.onDestroy(); mRecentFolderList.destroy(); mDestroyed = true; mHandler.removeCallbacks(mLogServiceChecker); @@ -2587,7 +2582,7 @@ public abstract class AbstractActivityController implements ActivityController, mCurrentConversation = conversation; if (mCurrentConversation != null) { - mActionBarView.setCurrentConversation(mCurrentConversation); + mActionBarController.setCurrentConversation(mCurrentConversation); mActivity.invalidateOptionsMenu(); } } @@ -3228,7 +3223,7 @@ public abstract class AbstractActivityController implements ActivityController, return; } if (mAccount.supportsSearch()) { - mActionBarView.expandSearch(); + mActionBarController.expandSearch(); } else { Toast.makeText(mActivity.getActivityContext(), mActivity.getActivityContext() .getString(R.string.search_unsupported), Toast.LENGTH_SHORT).show(); diff --git a/src/com/android/mail/ui/MailActionBarView.java b/src/com/android/mail/ui/ActionBarController.java index fcd64319f..c8179592e 100644 --- a/src/com/android/mail/ui/MailActionBarView.java +++ b/src/com/android/mail/ui/ActionBarController.java @@ -22,25 +22,16 @@ import android.app.SearchManager; import android.app.SearchableInfo; import android.content.ContentResolver; import android.content.Context; -import android.content.res.Resources; import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.support.v4.text.BidiFormatter; import android.text.TextUtils; -import android.util.AttributeSet; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.widget.LinearLayout; import android.widget.SearchView; import android.widget.SearchView.OnQueryTextListener; import android.widget.SearchView.OnSuggestionListener; -import android.widget.TextView; import com.android.mail.ConversationListContext; import com.android.mail.R; @@ -59,14 +50,12 @@ import com.android.mail.utils.LogUtils; import com.android.mail.utils.Utils; /** - * View to manage the various states of the Mail Action Bar. - * <p> - * This also happens to be the custom view we supply to ActionBar. - * + * Controller to manage the various states of the {@link android.app.ActionBar}. */ -public class MailActionBarView extends LinearLayout implements ViewMode.ModeChangeListener, - OnQueryTextListener, OnSuggestionListener, MenuItem.OnActionExpandListener, - View.OnClickListener { +public class ActionBarController implements ViewMode.ModeChangeListener, + OnQueryTextListener, OnSuggestionListener, MenuItem.OnActionExpandListener { + + private final Context mContext; protected ActionBar mActionBar; protected ControllableActivity mActivity; @@ -89,10 +78,6 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan private SearchView mSearchWidget; private MenuItem mEmptyTrashItem; private MenuItem mEmptySpamItem; - private boolean mUseLegacyTitle; - - private TextView mLegacyTitle; - private TextView mLegacySubTitle; /** True if the current device is a tablet, false otherwise. */ protected final boolean mIsOnTablet; @@ -102,38 +87,6 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan private FolderObserver mFolderObserver; - /** A handler that changes the subtitle when it receives a message. */ - private final class SubtitleHandler extends Handler { - /** Message sent to display the account email address in the subtitle. */ - private static final int EMAIL = 0; - - @Override - public void handleMessage(Message message) { - assert (message.what == EMAIL); - final String subtitleText; - if (mAccount != null) { - // Display the account name (usually email address). - subtitleText = mAccount.getDisplayName(); - } else { - subtitleText = null; - LogUtils.wtf(LOG_TAG, "MABV.handleMessage() has a null account!"); - } - setSubtitle(mBidiFormatter.unicodeWrap(subtitleText)); - super.handleMessage(message); - } - } - - /** Changes the subtitle to display the account name */ - private final SubtitleHandler mHandler = new SubtitleHandler(); - /** Unread count for the current folder. */ - private int mUnreadCount = 0; - /** We show the email address after this delay: 5 seconds currently */ - private static final int ACCOUNT_DELAY_MS = 5 * 1000; - /** At what point do we stop showing the unread count: 999+ currently */ - private final int UNREAD_LIMIT; - /** BidiFormatter for title and subtitle. */ - private final BidiFormatter mBidiFormatter; - /** Updates the resolver and tells it the most recent account. */ private final class UpdateProvider extends AsyncTask<Bundle, Void, Void> { final Uri mAccount; @@ -158,41 +111,9 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan } }; - public MailActionBarView(Context context) { - this(context, null); - } - - public MailActionBarView(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public MailActionBarView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - final Resources r = getResources(); - mIsOnTablet = Utils.useTabletUI(r); - UNREAD_LIMIT = r.getInteger(R.integer.maxUnreadCount); - mBidiFormatter = BidiFormatter.getInstance(); - } - - private void initializeTitleViews() { - final View legacyTitleContainer = findViewById(R.id.legacy_title_container); - if (legacyTitleContainer != null) { - // Determine if this device is running on MR1.1 or later - final boolean runningMR11OrLater = actionBarSupportsNewMethods(mActionBar); - if (runningMR11OrLater || !mController.isDrawerEnabled()) { - // We don't need the legacy view, just hide it - legacyTitleContainer.setVisibility(View.GONE); - mUseLegacyTitle = false; - } else { - mUseLegacyTitle = true; - // We need to show the legacy title/subtitle. Set the click listener - legacyTitleContainer.setOnClickListener(this); - - mLegacyTitle = (TextView) legacyTitleContainer.findViewById(R.id.legacy_title); - mLegacySubTitle = - (TextView) legacyTitleContainer.findViewById(R.id.legacy_subtitle); - } - } + public ActionBarController(Context context) { + mContext = context; + mIsOnTablet = Utils.useTabletUI(context.getResources()); } public void expandSearch() { @@ -264,7 +185,6 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan mActionBar = actionBar; mController = callback; mActivity = activity; - initializeTitleViews(); mFolderObserver = new FolderObserver() { @Override @@ -287,7 +207,7 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan bundle.putParcelable(UIProvider.SetCurrentAccountColumns.ACCOUNT, account); final UpdateProvider updater = new UpdateProvider(mAccount.uri, resolver); updater.execute(bundle); - setFolderAndAccount(false /* folderChanged */); + setFolderAndAccount(); } } @@ -296,7 +216,7 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan */ public void setFolder(Folder folder) { mFolder = folder; - setFolderAndAccount(true); + setFolderAndAccount(); } public void onDestroy() { @@ -305,13 +225,11 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan mFolderObserver = null; } mAccountObserver.unregisterAndDestroy(); - mHandler.removeMessages(SubtitleHandler.EMAIL); } @Override public void onViewModeChanged(int newMode) { mActivity.invalidateOptionsMenu(); - mHandler.removeMessages(SubtitleHandler.EMAIL); // Check if we are either on a phone, or in Conversation mode on tablet. For these, the // recent folders is enabled. switch (getMode()) { @@ -422,31 +340,14 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan * Put the ActionBar in List navigation mode. */ private void showNavList() { - setTitleModeFlags(getActionBarTitleModeFlag()); - setFolderAndAccount(false); - } - - private void setSubtitle(CharSequence subtitle) { - if (!TextUtils.equals(subtitle, mActionBar.getSubtitle())) { - mActionBar.setSubtitle(subtitle); - } - if (mLegacySubTitle != null) { - mLegacySubTitle.setText(subtitle); - } + setTitleModeFlags(ActionBar.DISPLAY_SHOW_TITLE); + setFolderAndAccount(); } private void setTitle(String title) { - title = mBidiFormatter.unicodeWrap(title); if (!TextUtils.equals(title, mActionBar.getTitle())) { mActionBar.setTitle(title); } - if (mLegacyTitle != null) { - mLegacyTitle.setText(title); - } - } - - private int getActionBarTitleModeFlag() { - return mUseLegacyTitle ? ActionBar.DISPLAY_SHOW_CUSTOM : ActionBar.DISPLAY_SHOW_TITLE; } /** @@ -465,8 +366,8 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan return; } // Remove the back button but continue showing an icon. - final int mask = ActionBar.DISPLAY_HOME_AS_UP; - mActionBar.setDisplayOptions(0, mask); + final int mask = ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME; + mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME, mask); mActivity.getActionBar().setHomeButtonEnabled(false); } @@ -475,7 +376,7 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan return; } // Show home as up, and show an icon. - final int mask = ActionBar.DISPLAY_HOME_AS_UP; + final int mask = ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME; mActionBar.setDisplayOptions(mask, mask); mActivity.getActionBar().setHomeButtonEnabled(true); } @@ -549,9 +450,8 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan * Uses the current state to update the current folder {@link #mFolder} and the current * account {@link #mAccount} shown in the actionbar. Also updates the actionbar subtitle to * momentarily display the unread count if it has changed. - * @param folderChanged true if folder changed in terms of URI */ - private void setFolderAndAccount(final boolean folderChanged) { + private void setFolderAndAccount() { // Very little can be done if the actionbar or activity is null. if (mActionBar == null || mActivity == null) { return; @@ -559,7 +459,6 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan if (ViewMode.isWaitingForSync(getMode())) { // Account is not synced: clear title and update the subtitle. setTitle(""); - removeUnreadCount(true); return; } // Check if we should be changing the actionbar at all, and back off if not. @@ -576,42 +475,8 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan return; } setTitle(mFolder.name); - - final int folderUnreadCount = mFolder.isUnreadCountHidden() ? 0 : mFolder.unreadCount; - // The user shouldn't see "999+ unread messages", and then a short while later: "999+ - // unread messages". So we set our unread count just past the limit. This way we can - // change the subtitle the first time around but not for subsequent changes as far as the - // unread count remains over the limit. - final int toDisplay = (folderUnreadCount > UNREAD_LIMIT) - ? (UNREAD_LIMIT + 1) : folderUnreadCount; - if ((mUnreadCount != toDisplay || folderChanged) && toDisplay != 0) { - setSubtitle(Utils.getUnreadMessageString(mActivity.getApplicationContext(), toDisplay)); - } - // Schedule a removal of unread count for the future, if there isn't one already. If the - // unread count dropped to zero, remove it and show the account name right away. - removeUnreadCount(toDisplay == 0); - // Remember the new value for the next run - mUnreadCount = toDisplay; } - /** - * Remove the unread count and show the account name, if required. - * @param now true if you want the change to happen immediately. False if you want to enforce - * it happens later. - */ - private void removeUnreadCount(boolean now) { - if (now) { - // Remove all previous messages which might change the subtitle - mHandler.removeMessages(SubtitleHandler.EMAIL); - // Update the subtitle: clear it or show account name. - mHandler.sendEmptyMessage(SubtitleHandler.EMAIL); - } else { - if (!mHandler.hasMessages(SubtitleHandler.EMAIL)) { - // In a short while, show the account name in its place. - mHandler.sendEmptyMessageDelayed(SubtitleHandler.EMAIL, ACCOUNT_DELAY_MS); - } - } - } /** * Notify that the folder has changed. @@ -623,7 +488,7 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan /** True if we are changing folders. */ final boolean changingFolders = (mFolder == null || !mFolder.equals(folder)); mFolder = folder; - setFolderAndAccount(changingFolders); + setFolderAndAccount(); final ConversationListContext listContext = mController == null ? null : mController.getCurrentListContext(); if (changingFolders && !ConversationListContext.isSearchResult(listContext)) { @@ -645,10 +510,6 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan @Override public boolean onMenuItemActionCollapse(MenuItem item) { - // Work around b/6664203 by manually forcing this view to be VISIBLE - // upon ActionView collapse. DISPLAY_SHOW_CUSTOM will still control its final - // visibility. - setVisibility(VISIBLE); // Have to return true here. Unlike other callbacks, the return value // here is whether we want to suppress the action (rather than consume the action). We // don't want to suppress the action. @@ -725,34 +586,12 @@ public class MailActionBarView extends LinearLayout implements ViewMode.ModeChan && !mCurrentConversation.muted); } - private static boolean actionBarSupportsNewMethods(ActionBar bar) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - return true; - } - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) { - return false; - } - // API 17 - why is this special? - boolean supportsNewApi = false; - try { - if (bar != null) { - supportsNewApi = (ActionBar.class.getField("DISPLAY_TITLE_MULTIPLE_LINES") != null); - } - } catch (NoSuchFieldException e) { - // stay false - } - return supportsNewApi; - } - - @Override - public void onClick (View v) { - if (v.getId() == R.id.legacy_title_container) { - mController.onUpPressed(); - } - } - public void setViewModeController(ViewMode viewModeController) { mViewModeController = viewModeController; mViewModeController.addListener(this); } + + public Context getContext() { + return mContext; + } } diff --git a/src/com/android/mail/ui/SearchMailActionBarView.java b/src/com/android/mail/ui/SearchActionBarController.java index cf1ee0ab6..ca6090697 100644 --- a/src/com/android/mail/ui/SearchMailActionBarView.java +++ b/src/com/android/mail/ui/SearchActionBarController.java @@ -19,7 +19,6 @@ package com.android.mail.ui; import android.content.Context; import android.text.TextUtils; -import android.util.AttributeSet; import android.view.Menu; import android.view.MenuItem; import android.widget.SearchView; @@ -28,21 +27,13 @@ import com.android.mail.ConversationListContext; import com.android.mail.utils.Utils; /** - * This class is used to show a custom actionbar for the search activity. This doesn't have any - * custom views, but it shows/hides various menu items based on the viewmode. + * This class is used to control the actionbar for the search activity. + * It shows/hides various menu items based on the viewmode. */ -public class SearchMailActionBarView extends MailActionBarView { +public class SearchActionBarController extends ActionBarController { - public SearchMailActionBarView(Context context) { - this(context, null); - } - - public SearchMailActionBarView(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public SearchMailActionBarView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); + public SearchActionBarController(Context context) { + super(context); } @Override @@ -110,7 +101,6 @@ public class SearchMailActionBarView extends MailActionBarView { @Override public boolean onMenuItemActionCollapse(MenuItem item) { - super.onMenuItemActionCollapse(item); // When we are in the search activity, back closes the search action mode. At that point // we want to quit the activity entirely. final int mode = getMode(); diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java index 4139f0427..6991a728d 100644 --- a/src/com/android/mail/ui/TwoPaneController.java +++ b/src/com/android/mail/ui/TwoPaneController.java @@ -200,7 +200,7 @@ public final class TwoPaneController extends AbstractActivityController { if (!Utils.isEmpty(folder.parent)) { // Show the up affordance when digging into child folders. - mActionBarView.setBackButton(); + mActionBarController.setBackButton(); } setHierarchyFolder(folder); super.onFolderSelected(folder); @@ -259,9 +259,9 @@ public final class TwoPaneController extends AbstractActivityController { // folders, and shown for every other condition. if ((mViewMode.isListMode() && (Folder.isRoot(mFolder) || mFolder.parent == null)) || mViewMode.isWaitingForSync()) { - mActionBarView.removeBackButton(); + mActionBarController.removeBackButton(); } else { - mActionBarView.setBackButton(); + mActionBarController.setBackButton(); } } |