+ mQueryTextView.getListSelection()); if (mQueryTextView.isPopupShowing() && mQueryTextView.getListSelection() != ListView.INVALID_POSITION) { return onSuggestionsKey(v, keyCode, event); launchQuerySearch(KeyEvent.KEYCODE_UNKNOWN, null, mQueryTextView.getText() .toString()); return true;
mQueryTextView.setSearchView(this); mSubmitButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mQueryTextView.setOnClickListener(mOnClickListener); mQueryTextView.addTextChangedListener(mTextWatcher); mQueryTextView.setOnEditorActionListener(mOnEditorActionListener); mQueryTextView.setOnItemClickListener(mOnItemClickListener); mQueryTextView.setOnItemSelectedListener(mOnItemSelectedListener); mQueryTextView.setOnKeyListener(mTextKeyListener); mQueryTextView.setOnFocusChangeListener(new OnFocusChangeListener() { mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mQueryTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
/** * Sets a query string in the text field and optionally submits the query as well. * * @param query the query string. This replaces any query text already present in the * text field. * @param submit whether to submit the query right now or only update the contents of * text field. */ public void setQuery(CharSequence query, boolean submit) { mQueryTextView.setText(query); if (query != null) { mQueryTextView.setSelection(mQueryTextView.length()); mUserQuery = query; } // If the query is not empty and submit is requested, submit the query if (submit && !TextUtils.isEmpty(query)) { onSubmitQuery(); } }
int position = mQueryTextView.getListSelection(); return onItemClicked(position, KeyEvent.KEYCODE_UNKNOWN, null); .length(); mQueryTextView.setSelection(selPoint); mQueryTextView.setListSelection(0); mQueryTextView.clearListSelection(); ensureImeVisible(mQueryTextView, true); if (keyCode == KeyEvent.KEYCODE_DPAD_UP && 0 == mQueryTextView.getListSelection()) {
mQueryTextView.setThreshold(mSearchable.getSuggestThreshold()); mQueryTextView.setImeOptions(mSearchable.getImeOptions()); int inputType = mSearchable.getInputType(); mQueryTextView.setInputType(inputType); if (mSuggestionsAdapter != null) { mSuggestionsAdapter.changeCursor(null); mSuggestionsAdapter = new SuggestionsAdapter(getContext(), this, mSearchable, mOutsideDrawablesCache); mQueryTextView.setAdapter(mSuggestionsAdapter); ((SuggestionsAdapter) mSuggestionsAdapter).setQueryRefinement( mQueryRefinement ? SuggestionsAdapter.REFINE_ALL
mSearchAutoComplete.setOnItemClickListener(listener); mSearchAutoComplete.setAdapter(adapter); mSearchAutoComplete.setText(text); mSearchAutoComplete.setSelection(position); return mSearchAutoComplete.getText().toString();
/** * Query rewriting. */ private void rewriteQueryFromSuggestion(int position) { CharSequence oldQuery = mQueryTextView.getText(); Cursor c = mSuggestionsAdapter.getCursor(); if (c == null) { return; } if (c.moveToPosition(position)) { // Get the new query from the suggestion. CharSequence newQuery = mSuggestionsAdapter.convertToString(c); if (newQuery != null) { // The suggestion rewrites the query. // Update the text field, without getting new suggestions. setQuery(newQuery); } else { // The suggestion does not rewrite the query, restore the user's query. setQuery(oldQuery); } } else { // We got a bad position, restore the user's query. setQuery(oldQuery); } }
private void onCloseClicked() { CharSequence text = mQueryTextView.getText(); if (TextUtils.isEmpty(text)) { if (mIconifiedByDefault) { // If the app doesn't override the close behavior if (mOnCloseListener == null || !mOnCloseListener.onClose()) { // hide the keyboard and remove focus clearFocus(); // collapse the search field updateViewsVisibility(true); } } } else { mQueryTextView.setText(""); mQueryTextView.requestFocus(); setImeVisibility(true); } }
SearchView.SearchAutoComplete complete = (SearchView.SearchAutoComplete)search.findViewById(R.id.search_src_text); complete.setThreshold(0);
private void dismissSuggestions() { mQueryTextView.dismissDropDown(); }
SearchView.SearchAutoComplete sac = (SearchView.SearchAutoComplete) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); if (sac != null) { sac.setThreshold(0); }
private void updateViewsVisibility(final boolean collapsed) { mIconified = collapsed; // Visibility of views that are visible when collapsed final int visCollapsed = collapsed ? VISIBLE : GONE; // Is there text in the query final boolean hasText = !TextUtils.isEmpty(mQueryTextView.getText()); mSearchButton.setVisibility(visCollapsed); updateSubmitButton(hasText); mSearchEditFrame.setVisibility(collapsed ? GONE : VISIBLE); mSearchHintIcon.setVisibility(mIconifiedByDefault ? GONE : VISIBLE); updateCloseButton(); updateVoiceButton(!hasText); updateSubmitArea(); }
private void onSubmitQuery() { CharSequence query = mQueryTextView.getText(); if (query != null && TextUtils.getTrimmedLength(query) > 0) { if (mOnQueryChangeListener == null || !mOnQueryChangeListener.onQueryTextSubmit(query.toString())) { if (mSearchable != null) { launchQuerySearch(KeyEvent.KEYCODE_UNKNOWN, null, query.toString()); setImeVisibility(false); } dismissSuggestions(); } } }
private void onTextChanged(CharSequence newText) { CharSequence text = mQueryTextView.getText(); mUserQuery = text; boolean hasText = !TextUtils.isEmpty(text); updateSubmitButton(hasText); updateVoiceButton(!hasText); updateCloseButton(); updateSubmitArea(); if (mOnQueryChangeListener != null && !TextUtils.equals(newText, mOldQueryText)) { mOnQueryChangeListener.onQueryTextChange(newText.toString()); } mOldQueryText = newText.toString(); }
/** * Returns the query string currently in the text field. * * @return the query string */ public CharSequence getQuery() { return mQueryTextView.getText(); }
/** * You can set a custom adapter if you wish. Otherwise the default adapter is used to * display the suggestions from the suggestions provider associated with the SearchableInfo. * * @see #setSearchableInfo(SearchableInfo) */ public void setSuggestionsAdapter(CursorAdapter adapter) { mSuggestionsAdapter = adapter; mQueryTextView.setAdapter(mSuggestionsAdapter); }
private void updateCloseButton() { final boolean hasText = !TextUtils.isEmpty(mQueryTextView.getText()); // Should we show the close button? It is not shown if there's no focus, // field is not iconified by default and there is no text in it. final boolean showClose = hasText || (mIconifiedByDefault && !mExpandedInActionView); mCloseButton.setVisibility(showClose ? VISIBLE : GONE); mCloseButton.getDrawable().setState(hasText ? ENABLED_STATE_SET : EMPTY_STATE_SET); }
/** * Sets the text in the query box, without updating the suggestions. */ private void setQuery(CharSequence query) { setText(mQueryTextView, query, true); // Move the cursor to the end mQueryTextView.setSelection(TextUtils.isEmpty(query) ? 0 : query.length()); }
/** @hide */ @Override public void clearFocus() { mClearingFocus = true; setImeVisibility(false); super.clearFocus(); mQueryTextView.clearFocus(); mClearingFocus = false; }
/** * Returns true if the text field is empty, or contains only whitespace. */ private boolean isEmpty() { return TextUtils.getTrimmedLength(getText()) == 0; }