public void run() { InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { showSoftInputUnchecked(SearchView.this, imm, 0); } } };
private int getPreferredWidth() { return getContext().getResources() .getDimensionPixelSize(R.dimen.abs__search_view_preferred_width); }
/** * Launches an intent, including any special intent handling. */ private void launchIntent(Intent intent) { if (intent == null) { return; } try { // If the intent was created from a suggestion, it will always have an explicit // component here. getContext().startActivity(intent); } catch (RuntimeException ex) { Log.e(LOG_TAG, "Failed launch activity: " + intent, ex); } }
private void launchQuerySearch(int actionKey, String actionMsg, String query) { String action = Intent.ACTION_SEARCH; Intent intent = createIntent(action, null, null, query, actionKey, actionMsg); getContext().startActivity(intent); }
getContext().getTheme().resolveAttribute(R.attr.searchViewSearchIcon, outValue, true); return outValue.resourceId;
/** * Gets the hint text to display in the query text field. * @return the query hint text, if specified, null otherwise. * * @attr ref android.R.styleable#SearchView_queryHint */ public CharSequence getQueryHint() { if (mQueryHint != null) { return mQueryHint; } else if (mSearchable != null) { CharSequence hint = null; int hintId = mSearchable.getHintId(); if (hintId != 0) { hint = getContext().getString(hintId); } return hint; } return null; }
private CharSequence getDecoratedHint(CharSequence hintText) { // If the field is always expanded, then don't add the search icon to the hint if (!mIconifiedByDefault) return hintText; SpannableStringBuilder ssb = new SpannableStringBuilder(" "); // for the icon ssb.append(hintText); Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId()); int textSize = (int) (mQueryTextView.getTextSize() * 1.25); searchIcon.setBounds(0, 0, textSize, textSize); ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return ssb; }
private void setImeVisibility(final boolean visible) { if (visible) { post(mShowImeRunnable); } else { removeCallbacks(mShowImeRunnable); InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(getWindowToken(), 0); } } }
private void adjustDropDownSizeAndPosition() { if (mDropDownAnchor.getWidth() > 1) { Resources res = getContext().getResources(); int anchorPadding = mSearchPlate.getPaddingLeft(); Rect dropDownPadding = new Rect(); int iconOffset = mIconifiedByDefault ? res.getDimensionPixelSize(R.dimen.abs__dropdownitem_icon_width) + res.getDimensionPixelSize(R.dimen.abs__dropdownitem_text_padding_left) : 0; mQueryTextView.getDropDownBackground().getPadding(dropDownPadding); mQueryTextView.setDropDownHorizontalOffset(-(dropDownPadding.left + iconOffset) + anchorPadding); mQueryTextView.setDropDownWidth(mDropDownAnchor.getWidth() + dropDownPadding.left + dropDownPadding.right + iconOffset - (anchorPadding)); } }
private void onVoiceClicked() { // guard against possible race conditions if (mSearchable == null) { return; } SearchableInfo searchable = mSearchable; try { if (searchable.getVoiceSearchLaunchWebSearch()) { Intent webSearchIntent = createVoiceWebSearchIntent(mVoiceWebSearchIntent, searchable); getContext().startActivity(webSearchIntent); } else if (searchable.getVoiceSearchLaunchRecognizer()) { Intent appSearchIntent = createVoiceAppSearchIntent(mVoiceAppSearchIntent, searchable); getContext().startActivity(appSearchIntent); } } catch (ActivityNotFoundException e) { // Should not happen, since we check the availability of // voice search before showing the button. But just in case... Log.w(LOG_TAG, "Could not find voice search activity"); } }
private boolean hasVoiceSearch() { if (mSearchable != null && mSearchable.getVoiceSearchEnabled()) { Intent testIntent = null; if (mSearchable.getVoiceSearchLaunchWebSearch()) { testIntent = mVoiceWebSearchIntent; } else if (mSearchable.getVoiceSearchLaunchRecognizer()) { testIntent = mVoiceAppSearchIntent; } if (testIntent != null) { ResolveInfo ri = getContext().getPackageManager().resolveActivity(testIntent, PackageManager.MATCH_DEFAULT_ONLY); return ri != null; } } return false; }
PendingIntent pending = PendingIntent.getActivity(getContext(), 0, queryIntent, PendingIntent.FLAG_ONE_SHOT);
private void updateQueryHint() { if (mQueryHint != null) { mQueryTextView.setHint(getDecoratedHint(mQueryHint)); } else if (mSearchable != null) { CharSequence hint = null; int hintId = mSearchable.getHintId(); if (hintId != 0) { hint = getContext().getString(hintId); } if (hint != null) { mQueryTextView.setHint(getDecoratedHint(hint)); } } else { mQueryTextView.setHint(getDecoratedHint("")); } }
mSuggestionsAdapter = new SuggestionsAdapter(getContext(), this, mSearchable, mOutsideDrawablesCache); mQueryTextView.setAdapter(mSuggestionsAdapter);