Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Google Inc. |
| 3 | * Licensed to The Android Open Source Project. |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 4 | * |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 8 | * |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 10 | * |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 17 | |
Vikram Aggarwal | 1ddcf0f | 2012-01-13 11:45:02 -0800 | [diff] [blame] | 18 | package com.android.mail.ui; |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 19 | |
| 20 | import android.app.ActionBar; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 21 | import android.app.SearchManager; |
| 22 | import android.app.SearchableInfo; |
Vikram Aggarwal | 2175d0a | 2012-02-17 16:04:23 -0800 | [diff] [blame] | 23 | import android.app.ActionBar.OnNavigationListener; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Vikram Aggarwal | 12a7c04 | 2012-03-28 16:48:08 -0700 | [diff] [blame] | 25 | import android.database.Cursor; |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 26 | import android.os.Bundle; |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 27 | import android.os.Handler; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 28 | import android.util.AttributeSet; |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 29 | import android.view.Menu; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 30 | import android.view.MenuItem; |
| 31 | import android.view.View; |
| 32 | import android.widget.LinearLayout; |
| 33 | import android.widget.SearchView; |
| 34 | import android.widget.SearchView.OnQueryTextListener; |
Vikram Aggarwal | 12a7c04 | 2012-03-28 16:48:08 -0700 | [diff] [blame] | 35 | import android.widget.SearchView.OnSuggestionListener; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 36 | import android.widget.TextView; |
| 37 | import android.widget.Toast; |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 38 | |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 39 | import com.android.mail.R; |
| 40 | import com.android.mail.AccountSpinnerAdapter; |
| 41 | import com.android.mail.ConversationListContext; |
Vikram Aggarwal | a9b93f3 | 2012-02-23 14:51:58 -0800 | [diff] [blame] | 42 | import com.android.mail.providers.Account; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 43 | import com.android.mail.providers.UIProvider.AccountCapabilities; |
Marc Blank | edcab01 | 2012-04-04 12:42:38 -0700 | [diff] [blame^] | 44 | import com.android.mail.providers.UIProvider.FolderCapabilities; |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 45 | import com.android.mail.providers.UIProvider.LastSyncResult; |
Mindy Pereira | f9323cd | 2012-02-29 13:47:09 -0800 | [diff] [blame] | 46 | import com.android.mail.providers.Folder; |
Andy Huang | 0d64735 | 2012-03-21 21:48:16 -0700 | [diff] [blame] | 47 | import com.android.mail.utils.LogUtils; |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 48 | import com.android.mail.utils.Utils; |
Vikram Aggarwal | a9b93f3 | 2012-02-23 14:51:58 -0800 | [diff] [blame] | 49 | |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 50 | /** |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 51 | * View to manage the various states of the Mail Action Bar |
| 52 | * |
| 53 | * TODO(viki): Include ConversationSubjectDisplayer here as well. |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 54 | */ |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 55 | public final class ActionBarView extends LinearLayout implements OnNavigationListener, |
Vikram Aggarwal | 12a7c04 | 2012-03-28 16:48:08 -0700 | [diff] [blame] | 56 | ViewMode.ModeChangeListener, OnQueryTextListener, OnSuggestionListener { |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 57 | private ActionBar mActionBar; |
| 58 | private RestrictedActivity mActivity; |
Vikram Aggarwal | a799795 | 2012-03-09 10:30:13 -0800 | [diff] [blame] | 59 | private ActivityController mController; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 60 | private View mFolderView; |
| 61 | /** |
| 62 | * The current mode of the ActionBar. This references constants in {@link ViewMode} |
| 63 | */ |
| 64 | private int mMode = ViewMode.UNKNOWN; |
| 65 | |
| 66 | private MenuItem mSearch; |
| 67 | AccountSpinnerAdapter mSpinner; |
| 68 | /** |
| 69 | * The account currently being shown |
| 70 | */ |
| 71 | private Account mAccount; |
Marc Blank | edcab01 | 2012-04-04 12:42:38 -0700 | [diff] [blame^] | 72 | /** |
| 73 | * The folder currently being shown |
| 74 | */ |
| 75 | private Folder mFolder; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 76 | |
| 77 | // TODO(viki): This is a SnippetTextView in the Gmail source code. Resolve. |
| 78 | private TextView mSubjectView; |
| 79 | private SearchView mSearchWidget; |
| 80 | private MenuItem mHelpItem; |
Paul Westbrook | 517743e | 2012-03-22 10:40:46 -0700 | [diff] [blame] | 81 | private MenuItem mSendFeedbackItem; |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 82 | private MenuItem mRefreshItem; |
Marc Blank | edcab01 | 2012-04-04 12:42:38 -0700 | [diff] [blame^] | 83 | private MenuItem mFolderSettingsItem; |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 84 | private View mRefreshActionView; |
| 85 | private boolean mRefreshInProgress; |
| 86 | |
Andy Huang | 0d64735 | 2012-03-21 21:48:16 -0700 | [diff] [blame] | 87 | public static final String LOG_TAG = new LogUtils().getLogTag(); |
| 88 | |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 89 | private final Handler mHandler = new Handler(); |
| 90 | private final Runnable mInvalidateMenu = new Runnable() { |
| 91 | @Override |
| 92 | public void run() { |
| 93 | mActivity.invalidateOptionsMenu(); |
| 94 | } |
| 95 | }; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 96 | |
| 97 | public ActionBarView(Context context) { |
| 98 | this(context, null); |
| 99 | } |
| 100 | |
| 101 | public ActionBarView(Context context, AttributeSet attrs) { |
| 102 | this(context, attrs, 0); |
| 103 | } |
| 104 | |
| 105 | public ActionBarView(Context context, AttributeSet attrs, int defStyle) { |
| 106 | super(context, attrs, defStyle); |
| 107 | } |
| 108 | |
| 109 | public boolean onCreateOptionsMenu(Menu menu) { |
| 110 | // If the mode is valid, then set the initial menu |
| 111 | if (mMode == ViewMode.UNKNOWN) { |
| 112 | return false; |
| 113 | } |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 114 | mSearch = menu.findItem(R.id.search); |
| 115 | if (mSearch != null) { |
| 116 | mSearchWidget = (SearchView) mSearch.getActionView(); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 117 | SearchManager searchManager = (SearchManager) mActivity.getActivityContext() |
| 118 | .getSystemService(Context.SEARCH_SERVICE); |
Mindy Pereira | fb17849 | 2012-03-07 18:56:42 -0800 | [diff] [blame] | 119 | if (searchManager != null && mSearchWidget != null) { |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 120 | SearchableInfo info = searchManager.getSearchableInfo(mActivity.getComponentName()); |
| 121 | mSearchWidget.setSearchableInfo(info); |
| 122 | mSearchWidget.setOnQueryTextListener(this); |
Vikram Aggarwal | 12a7c04 | 2012-03-28 16:48:08 -0700 | [diff] [blame] | 123 | mSearchWidget.setOnSuggestionListener(this); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | mHelpItem = menu.findItem(R.id.help_info_menu_item); |
Paul Westbrook | 517743e | 2012-03-22 10:40:46 -0700 | [diff] [blame] | 127 | mSendFeedbackItem = menu.findItem(R.id.feedback_menu_item); |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 128 | mRefreshItem = menu.findItem(R.id.refresh); |
Marc Blank | edcab01 | 2012-04-04 12:42:38 -0700 | [diff] [blame^] | 129 | mFolderSettingsItem = menu.findItem(R.id.folder_options); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 130 | return true; |
| 131 | } |
| 132 | |
| 133 | public int getOptionsMenuId() { |
| 134 | // Relies on the ordering of the view modes, since they are integer constants. |
| 135 | final int[] modeMenu = { |
| 136 | // 0: UNKNOWN |
| 137 | R.menu.conversation_list_menu, |
| 138 | // 1: CONVERSATION |
| 139 | R.menu.conversation_actions, |
| 140 | // 2: CONVERSATION_LIST |
| 141 | R.menu.conversation_list_menu, |
| 142 | // 3: FOLDER_LIST |
| 143 | R.menu.folder_list_menu, |
| 144 | // 4: SEARCH_RESULTS_LIST |
| 145 | R.menu.conversation_list_search_results_actions, |
| 146 | // 5: SEARCH_RESULTS_CONVERSATION |
Mindy Pereira | b849dfb | 2012-03-07 18:13:15 -0800 | [diff] [blame] | 147 | R.menu.conversation_search_results_actions |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 148 | }; |
| 149 | return modeMenu[mMode]; |
| 150 | } |
| 151 | |
| 152 | public void handleRestore(Bundle savedInstanceState) { |
| 153 | } |
| 154 | |
| 155 | public void handleSaveInstanceState(Bundle outState) { |
| 156 | } |
| 157 | |
| 158 | public void initialize(RestrictedActivity activity, ActivityController callback, |
Vikram Aggarwal | ec5cbf7 | 2012-03-08 15:10:35 -0800 | [diff] [blame] | 159 | ViewMode viewMode, ActionBar actionBar, RecentFolderList recentFolders) { |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 160 | mActionBar = actionBar; |
Vikram Aggarwal | a799795 | 2012-03-09 10:30:13 -0800 | [diff] [blame] | 161 | mController = callback; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 162 | mActivity = activity; |
| 163 | |
Vikram Aggarwal | ec5cbf7 | 2012-03-08 15:10:35 -0800 | [diff] [blame] | 164 | mSpinner = new AccountSpinnerAdapter(getContext(), recentFolders); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 165 | // Set the mode to Navigation mode and listen on navigation changes. |
| 166 | mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); |
| 167 | mActionBar.setListNavigationCallbacks(mSpinner, this); |
| 168 | } |
| 169 | |
| 170 | public void setAccounts(Account[] accounts) { |
Vikram Aggarwal | a799795 | 2012-03-09 10:30:13 -0800 | [diff] [blame] | 171 | Account currentAccount = mController.getCurrentAccount(); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 172 | mSpinner.setAccounts(accounts); |
Andy Huang | 0d64735 | 2012-03-21 21:48:16 -0700 | [diff] [blame] | 173 | |
| 174 | int position; |
| 175 | for (position = 0; position < accounts.length; position++) { |
| 176 | if (accounts[position].equals(currentAccount)) { |
| 177 | break; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 178 | } |
| 179 | } |
Andy Huang | 0d64735 | 2012-03-21 21:48:16 -0700 | [diff] [blame] | 180 | if (position >= accounts.length) { |
| 181 | position = 0; |
| 182 | LogUtils.w(LOG_TAG, "IN actionbarview setAccounts, account not found, using first."); |
| 183 | } |
Vikram Aggarwal | 3a10473 | 2012-03-27 11:35:17 -0700 | [diff] [blame] | 184 | |
| 185 | setSelectedPosition(position); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Sets the selected navigation position in the spinner to the position given here. |
| 190 | * @param position |
| 191 | */ |
| 192 | private void setSelectedPosition(int position) { |
| 193 | // Only change the position if we are in the correct mode. |
| 194 | if (mActionBar.getNavigationMode() != ActionBar.NAVIGATION_MODE_LIST) |
| 195 | return; |
Andy Huang | 0d64735 | 2012-03-21 21:48:16 -0700 | [diff] [blame] | 196 | mActionBar.setSelectedNavigationItem(position); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 197 | } |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 198 | |
| 199 | /** |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 200 | * Called by the owner of the ActionBar to set the |
| 201 | * folder that is currently being displayed. |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 202 | */ |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 203 | public void setFolder(Folder folder) { |
Vikram Aggarwal | e6340bc | 2012-03-26 15:57:09 -0700 | [diff] [blame] | 204 | // Change the currently selected item to an element which is a spacer: valid but not useful |
| 205 | // This allows us to receive a tap on the account name when the user taps on it, and we can |
| 206 | // take the user to the default inbox. |
Vikram Aggarwal | 3a10473 | 2012-03-27 11:35:17 -0700 | [diff] [blame] | 207 | setSelectedPosition(mSpinner.getSpacerPosition()); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 208 | mSpinner.setCurrentFolder(folder); |
| 209 | mSpinner.notifyDataSetChanged(); |
Marc Blank | edcab01 | 2012-04-04 12:42:38 -0700 | [diff] [blame^] | 210 | mFolder = folder; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 211 | } |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 212 | |
| 213 | /** |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 214 | * Called by the owner of the ActionBar to set the |
| 215 | * account that is currently being displayed. |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 216 | */ |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 217 | public void setAccount(Account account) { |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 218 | mAccount = account; |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 219 | mSpinner.setCurrentAccount(account); |
| 220 | mSpinner.notifyDataSetChanged(); |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public boolean onNavigationItemSelected(int position, long id) { |
Marc Blank | 41e764d | 2012-03-20 20:46:28 -0700 | [diff] [blame] | 225 | final int type = mSpinner.getType(position); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 226 | switch (type) { |
| 227 | case AccountSpinnerAdapter.TYPE_ACCOUNT: |
| 228 | // Get the capabilities associated with this account. |
Marc Blank | 41e764d | 2012-03-20 20:46:28 -0700 | [diff] [blame] | 229 | final Object account = mSpinner.getItem(position); |
| 230 | assert (account instanceof Account); |
| 231 | mController.onAccountChanged((Account) account); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 232 | break; |
| 233 | case AccountSpinnerAdapter.TYPE_FOLDER: |
| 234 | final Object folder = mSpinner.getItem(position); |
| 235 | assert (folder instanceof Folder); |
Vikram Aggarwal | a799795 | 2012-03-09 10:30:13 -0800 | [diff] [blame] | 236 | mController.onFolderChanged((Folder) folder); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 237 | break; |
| 238 | } |
| 239 | return false; |
| 240 | } |
| 241 | |
| 242 | public void onPause() { |
| 243 | } |
| 244 | |
| 245 | public void onResume() { |
| 246 | } |
| 247 | |
Vikram Aggarwal | a799795 | 2012-03-09 10:30:13 -0800 | [diff] [blame] | 248 | @Override |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 249 | public void onViewModeChanged(int newMode) { |
| 250 | mMode = newMode; |
| 251 | // Always update the options menu and redraw. This will read the new mode and redraw |
| 252 | // the options menu. |
| 253 | mActivity.invalidateOptionsMenu(); |
| 254 | } |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 255 | |
Mindy Pereira | b849dfb | 2012-03-07 18:13:15 -0800 | [diff] [blame] | 256 | public boolean onPrepareOptionsMenu(Menu menu) { |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 257 | // We start out with every option enabled. Based on the current view, we disable actions |
| 258 | // that are possible. |
| 259 | if (mSubjectView != null){ |
| 260 | mSubjectView.setVisibility(GONE); |
| 261 | } |
| 262 | if (mFolderView != null){ |
| 263 | mFolderView.setVisibility(GONE); |
| 264 | } |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 265 | |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 266 | if (mRefreshInProgress) { |
| 267 | if (mRefreshItem != null) { |
| 268 | if (mRefreshActionView == null) { |
| 269 | mRefreshItem.setActionView(R.layout.action_bar_indeterminate_progress); |
| 270 | mRefreshActionView = mRefreshItem.getActionView(); |
| 271 | } else { |
| 272 | mRefreshItem.setActionView(mRefreshActionView); |
| 273 | } |
| 274 | } |
| 275 | } else { |
| 276 | if (mRefreshItem != null) { |
| 277 | mRefreshItem.setActionView(null); |
| 278 | } |
| 279 | } |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 280 | if (mHelpItem != null) { |
| 281 | mHelpItem.setVisible(mAccount != null |
| 282 | && mAccount.supportsCapability(AccountCapabilities.HELP_CONTENT)); |
| 283 | } |
Paul Westbrook | 517743e | 2012-03-22 10:40:46 -0700 | [diff] [blame] | 284 | if (mSendFeedbackItem != null) { |
| 285 | mSendFeedbackItem.setVisible(mAccount != null |
| 286 | && mAccount.supportsCapability(AccountCapabilities.SEND_FEEDBACK)); |
| 287 | } |
Marc Blank | edcab01 | 2012-04-04 12:42:38 -0700 | [diff] [blame^] | 288 | if (mFolderSettingsItem != null) { |
| 289 | mFolderSettingsItem.setVisible(mFolder != null |
| 290 | && mFolder.supportsCapability(FolderCapabilities.SUPPORTS_SETTINGS)); |
| 291 | } |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 292 | switch (mMode) { |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 293 | case ViewMode.UNKNOWN: |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 294 | if (mSearch != null) { |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 295 | mSearch.collapseActionView(); |
| 296 | } |
| 297 | break; |
| 298 | case ViewMode.CONVERSATION_LIST: |
Mindy Pereira | 30fd47b | 2012-03-09 09:24:00 -0800 | [diff] [blame] | 299 | // Show compose, search, folders, and sync based on the account |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 300 | // The only option that needs to be disabled is search |
Mindy Pereira | 72a9f39 | 2012-03-21 09:41:09 -0700 | [diff] [blame] | 301 | showNavList(); |
Mindy Pereira | 863e441 | 2012-03-23 12:21:38 -0700 | [diff] [blame] | 302 | Utils.setMenuItemVisibility(menu, R.id.search, |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 303 | mAccount.supportsCapability(AccountCapabilities.FOLDER_SERVER_SEARCH)); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 304 | break; |
| 305 | case ViewMode.CONVERSATION: |
Mindy Pereira | 72a9f39 | 2012-03-21 09:41:09 -0700 | [diff] [blame] | 306 | mActionBar.setDisplayHomeAsUpEnabled(true); |
| 307 | showNavList(); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 308 | break; |
| 309 | case ViewMode.SEARCH_RESULTS_LIST: |
Mindy Pereira | 72a9f39 | 2012-03-21 09:41:09 -0700 | [diff] [blame] | 310 | showNavList(); |
Mindy Pereira | b849dfb | 2012-03-07 18:13:15 -0800 | [diff] [blame] | 311 | setPopulatedSearchView(); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 312 | break; |
| 313 | case ViewMode.SEARCH_RESULTS_CONVERSATION: |
| 314 | mActionBar.setDisplayHomeAsUpEnabled(true); |
Mindy Pereira | 72a9f39 | 2012-03-21 09:41:09 -0700 | [diff] [blame] | 315 | showNavList(); |
Mindy Pereira | b849dfb | 2012-03-07 18:13:15 -0800 | [diff] [blame] | 316 | if (Utils.useTabletUI(mActivity.getActivityContext())) { |
| 317 | setPopulatedSearchView(); |
| 318 | } |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 319 | break; |
| 320 | case ViewMode.FOLDER_LIST: |
Mindy Pereira | 72a9f39 | 2012-03-21 09:41:09 -0700 | [diff] [blame] | 321 | mActionBar.setDisplayHomeAsUpEnabled(true); |
| 322 | mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, |
| 323 | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM); |
| 324 | mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); |
| 325 | mActionBar.setTitle(R.string.folder_list_title); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 326 | break; |
| 327 | } |
| 328 | return false; |
| 329 | } |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 330 | |
Mindy Pereira | 72a9f39 | 2012-03-21 09:41:09 -0700 | [diff] [blame] | 331 | private void showNavList() { |
| 332 | mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); |
| 333 | mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, |
| 334 | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM); |
| 335 | } |
| 336 | |
Mindy Pereira | b849dfb | 2012-03-07 18:13:15 -0800 | [diff] [blame] | 337 | private void setPopulatedSearchView() { |
| 338 | if (mSearch != null) { |
| 339 | mSearch.expandActionView(); |
Vikram Aggarwal | a799795 | 2012-03-09 10:30:13 -0800 | [diff] [blame] | 340 | ConversationListContext context = mController.getCurrentListContext(); |
Mindy Pereira | b849dfb | 2012-03-07 18:13:15 -0800 | [diff] [blame] | 341 | if (context != null) { |
| 342 | mSearchWidget.setQuery(context.searchQuery, false); |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 347 | public void removeBackButton() { |
| 348 | if (mActionBar == null) { |
| 349 | return; |
| 350 | } |
| 351 | mActionBar.setDisplayOptions( |
| 352 | ActionBar.DISPLAY_SHOW_HOME, |
| 353 | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME); |
| 354 | mActivity.getActionBar().setHomeButtonEnabled(false); |
| 355 | } |
Mindy Pereira | bc57bf1 | 2012-02-29 14:39:09 -0800 | [diff] [blame] | 356 | |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 357 | public void setBackButton() { |
| 358 | if (mActionBar == null){ |
| 359 | return; |
| 360 | } |
| 361 | mActionBar.setDisplayOptions( |
| 362 | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME, |
| 363 | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME); |
| 364 | mActivity.getActionBar().setHomeButtonEnabled(true); |
| 365 | } |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 366 | |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 367 | @Override |
| 368 | public boolean onQueryTextSubmit(String query) { |
Mindy Pereira | 4ce5994 | 2012-03-08 09:57:35 -0800 | [diff] [blame] | 369 | if (mSearch != null) { |
| 370 | mSearch.collapseActionView(); |
| 371 | mSearchWidget.setQuery("", false); |
| 372 | } |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 373 | mActivity.onSearchRequested(query); |
| 374 | return true; |
| 375 | } |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 376 | |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 377 | @Override |
| 378 | public boolean onQueryTextChange(String newText) { |
| 379 | // TODO Auto-generated method stub |
| 380 | return false; |
| 381 | } |
Mindy Pereira | 9b62380 | 2012-03-07 17:15:49 -0800 | [diff] [blame] | 382 | |
| 383 | public boolean setRefreshInProgress(boolean inProgress) { |
| 384 | if (inProgress != mRefreshInProgress) { |
| 385 | mRefreshInProgress = inProgress; |
| 386 | if (mSearch == null || !mSearch.isActionViewExpanded()) { |
| 387 | mHandler.post(mInvalidateMenu); |
| 388 | } |
| 389 | return true; |
| 390 | } |
| 391 | return false; |
| 392 | } |
| 393 | |
| 394 | public void onRefreshStarted() { |
| 395 | setRefreshInProgress(true); |
| 396 | } |
| 397 | |
| 398 | public void onRefreshStopped(int status) { |
| 399 | if (setRefreshInProgress(false)) { |
| 400 | switch (status) { |
| 401 | case LastSyncResult.SUCCESS: |
| 402 | break; |
| 403 | default: |
| 404 | Context context = mActivity.getActivityContext(); |
| 405 | Toast.makeText(context, Utils.getSyncStatusText(context, status), |
| 406 | Toast.LENGTH_LONG).show(); |
| 407 | break; |
| 408 | } |
| 409 | } |
| 410 | } |
Mindy Pereira | fd0c297 | 2012-03-27 13:50:39 -0700 | [diff] [blame] | 411 | |
| 412 | /** |
| 413 | * Get the query text the user entered in the search widget, or empty string |
| 414 | * if there is none. |
| 415 | */ |
| 416 | public String getQuery() { |
| 417 | return mSearchWidget != null ? mSearchWidget.getQuery().toString() : ""; |
| 418 | } |
Vikram Aggarwal | 12a7c04 | 2012-03-28 16:48:08 -0700 | [diff] [blame] | 419 | |
| 420 | // Next two methods are called when search suggestions are clicked. |
| 421 | @Override |
| 422 | public boolean onSuggestionSelect(int position) { |
| 423 | return onSuggestionClick(position); |
| 424 | } |
| 425 | |
| 426 | @Override |
| 427 | public boolean onSuggestionClick(int position) { |
| 428 | final Cursor c = mSearchWidget.getSuggestionsAdapter().getCursor(); |
| 429 | final boolean haveValidQuery = (c != null) && c.moveToPosition(position); |
| 430 | if (!haveValidQuery) { |
| 431 | LogUtils.d(LOG_TAG, "onSuggestionClick: Couldn't get a search query"); |
| 432 | // We haven't handled this query, but the default behavior will leave EXTRA_ACCOUNT |
| 433 | // un-populated, leading to a crash. So claim that we have handled the event. |
| 434 | return true; |
| 435 | } |
| 436 | final String query = c.getString(c.getColumnIndex(SearchManager.SUGGEST_COLUMN_QUERY)); |
| 437 | mController.onSearchRequested(query); |
| 438 | return true; |
| 439 | } |
Mindy Pereira | a46a57f | 2012-04-03 17:19:31 -0700 | [diff] [blame] | 440 | |
| 441 | /** |
| 442 | * Notify that the folder has changed. |
| 443 | */ |
| 444 | public void onFolderUpdated(Folder folder) { |
| 445 | mSpinner.onFolderUpdated(folder); |
| 446 | } |
Vikram Aggarwal | 5e5ac74 | 2011-12-19 08:14:16 -0800 | [diff] [blame] | 447 | } |