@Override public boolean onQueryTextSubmit(String query) { if (mSearch != null) { mSearch.collapseActionView(); mSearchWidget.setQuery("", false); } mController.executeSearch(query.trim()); return true; }
/** Notify that the folder has changed. */ public void onFolderUpdated(Folder folder) { if (folder == null) { return; } /** True if we are changing folders. */ final boolean changingFolders = (mFolder == null || !mFolder.equals(folder)); mFolder = folder; setFolderAndAccount(changingFolders); final ConversationListContext listContext = mController == null ? null : mController.getCurrentListContext(); if (changingFolders && !ConversationListContext.isSearchResult(listContext)) { closeSearchField(); } }
@Override public boolean onSuggestionClick(int position) { final Cursor c = mSearchWidget.getSuggestionsAdapter().getCursor(); final boolean haveValidQuery = (c != null) && c.moveToPosition(position); if (!haveValidQuery) { LogUtils.d(LOG_TAG, "onSuggestionClick: Couldn't get a search query"); // We haven't handled this query, but the default behavior will // leave EXTRA_ACCOUNT un-populated, leading to a crash. So claim // that we have handled the event. return true; } collapseSearch(); // what is in the text field String queryText = mSearchWidget.getQuery().toString(); // What the suggested query is String query = c.getString(c.getColumnIndex(SearchManager.SUGGEST_COLUMN_QUERY)); // If the text the user typed in is a prefix of what is in the search // widget suggestion query, just take the search widget suggestion // query. Otherwise, it is a suffix and we want to remove matching // prefix portions. if (!TextUtils.isEmpty(queryText) && query.indexOf(queryText) != 0) { final int queryTokenIndex = queryText.lastIndexOf(SearchRecentSuggestionsProvider.QUERY_TOKEN_SEPARATOR); if (queryTokenIndex > -1) { queryText = queryText.substring(0, queryTokenIndex); } // Since we auto-complete on each token in a query, if the query the // user typed up until the last token is a substring of the // suggestion they click, make sure we don't double include the // query text. For example: // user types john, that matches john palo alto // User types john p, that matches john john palo alto // Remove the first john // Only do this if we have multiple query tokens. if (queryTokenIndex > -1 && !TextUtils.isEmpty(query) && query.contains(queryText) && queryText.length() < query.length()) { int start = query.indexOf(queryText); query = query.substring(0, start) + query.substring(start + queryText.length()); } } mController.executeSearch(query.trim()); return true; }
private void initializeTitleViews() { mLegacyTitleContainer = findViewById(R.id.legacy_title_container); if (mLegacyTitleContainer != 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 mLegacyTitleContainer.setVisibility(View.GONE); mUseLegacyTitle = false; } else { mUseLegacyTitle = true; // We need to show the legacy title/subtitle. Set the click listener mLegacyTitleContainer.setOnClickListener(this); mLegacyTitle = (TextView) mLegacyTitleContainer.findViewById(R.id.legacy_title); mLegacySubTitle = (TextView) mLegacyTitleContainer.findViewById(R.id.legacy_subtitle); } } }
@Override public void onClick(View v) { if (v.getId() == R.id.legacy_title_container) { mController.onUpPressed(); } }
public boolean onPrepareOptionsMenu(Menu menu) { // We start out with every option enabled. Based on the current view, we disable actions // that are possible. LogUtils.d(LOG_TAG, "ActionBarView.onPrepareOptionsMenu()."); if (mHelpItem != null) { mHelpItem.setVisible( mAccount != null && mAccount.supportsCapability(AccountCapabilities.HELP_CONTENT)); } if (mSendFeedbackItem != null) { mSendFeedbackItem.setVisible( mAccount != null && mAccount.supportsCapability(AccountCapabilities.SEND_FEEDBACK)); } if (mController.shouldHideMenuItems()) { // Shortcut: hide all remaining menu items if the drawer is shown final int size = menu.size(); for (int i = 0; i < size; i++) { final MenuItem item = menu.getItem(i); final int id = item.getItemId(); if (id != R.id.settings && id != R.id.feedback_menu_item && id != R.id.help_info_menu_item) { item.setVisible(false); } } return false; } if (mRefreshItem != null) { // See b/11158759 // Disable refresh on drafts folders. mRefreshItem.setVisible( mFolder != null && !mFolder.isDraft() && !mFolder.supportsCapability(FolderCapabilities.IS_VIRTUAL)); } if (mFolderSettingsItem != null) { mFolderSettingsItem.setVisible( mFolder != null && mFolder.supportsCapability(FolderCapabilities.SUPPORTS_SETTINGS)); } if (mEmptyTrashItem != null) { mEmptyTrashItem.setVisible( mAccount != null && mFolder != null && mAccount.supportsCapability(AccountCapabilities.EMPTY_TRASH) && mFolder.isTrash() && mFolder.totalCount > 0); } if (mEmptySpamItem != null) { mEmptySpamItem.setVisible( mAccount != null && mFolder != null && mAccount.supportsCapability(AccountCapabilities.EMPTY_SPAM) && mFolder.isType(FolderType.SPAM) && mFolder.totalCount > 0); } switch (mMode) { case ViewMode.CONVERSATION: case ViewMode.SEARCH_RESULTS_CONVERSATION: // We update the ActionBar options when we are entering conversation view because // waiting for the AbstractConversationViewFragment to do it causes duplicate icons // to show up during the time between the conversation is selected and the fragment // is added. setConversationModeOptions(menu); // We want to use the user's preferred menu items here final Resources resources = getResources(); final int maxItems = resources.getInteger(R.integer.actionbar_max_items); final int hiddenItems = resources.getInteger(R.integer.actionbar_hidden_non_cab_items_no_physical_button); final int totalItems = maxItems - (ViewConfiguration.get(getContext()).hasPermanentMenuKey() ? 0 : hiddenItems); reorderMenu(getContext(), mAccount, menu, totalItems); break; case ViewMode.CONVERSATION_LIST: // Show compose and search based on the account // The only option that needs to be disabled is search Utils.setMenuItemVisibility( menu, R.id.search, mAccount.supportsCapability(AccountCapabilities.FOLDER_SERVER_SEARCH)); break; case ViewMode.SEARCH_RESULTS_LIST: // Hide compose and search Utils.setMenuItemVisibility(menu, R.id.compose, false); Utils.setMenuItemVisibility(menu, R.id.search, false); break; } return false; }