blob: f00a99dc6d3e8fbfdde71437ad0be3ff8e39f307 [file] [log] [blame]
Mindy Pereira68f2e222012-03-07 10:36:54 -08001/*
2 * Copyright (C) 2012 Google Inc.
3 * Licensed to The Android Open Source Project.
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -08004 *
Mindy Pereira68f2e222012-03-07 10:36:54 -08005 * 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 Aggarwal5e5ac742011-12-19 08:14:16 -08008 *
Mindy Pereira68f2e222012-03-07 10:36:54 -08009 * http://www.apache.org/licenses/LICENSE-2.0
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -080010 *
Mindy Pereira68f2e222012-03-07 10:36:54 -080011 * 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 Aggarwal5e5ac742011-12-19 08:14:16 -080017
Vikram Aggarwal1ddcf0f2012-01-13 11:45:02 -080018package com.android.mail.ui;
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -080019
20import android.app.ActionBar;
Mindy Pereira68f2e222012-03-07 10:36:54 -080021import android.app.SearchManager;
22import android.app.SearchableInfo;
Vikram Aggarwal2175d0a2012-02-17 16:04:23 -080023import android.app.ActionBar.OnNavigationListener;
Mindy Pereira68f2e222012-03-07 10:36:54 -080024import android.content.Context;
Vikram Aggarwal12a7c042012-03-28 16:48:08 -070025import android.database.Cursor;
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -080026import android.os.Bundle;
Mindy Pereira9b623802012-03-07 17:15:49 -080027import android.os.Handler;
Mindy Pereira68f2e222012-03-07 10:36:54 -080028import android.util.AttributeSet;
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -080029import android.view.Menu;
Mindy Pereira68f2e222012-03-07 10:36:54 -080030import android.view.MenuItem;
31import android.view.View;
32import android.widget.LinearLayout;
33import android.widget.SearchView;
34import android.widget.SearchView.OnQueryTextListener;
Vikram Aggarwal12a7c042012-03-28 16:48:08 -070035import android.widget.SearchView.OnSuggestionListener;
Mindy Pereira68f2e222012-03-07 10:36:54 -080036import android.widget.TextView;
37import android.widget.Toast;
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -080038
Mindy Pereira68f2e222012-03-07 10:36:54 -080039import com.android.mail.R;
40import com.android.mail.AccountSpinnerAdapter;
41import com.android.mail.ConversationListContext;
Vikram Aggarwala9b93f32012-02-23 14:51:58 -080042import com.android.mail.providers.Account;
Mindy Pereira68f2e222012-03-07 10:36:54 -080043import com.android.mail.providers.UIProvider.AccountCapabilities;
Marc Blankedcab012012-04-04 12:42:38 -070044import com.android.mail.providers.UIProvider.FolderCapabilities;
Mindy Pereira9b623802012-03-07 17:15:49 -080045import com.android.mail.providers.UIProvider.LastSyncResult;
Mindy Pereiraf9323cd2012-02-29 13:47:09 -080046import com.android.mail.providers.Folder;
Andy Huang0d647352012-03-21 21:48:16 -070047import com.android.mail.utils.LogUtils;
Mindy Pereira9b623802012-03-07 17:15:49 -080048import com.android.mail.utils.Utils;
Vikram Aggarwala9b93f32012-02-23 14:51:58 -080049
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -080050/**
Mindy Pereira68f2e222012-03-07 10:36:54 -080051 * View to manage the various states of the Mail Action Bar
52 *
53 * TODO(viki): Include ConversationSubjectDisplayer here as well.
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -080054 */
Mindy Pereira68f2e222012-03-07 10:36:54 -080055public final class ActionBarView extends LinearLayout implements OnNavigationListener,
Vikram Aggarwal12a7c042012-03-28 16:48:08 -070056 ViewMode.ModeChangeListener, OnQueryTextListener, OnSuggestionListener {
Mindy Pereira68f2e222012-03-07 10:36:54 -080057 private ActionBar mActionBar;
58 private RestrictedActivity mActivity;
Vikram Aggarwala7997952012-03-09 10:30:13 -080059 private ActivityController mController;
Mindy Pereira68f2e222012-03-07 10:36:54 -080060 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 Blankedcab012012-04-04 12:42:38 -070072 /**
73 * The folder currently being shown
74 */
75 private Folder mFolder;
Mindy Pereira68f2e222012-03-07 10:36:54 -080076
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 Westbrook517743e2012-03-22 10:40:46 -070081 private MenuItem mSendFeedbackItem;
Mindy Pereira9b623802012-03-07 17:15:49 -080082 private MenuItem mRefreshItem;
Marc Blankedcab012012-04-04 12:42:38 -070083 private MenuItem mFolderSettingsItem;
Mindy Pereira9b623802012-03-07 17:15:49 -080084 private View mRefreshActionView;
85 private boolean mRefreshInProgress;
86
Andy Huang0d647352012-03-21 21:48:16 -070087 public static final String LOG_TAG = new LogUtils().getLogTag();
88
Mindy Pereira9b623802012-03-07 17:15:49 -080089 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 Pereira68f2e222012-03-07 10:36:54 -080096
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 Pereira9b623802012-03-07 17:15:49 -0800114 mSearch = menu.findItem(R.id.search);
115 if (mSearch != null) {
116 mSearchWidget = (SearchView) mSearch.getActionView();
Mindy Pereira68f2e222012-03-07 10:36:54 -0800117 SearchManager searchManager = (SearchManager) mActivity.getActivityContext()
118 .getSystemService(Context.SEARCH_SERVICE);
Mindy Pereirafb178492012-03-07 18:56:42 -0800119 if (searchManager != null && mSearchWidget != null) {
Mindy Pereira68f2e222012-03-07 10:36:54 -0800120 SearchableInfo info = searchManager.getSearchableInfo(mActivity.getComponentName());
121 mSearchWidget.setSearchableInfo(info);
122 mSearchWidget.setOnQueryTextListener(this);
Vikram Aggarwal12a7c042012-03-28 16:48:08 -0700123 mSearchWidget.setOnSuggestionListener(this);
Mindy Pereira68f2e222012-03-07 10:36:54 -0800124 }
125 }
126 mHelpItem = menu.findItem(R.id.help_info_menu_item);
Paul Westbrook517743e2012-03-22 10:40:46 -0700127 mSendFeedbackItem = menu.findItem(R.id.feedback_menu_item);
Mindy Pereira9b623802012-03-07 17:15:49 -0800128 mRefreshItem = menu.findItem(R.id.refresh);
Marc Blankedcab012012-04-04 12:42:38 -0700129 mFolderSettingsItem = menu.findItem(R.id.folder_options);
Mindy Pereira68f2e222012-03-07 10:36:54 -0800130 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 Pereirab849dfb2012-03-07 18:13:15 -0800147 R.menu.conversation_search_results_actions
Mindy Pereira68f2e222012-03-07 10:36:54 -0800148 };
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 Aggarwalec5cbf72012-03-08 15:10:35 -0800159 ViewMode viewMode, ActionBar actionBar, RecentFolderList recentFolders) {
Mindy Pereira68f2e222012-03-07 10:36:54 -0800160 mActionBar = actionBar;
Vikram Aggarwala7997952012-03-09 10:30:13 -0800161 mController = callback;
Mindy Pereira68f2e222012-03-07 10:36:54 -0800162 mActivity = activity;
163
Vikram Aggarwalec5cbf72012-03-08 15:10:35 -0800164 mSpinner = new AccountSpinnerAdapter(getContext(), recentFolders);
Mindy Pereira68f2e222012-03-07 10:36:54 -0800165 // 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 Aggarwala7997952012-03-09 10:30:13 -0800171 Account currentAccount = mController.getCurrentAccount();
Mindy Pereira68f2e222012-03-07 10:36:54 -0800172 mSpinner.setAccounts(accounts);
Andy Huang0d647352012-03-21 21:48:16 -0700173
174 int position;
175 for (position = 0; position < accounts.length; position++) {
176 if (accounts[position].equals(currentAccount)) {
177 break;
Mindy Pereira68f2e222012-03-07 10:36:54 -0800178 }
179 }
Andy Huang0d647352012-03-21 21:48:16 -0700180 if (position >= accounts.length) {
181 position = 0;
182 LogUtils.w(LOG_TAG, "IN actionbarview setAccounts, account not found, using first.");
183 }
Vikram Aggarwal3a104732012-03-27 11:35:17 -0700184
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 Huang0d647352012-03-21 21:48:16 -0700196 mActionBar.setSelectedNavigationItem(position);
Mindy Pereira68f2e222012-03-07 10:36:54 -0800197 }
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -0800198
199 /**
Mindy Pereira68f2e222012-03-07 10:36:54 -0800200 * Called by the owner of the ActionBar to set the
201 * folder that is currently being displayed.
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -0800202 */
Mindy Pereira68f2e222012-03-07 10:36:54 -0800203 public void setFolder(Folder folder) {
Vikram Aggarwale6340bc2012-03-26 15:57:09 -0700204 // 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 Aggarwal3a104732012-03-27 11:35:17 -0700207 setSelectedPosition(mSpinner.getSpacerPosition());
Mindy Pereira68f2e222012-03-07 10:36:54 -0800208 mSpinner.setCurrentFolder(folder);
209 mSpinner.notifyDataSetChanged();
Marc Blankedcab012012-04-04 12:42:38 -0700210 mFolder = folder;
Mindy Pereira68f2e222012-03-07 10:36:54 -0800211 }
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -0800212
213 /**
Mindy Pereira68f2e222012-03-07 10:36:54 -0800214 * Called by the owner of the ActionBar to set the
215 * account that is currently being displayed.
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -0800216 */
Mindy Pereira68f2e222012-03-07 10:36:54 -0800217 public void setAccount(Account account) {
Mindy Pereira9b623802012-03-07 17:15:49 -0800218 mAccount = account;
Mindy Pereira68f2e222012-03-07 10:36:54 -0800219 mSpinner.setCurrentAccount(account);
220 mSpinner.notifyDataSetChanged();
221 }
222
223 @Override
224 public boolean onNavigationItemSelected(int position, long id) {
Marc Blank41e764d2012-03-20 20:46:28 -0700225 final int type = mSpinner.getType(position);
Mindy Pereira68f2e222012-03-07 10:36:54 -0800226 switch (type) {
227 case AccountSpinnerAdapter.TYPE_ACCOUNT:
228 // Get the capabilities associated with this account.
Marc Blank41e764d2012-03-20 20:46:28 -0700229 final Object account = mSpinner.getItem(position);
230 assert (account instanceof Account);
231 mController.onAccountChanged((Account) account);
Mindy Pereira68f2e222012-03-07 10:36:54 -0800232 break;
233 case AccountSpinnerAdapter.TYPE_FOLDER:
234 final Object folder = mSpinner.getItem(position);
235 assert (folder instanceof Folder);
Vikram Aggarwala7997952012-03-09 10:30:13 -0800236 mController.onFolderChanged((Folder) folder);
Mindy Pereira68f2e222012-03-07 10:36:54 -0800237 break;
238 }
239 return false;
240 }
241
242 public void onPause() {
243 }
244
245 public void onResume() {
246 }
247
Vikram Aggarwala7997952012-03-09 10:30:13 -0800248 @Override
Mindy Pereira68f2e222012-03-07 10:36:54 -0800249 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 Aggarwal5e5ac742011-12-19 08:14:16 -0800255
Mindy Pereirab849dfb2012-03-07 18:13:15 -0800256 public boolean onPrepareOptionsMenu(Menu menu) {
Mindy Pereira68f2e222012-03-07 10:36:54 -0800257 // 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 Aggarwal5e5ac742011-12-19 08:14:16 -0800265
Mindy Pereira9b623802012-03-07 17:15:49 -0800266 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 Pereira68f2e222012-03-07 10:36:54 -0800280 if (mHelpItem != null) {
281 mHelpItem.setVisible(mAccount != null
282 && mAccount.supportsCapability(AccountCapabilities.HELP_CONTENT));
283 }
Paul Westbrook517743e2012-03-22 10:40:46 -0700284 if (mSendFeedbackItem != null) {
285 mSendFeedbackItem.setVisible(mAccount != null
286 && mAccount.supportsCapability(AccountCapabilities.SEND_FEEDBACK));
287 }
Marc Blankedcab012012-04-04 12:42:38 -0700288 if (mFolderSettingsItem != null) {
289 mFolderSettingsItem.setVisible(mFolder != null
290 && mFolder.supportsCapability(FolderCapabilities.SUPPORTS_SETTINGS));
291 }
Mindy Pereira9b623802012-03-07 17:15:49 -0800292 switch (mMode) {
Mindy Pereira68f2e222012-03-07 10:36:54 -0800293 case ViewMode.UNKNOWN:
Mindy Pereira9b623802012-03-07 17:15:49 -0800294 if (mSearch != null) {
Mindy Pereira68f2e222012-03-07 10:36:54 -0800295 mSearch.collapseActionView();
296 }
297 break;
298 case ViewMode.CONVERSATION_LIST:
Mindy Pereira30fd47b2012-03-09 09:24:00 -0800299 // Show compose, search, folders, and sync based on the account
Mindy Pereira68f2e222012-03-07 10:36:54 -0800300 // The only option that needs to be disabled is search
Mindy Pereira72a9f392012-03-21 09:41:09 -0700301 showNavList();
Mindy Pereira863e4412012-03-23 12:21:38 -0700302 Utils.setMenuItemVisibility(menu, R.id.search,
Mindy Pereira9b623802012-03-07 17:15:49 -0800303 mAccount.supportsCapability(AccountCapabilities.FOLDER_SERVER_SEARCH));
Mindy Pereira68f2e222012-03-07 10:36:54 -0800304 break;
305 case ViewMode.CONVERSATION:
Mindy Pereira72a9f392012-03-21 09:41:09 -0700306 mActionBar.setDisplayHomeAsUpEnabled(true);
307 showNavList();
Mindy Pereira68f2e222012-03-07 10:36:54 -0800308 break;
309 case ViewMode.SEARCH_RESULTS_LIST:
Mindy Pereira72a9f392012-03-21 09:41:09 -0700310 showNavList();
Mindy Pereirab849dfb2012-03-07 18:13:15 -0800311 setPopulatedSearchView();
Mindy Pereira68f2e222012-03-07 10:36:54 -0800312 break;
313 case ViewMode.SEARCH_RESULTS_CONVERSATION:
314 mActionBar.setDisplayHomeAsUpEnabled(true);
Mindy Pereira72a9f392012-03-21 09:41:09 -0700315 showNavList();
Mindy Pereirab849dfb2012-03-07 18:13:15 -0800316 if (Utils.useTabletUI(mActivity.getActivityContext())) {
317 setPopulatedSearchView();
318 }
Mindy Pereira68f2e222012-03-07 10:36:54 -0800319 break;
320 case ViewMode.FOLDER_LIST:
Mindy Pereira72a9f392012-03-21 09:41:09 -0700321 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 Pereira68f2e222012-03-07 10:36:54 -0800326 break;
327 }
328 return false;
329 }
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -0800330
Mindy Pereira72a9f392012-03-21 09:41:09 -0700331 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 Pereirab849dfb2012-03-07 18:13:15 -0800337 private void setPopulatedSearchView() {
338 if (mSearch != null) {
339 mSearch.expandActionView();
Vikram Aggarwala7997952012-03-09 10:30:13 -0800340 ConversationListContext context = mController.getCurrentListContext();
Mindy Pereirab849dfb2012-03-07 18:13:15 -0800341 if (context != null) {
342 mSearchWidget.setQuery(context.searchQuery, false);
343 }
344 }
345 }
346
Mindy Pereira68f2e222012-03-07 10:36:54 -0800347 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 Pereirabc57bf12012-02-29 14:39:09 -0800356
Mindy Pereira68f2e222012-03-07 10:36:54 -0800357 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 Aggarwal5e5ac742011-12-19 08:14:16 -0800366
Mindy Pereira68f2e222012-03-07 10:36:54 -0800367 @Override
368 public boolean onQueryTextSubmit(String query) {
Mindy Pereira4ce59942012-03-08 09:57:35 -0800369 if (mSearch != null) {
370 mSearch.collapseActionView();
371 mSearchWidget.setQuery("", false);
372 }
Mindy Pereira68f2e222012-03-07 10:36:54 -0800373 mActivity.onSearchRequested(query);
374 return true;
375 }
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -0800376
Mindy Pereira68f2e222012-03-07 10:36:54 -0800377 @Override
378 public boolean onQueryTextChange(String newText) {
379 // TODO Auto-generated method stub
380 return false;
381 }
Mindy Pereira9b623802012-03-07 17:15:49 -0800382
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 Pereirafd0c2972012-03-27 13:50:39 -0700411
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 Aggarwal12a7c042012-03-28 16:48:08 -0700419
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 Pereiraa46a57f2012-04-03 17:19:31 -0700440
441 /**
442 * Notify that the folder has changed.
443 */
444 public void onFolderUpdated(Folder folder) {
445 mSpinner.onFolderUpdated(folder);
446 }
Vikram Aggarwal5e5ac742011-12-19 08:14:16 -0800447}