private boolean isSubmitAreaEnabled() { return (mSubmitButtonEnabled || mVoiceButtonEnabled) && !isIconified(); }
/** * Update the visibility of the voice button. There are actually two voice search modes, * either of which will activate the button. * @param empty whether the search query text field is empty. If it is, then the other * criteria apply to make the voice button visible. */ private void updateVoiceButton(boolean empty) { int visibility = GONE; if (mVoiceButtonEnabled && !isIconified() && empty) { visibility = VISIBLE; mSubmitButton.setVisibility(GONE); } mVoiceButton.setVisibility(visibility); }
/** * Enables showing a submit button when the query is non-empty. In cases where the SearchView * is being used to filter the contents of the current activity and doesn't launch a separate * results activity, then the submit button should be disabled. * * @param enabled true to show a submit button for submitting queries, false if a submit * button is not required. */ public void setSubmitButtonEnabled(boolean enabled) { mSubmitButtonEnabled = enabled; updateViewsVisibility(isIconified()); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (isIconified()) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); return;
void onTextFocusChanged() { updateViewsVisibility(isIconified()); // Delayed update to make sure that the focus has settled down and window focus changes // don't affect it. A synchronous update was not working. postUpdateFocusedState(); if (mQueryTextView.hasFocus()) { forceSuggestionQuery(); } }
/** @hide */ @Override public boolean requestFocus(int direction, Rect previouslyFocusedRect) { // Don't accept focus if in the middle of clearing focus if (mClearingFocus) return false; // Check if SearchView is focusable. if (!isFocusable()) return false; // If it is not iconified, then give the focus to the text field if (!isIconified()) { boolean result = mQueryTextView.requestFocus(direction, previouslyFocusedRect); if (result) { updateViewsVisibility(false); } return result; } else { return super.requestFocus(direction, previouslyFocusedRect); } }
/** * Sets the SearchableInfo for this SearchView. Properties in the SearchableInfo are used * to display labels, hints, suggestions, create intents for launching search results screens * and controlling other affordances such as a voice button. * * @param searchable a SearchableInfo can be retrieved from the SearchManager, for a specific * activity or a global search provider. */ public void setSearchableInfo(SearchableInfo searchable) { mSearchable = searchable; if (mSearchable != null) { updateSearchAutoComplete(); updateQueryHint(); } // Cache the voice search capability mVoiceButtonEnabled = hasVoiceSearch(); if (mVoiceButtonEnabled) { // Disable the microphone on the keyboard, as a mic is displayed near the text box // TODO: use imeOptions to disable voice input when the new API will be available mQueryTextView.setPrivateImeOptions(IME_OPTION_NO_MICROPHONE); } updateViewsVisibility(isIconified()); }