MD5 校验值:d555a6389a0a865314e2706996812829
SearchView.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package fodroidx.appcompat.widget; import android.app.PendingIntent; import android.app.SearchableInfo; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.text.Editable; import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.TextWatcher; import android.text.style.ImageSpan; import android.util.AttributeSet; import android.util.Log; import android.util.TypedValue; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.TouchDelegate; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.AutoCompleteTextView; import android.widget.ImageView; import android.widget.TextView; import fodroidx.appcompat.R; import fodroidx.appcompat.view.CollapsibleActionView; import fodroidx.core.view.ViewCompat; import fodroidx.cursoradapter.widget.CursorAdapter; import fodroidx.customview.view.AbsSavedState; import java.lang.reflect.Method; import java.util.WeakHashMap; public class SearchView extends LinearLayoutCompat implements CollapsibleActionView { static final boolean DBG = false; static final AutoCompleteTextViewReflector HIDDEN_METHOD_INVOKER = new AutoCompleteTextViewReflector(); private static final String IME_OPTION_NO_MICROPHONE = "nm"; static final String LOG_TAG = "SearchView"; private Bundle mAppSearchData; private boolean mClearingFocus; final ImageView mCloseButton; private final ImageView mCollapsedIcon; private int mCollapsedImeOptions; private final CharSequence mDefaultQueryHint; private final View mDropDownAnchor; private boolean mExpandedInActionView; final ImageView mGoButton; private boolean mIconified; private boolean mIconifiedByDefault; private int mMaxWidth; private CharSequence mOldQueryText; private final View.OnClickListener mOnClickListener; private OnCloseListener mOnCloseListener; private final TextView.OnEditorActionListener mOnEditorActionListener; private final AdapterView.OnItemClickListener mOnItemClickListener; private final AdapterView.OnItemSelectedListener mOnItemSelectedListener; private OnQueryTextListener mOnQueryChangeListener; View.OnFocusChangeListener mOnQueryTextFocusChangeListener; private View.OnClickListener mOnSearchClickListener; private OnSuggestionListener mOnSuggestionListener; private final WeakHashMap<String, Drawable.ConstantState> mOutsideDrawablesCache; private CharSequence mQueryHint; private boolean mQueryRefinement; private Runnable mReleaseCursorRunnable; final ImageView mSearchButton; private final View mSearchEditFrame; private final Drawable mSearchHintIcon; private final View mSearchPlate; final SearchAutoComplete mSearchSrcTextView; private Rect mSearchSrcTextViewBounds; private Rect mSearchSrtTextViewBoundsExpanded; SearchableInfo mSearchable; private final View mSubmitArea; private boolean mSubmitButtonEnabled; private final int mSuggestionCommitIconResId; private final int mSuggestionRowLayout; CursorAdapter mSuggestionsAdapter; private int[] mTemp; private int[] mTemp2; View.OnKeyListener mTextKeyListener; private TextWatcher mTextWatcher; private UpdatableTouchDelegate mTouchDelegate; private final Runnable mUpdateDrawableStateRunnable; private CharSequence mUserQuery; private final Intent mVoiceAppSearchIntent; final ImageView mVoiceButton; private boolean mVoiceButtonEnabled; private final Intent mVoiceWebSearchIntent; public interface OnCloseListener { boolean onClose(); } public interface OnQueryTextListener { boolean onQueryTextChange(String str); boolean onQueryTextSubmit(String str); } public interface OnSuggestionListener { boolean onSuggestionClick(int i); boolean onSuggestionSelect(int i); } public SearchView(Context context) { this(context, null); } public SearchView(Context context, AttributeSet attributeSet) { this(context, attributeSet, R.attr.searchViewStyle); } public SearchView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); this.mSearchSrcTextViewBounds = new Rect(); this.mSearchSrtTextViewBoundsExpanded = new Rect(); this.mTemp = new int[2]; this.mTemp2 = new int[2]; this.mUpdateDrawableStateRunnable = new Runnable() { @Override public void run() { SearchView.this.updateFocusedState(); } }; this.mReleaseCursorRunnable = new Runnable() { @Override public void run() { if (SearchView.this.mSuggestionsAdapter == null || !(SearchView.this.mSuggestionsAdapter instanceof SuggestionsAdapter)) { return; } SearchView.this.mSuggestionsAdapter.changeCursor(null); } }; this.mOutsideDrawablesCache = new WeakHashMap<>(); this.mOnClickListener = new View.OnClickListener() { @Override public void onClick(View view) { if (view == SearchView.this.mSearchButton) { SearchView.this.onSearchClicked(); return; } if (view == SearchView.this.mCloseButton) { SearchView.this.onCloseClicked(); return; } if (view == SearchView.this.mGoButton) { SearchView.this.onSubmitQuery(); } else if (view == SearchView.this.mVoiceButton) { SearchView.this.onVoiceClicked(); } else if (view == SearchView.this.mSearchSrcTextView) { SearchView.this.forceSuggestionQuery(); } } }; this.mTextKeyListener = new View.OnKeyListener() { @Override public boolean onKey(View view, int i2, KeyEvent keyEvent) { if (SearchView.this.mSearchable == null) { return false; } if (SearchView.this.mSearchSrcTextView.isPopupShowing() && SearchView.this.mSearchSrcTextView.getListSelection() != -1) { return SearchView.this.onSuggestionsKey(view, i2, keyEvent); } if (SearchView.this.mSearchSrcTextView.isEmpty() || !keyEvent.hasNoModifiers() || keyEvent.getAction() != 1 || i2 != 66) { return false; } view.cancelLongPress(); SearchView searchView = SearchView.this; searchView.launchQuerySearch(0, null, searchView.mSearchSrcTextView.getText().toString()); return true; } }; this.mOnEditorActionListener = new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i2, KeyEvent keyEvent) { SearchView.this.onSubmitQuery(); return true; } }; this.mOnItemClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i2, long j) { SearchView.this.onItemClicked(i2, 0, null); } }; this.mOnItemSelectedListener = new AdapterView.OnItemSelectedListener() { @Override public void onNothingSelected(AdapterView<?> adapterView) { } @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i2, long j) { SearchView.this.onItemSelected(i2); } }; this.mTextWatcher = new TextWatcher() { @Override public void afterTextChanged(Editable editable) { } @Override public void beforeTextChanged(CharSequence charSequence, int i2, int i3, int i4) { } @Override public void onTextChanged(CharSequence charSequence, int i2, int i3, int i4) { SearchView.this.onTextChanged(charSequence); } }; TintTypedArray obtainStyledAttributes = TintTypedArray.obtainStyledAttributes(context, attributeSet, R.styleable.SearchView, i, 0); LayoutInflater.from(context).inflate(obtainStyledAttributes.getResourceId(R.styleable.SearchView_layout, R.layout.abc_search_view), (ViewGroup) this, true); this.mSearchSrcTextView = (SearchAutoComplete) findViewById(R.id.search_src_text); this.mSearchSrcTextView.setSearchView(this); this.mSearchEditFrame = findViewById(R.id.search_edit_frame); this.mSearchPlate = findViewById(R.id.search_plate); this.mSubmitArea = findViewById(R.id.submit_area); this.mSearchButton = (ImageView) findViewById(R.id.search_button); this.mGoButton = (ImageView) findViewById(R.id.search_go_btn); this.mCloseButton = (ImageView) findViewById(R.id.search_close_btn); this.mVoiceButton = (ImageView) findViewById(R.id.search_voice_btn); this.mCollapsedIcon = (ImageView) findViewById(R.id.search_mag_icon); ViewCompat.setBackground(this.mSearchPlate, obtainStyledAttributes.getDrawable(R.styleable.SearchView_queryBackground)); ViewCompat.setBackground(this.mSubmitArea, obtainStyledAttributes.getDrawable(R.styleable.SearchView_submitBackground)); this.mSearchButton.setImageDrawable(obtainStyledAttributes.getDrawable(R.styleable.SearchView_searchIcon)); this.mGoButton.setImageDrawable(obtainStyledAttributes.getDrawable(R.styleable.SearchView_goIcon)); this.mCloseButton.setImageDrawable(obtainStyledAttributes.getDrawable(R.styleable.SearchView_closeIcon)); this.mVoiceButton.setImageDrawable(obtainStyledAttributes.getDrawable(R.styleable.SearchView_voiceIcon)); this.mCollapsedIcon.setImageDrawable(obtainStyledAttributes.getDrawable(R.styleable.SearchView_searchIcon)); this.mSearchHintIcon = obtainStyledAttributes.getDrawable(R.styleable.SearchView_searchHintIcon); TooltipCompat.setTooltipText(this.mSearchButton, getResources().getString(R.string.abc_searchview_description_search)); this.mSuggestionRowLayout = obtainStyledAttributes.getResourceId(R.styleable.SearchView_suggestionRowLayout, R.layout.abc_search_dropdown_item_icons_2line); this.mSuggestionCommitIconResId = obtainStyledAttributes.getResourceId(R.styleable.SearchView_commitIcon, 0); this.mSearchButton.setOnClickListener(this.mOnClickListener); this.mCloseButton.setOnClickListener(this.mOnClickListener); this.mGoButton.setOnClickListener(this.mOnClickListener); this.mVoiceButton.setOnClickListener(this.mOnClickListener); this.mSearchSrcTextView.setOnClickListener(this.mOnClickListener); this.mSearchSrcTextView.addTextChangedListener(this.mTextWatcher); this.mSearchSrcTextView.setOnEditorActionListener(this.mOnEditorActionListener); this.mSearchSrcTextView.setOnItemClickListener(this.mOnItemClickListener); this.mSearchSrcTextView.setOnItemSelectedListener(this.mOnItemSelectedListener); this.mSearchSrcTextView.setOnKeyListener(this.mTextKeyListener); this.mSearchSrcTextView.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean z) { if (SearchView.this.mOnQueryTextFocusChangeListener != null) { SearchView.this.mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, z); } } }); setIconifiedByDefault(obtainStyledAttributes.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1); if (dimensionPixelSize != -1) { setMaxWidth(dimensionPixelSize); } this.mDefaultQueryHint = obtainStyledAttributes.getText(R.styleable.SearchView_defaultQueryHint); this.mQueryHint = obtainStyledAttributes.getText(R.styleable.SearchView_queryHint); int i2 = obtainStyledAttributes.getInt(R.styleable.SearchView_android_imeOptions, -1); if (i2 != -1) { setImeOptions(i2); } int i3 = obtainStyledAttributes.getInt(R.styleable.SearchView_android_inputType, -1); if (i3 != -1) { setInputType(i3); } setFocusable(obtainStyledAttributes.getBoolean(R.styleable.SearchView_android_focusable, true)); obtainStyledAttributes.recycle(); this.mVoiceWebSearchIntent = new Intent("android.speech.action.WEB_SEARCH"); this.mVoiceWebSearchIntent.addFlags(268435456); this.mVoiceWebSearchIntent.putExtra("android.speech.extra.LANGUAGE_MODEL", "web_search"); this.mVoiceAppSearchIntent = new Intent("android.speech.action.RECOGNIZE_SPEECH"); this.mVoiceAppSearchIntent.addFlags(268435456); this.mDropDownAnchor = findViewById(this.mSearchSrcTextView.getDropDownAnchor()); View view = this.mDropDownAnchor; if (view != null) { view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View view2, int i4, int i5, int i6, int i7, int i8, int i9, int i10, int i11) { SearchView.this.adjustDropDownSizeAndPosition(); } }); } updateViewsVisibility(this.mIconifiedByDefault); updateQueryHint(); } public int getSuggestionRowLayout() { return this.mSuggestionRowLayout; } public int getSuggestionCommitIconResId() { return this.mSuggestionCommitIconResId; } public void setSearchableInfo(SearchableInfo searchableInfo) { this.mSearchable = searchableInfo; if (this.mSearchable != null) { updateSearchAutoComplete(); updateQueryHint(); } this.mVoiceButtonEnabled = hasVoiceSearch(); if (this.mVoiceButtonEnabled) { this.mSearchSrcTextView.setPrivateImeOptions(IME_OPTION_NO_MICROPHONE); } updateViewsVisibility(isIconified()); } public void setAppSearchData(Bundle bundle) { this.mAppSearchData = bundle; } public void setImeOptions(int i) { this.mSearchSrcTextView.setImeOptions(i); } public int getImeOptions() { return this.mSearchSrcTextView.getImeOptions(); } public void setInputType(int i) { this.mSearchSrcTextView.setInputType(i); } public int getInputType() { return this.mSearchSrcTextView.getInputType(); } @Override public boolean requestFocus(int i, Rect rect) { if (this.mClearingFocus || !isFocusable()) { return false; } if (!isIconified()) { boolean requestFocus = this.mSearchSrcTextView.requestFocus(i, rect); if (requestFocus) { updateViewsVisibility(false); } return requestFocus; } return super.requestFocus(i, rect); } @Override public void clearFocus() { this.mClearingFocus = true; super.clearFocus(); this.mSearchSrcTextView.clearFocus(); this.mSearchSrcTextView.setImeVisibility(false); this.mClearingFocus = false; } public void setOnQueryTextListener(OnQueryTextListener onQueryTextListener) { this.mOnQueryChangeListener = onQueryTextListener; } public void setOnCloseListener(OnCloseListener onCloseListener) { this.mOnCloseListener = onCloseListener; } public void setOnQueryTextFocusChangeListener(View.OnFocusChangeListener onFocusChangeListener) { this.mOnQueryTextFocusChangeListener = onFocusChangeListener; } public void setOnSuggestionListener(OnSuggestionListener onSuggestionListener) { this.mOnSuggestionListener = onSuggestionListener; } public void setOnSearchClickListener(View.OnClickListener onClickListener) { this.mOnSearchClickListener = onClickListener; } public CharSequence getQuery() { return this.mSearchSrcTextView.getText(); } public void setQuery(CharSequence charSequence, boolean z) { this.mSearchSrcTextView.setText(charSequence); if (charSequence != null) { SearchAutoComplete searchAutoComplete = this.mSearchSrcTextView; searchAutoComplete.setSelection(searchAutoComplete.length()); this.mUserQuery = charSequence; } if (!z || TextUtils.isEmpty(charSequence)) { return; } onSubmitQuery(); } public void setQueryHint(CharSequence charSequence) { this.mQueryHint = charSequence; updateQueryHint(); } public CharSequence getQueryHint() { CharSequence charSequence = this.mQueryHint; if (charSequence != null) { return charSequence; } SearchableInfo searchableInfo = this.mSearchable; if (searchableInfo != null && searchableInfo.getHintId() != 0) { return getContext().getText(this.mSearchable.getHintId()); } return this.mDefaultQueryHint; } public void setIconifiedByDefault(boolean z) { if (this.mIconifiedByDefault == z) { return; } this.mIconifiedByDefault = z; updateViewsVisibility(z); updateQueryHint(); } public boolean isIconfiedByDefault() { return this.mIconifiedByDefault; } public void setIconified(boolean z) { if (z) { onCloseClicked(); } else { onSearchClicked(); } } public boolean isIconified() { return this.mIconified; } public void setSubmitButtonEnabled(boolean z) { this.mSubmitButtonEnabled = z; updateViewsVisibility(isIconified()); } public boolean isSubmitButtonEnabled() { return this.mSubmitButtonEnabled; } public void setQueryRefinementEnabled(boolean z) { this.mQueryRefinement = z; CursorAdapter cursorAdapter = this.mSuggestionsAdapter; if (cursorAdapter instanceof SuggestionsAdapter) { ((SuggestionsAdapter) cursorAdapter).setQueryRefinement(z ? 2 : 1); } } public boolean isQueryRefinementEnabled() { return this.mQueryRefinement; } public void setSuggestionsAdapter(CursorAdapter cursorAdapter) { this.mSuggestionsAdapter = cursorAdapter; this.mSearchSrcTextView.setAdapter(this.mSuggestionsAdapter); } public CursorAdapter getSuggestionsAdapter() { return this.mSuggestionsAdapter; } public void setMaxWidth(int i) { this.mMaxWidth = i; requestLayout(); } public int getMaxWidth() { return this.mMaxWidth; } @Override public void onMeasure(int i, int i2) { int i3; if (isIconified()) { super.onMeasure(i, i2); return; } int mode = View.MeasureSpec.getMode(i); int size = View.MeasureSpec.getSize(i); if (mode == Integer.MIN_VALUE) { int i4 = this.mMaxWidth; size = i4 > 0 ? Math.min(i4, size) : Math.min(getPreferredWidth(), size); } else if (mode == 0) { size = this.mMaxWidth; if (size <= 0) { size = getPreferredWidth(); } } else if (mode == 1073741824 && (i3 = this.mMaxWidth) > 0) { size = Math.min(i3, size); } int mode2 = View.MeasureSpec.getMode(i2); int size2 = View.MeasureSpec.getSize(i2); if (mode2 == Integer.MIN_VALUE) { size2 = Math.min(getPreferredHeight(), size2); } else if (mode2 == 0) { size2 = getPreferredHeight(); } super.onMeasure(View.MeasureSpec.makeMeasureSpec(size, 1073741824), View.MeasureSpec.makeMeasureSpec(size2, 1073741824)); } @Override public void onLayout(boolean z, int i, int i2, int i3, int i4) { super.onLayout(z, i, i2, i3, i4); if (z) { getChildBoundsWithinSearchView(this.mSearchSrcTextView, this.mSearchSrcTextViewBounds); this.mSearchSrtTextViewBoundsExpanded.set(this.mSearchSrcTextViewBounds.left, 0, this.mSearchSrcTextViewBounds.right, i4 - i2); UpdatableTouchDelegate updatableTouchDelegate = this.mTouchDelegate; if (updatableTouchDelegate == null) { this.mTouchDelegate = new UpdatableTouchDelegate(this.mSearchSrtTextViewBoundsExpanded, this.mSearchSrcTextViewBounds, this.mSearchSrcTextView); setTouchDelegate(this.mTouchDelegate); } else { updatableTouchDelegate.setBounds(this.mSearchSrtTextViewBoundsExpanded, this.mSearchSrcTextViewBounds); } } } private void getChildBoundsWithinSearchView(View view, Rect rect) { view.getLocationInWindow(this.mTemp); getLocationInWindow(this.mTemp2); int[] iArr = this.mTemp; int i = iArr[1]; int[] iArr2 = this.mTemp2; int i2 = i - iArr2[1]; int i3 = iArr[0] - iArr2[0]; rect.set(i3, i2, view.getWidth() + i3, view.getHeight() + i2); } private int getPreferredWidth() { return getContext().getResources().getDimensionPixelSize(R.dimen.abc_search_view_preferred_width); } private int getPreferredHeight() { return getContext().getResources().getDimensionPixelSize(R.dimen.abc_search_view_preferred_height); } private void updateViewsVisibility(boolean z) { this.mIconified = z; int i = z ? 0 : 8; boolean z2 = !TextUtils.isEmpty(this.mSearchSrcTextView.getText()); this.mSearchButton.setVisibility(i); updateSubmitButton(z2); this.mSearchEditFrame.setVisibility(z ? 8 : 0); this.mCollapsedIcon.setVisibility((this.mCollapsedIcon.getDrawable() == null || this.mIconifiedByDefault) ? 8 : 0); updateCloseButton(); updateVoiceButton(!z2); updateSubmitArea(); } private boolean hasVoiceSearch() { SearchableInfo searchableInfo = this.mSearchable; if (searchableInfo == null || !searchableInfo.getVoiceSearchEnabled()) { return false; } Intent intent = null; if (this.mSearchable.getVoiceSearchLaunchWebSearch()) { intent = this.mVoiceWebSearchIntent; } else if (this.mSearchable.getVoiceSearchLaunchRecognizer()) { intent = this.mVoiceAppSearchIntent; } return (intent == null || getContext().getPackageManager().resolveActivity(intent, 65536) == null) ? false : true; } private boolean isSubmitAreaEnabled() { return (this.mSubmitButtonEnabled || this.mVoiceButtonEnabled) && !isIconified(); } private void updateSubmitButton(boolean z) { this.mGoButton.setVisibility((this.mSubmitButtonEnabled && isSubmitAreaEnabled() && hasFocus() && (z || !this.mVoiceButtonEnabled)) ? 0 : 8); } private void updateSubmitArea() { this.mSubmitArea.setVisibility((isSubmitAreaEnabled() && (this.mGoButton.getVisibility() == 0 || this.mVoiceButton.getVisibility() == 0)) ? 0 : 8); } private void updateCloseButton() { boolean z = true; boolean z2 = !TextUtils.isEmpty(this.mSearchSrcTextView.getText()); if (!z2 && (!this.mIconifiedByDefault || this.mExpandedInActionView)) { z = false; } this.mCloseButton.setVisibility(z ? 0 : 8); Drawable drawable = this.mCloseButton.getDrawable(); if (drawable != null) { drawable.setState(z2 ? ENABLED_STATE_SET : EMPTY_STATE_SET); } } private void postUpdateFocusedState() { post(this.mUpdateDrawableStateRunnable); } void updateFocusedState() { int[] iArr = this.mSearchSrcTextView.hasFocus() ? FOCUSED_STATE_SET : EMPTY_STATE_SET; Drawable background = this.mSearchPlate.getBackground(); if (background != null) { background.setState(iArr); } Drawable background2 = this.mSubmitArea.getBackground(); if (background2 != null) { background2.setState(iArr); } invalidate(); } @Override protected void onDetachedFromWindow() { removeCallbacks(this.mUpdateDrawableStateRunnable); post(this.mReleaseCursorRunnable); super.onDetachedFromWindow(); } public void onQueryRefine(CharSequence charSequence) { setQuery(charSequence); } boolean onSuggestionsKey(View view, int i, KeyEvent keyEvent) { if (this.mSearchable != null && this.mSuggestionsAdapter != null && keyEvent.getAction() == 0 && keyEvent.hasNoModifiers()) { if (i == 66 || i == 84 || i == 61) { return onItemClicked(this.mSearchSrcTextView.getListSelection(), 0, null); } if (i == 21 || i == 22) { this.mSearchSrcTextView.setSelection(i == 21 ? 0 : this.mSearchSrcTextView.length()); this.mSearchSrcTextView.setListSelection(0); this.mSearchSrcTextView.clearListSelection(); HIDDEN_METHOD_INVOKER.ensureImeVisible(this.mSearchSrcTextView, true); return true; } if (i != 19 || this.mSearchSrcTextView.getListSelection() == 0) { return false; } } return false; } private CharSequence getDecoratedHint(CharSequence charSequence) { if (!this.mIconifiedByDefault || this.mSearchHintIcon == null) { return charSequence; } double textSize = this.mSearchSrcTextView.getTextSize(); Double.isNaN(textSize); int i = (int) (textSize * 1.25d); this.mSearchHintIcon.setBounds(0, 0, i, i); SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(" "); spannableStringBuilder.setSpan(new ImageSpan(this.mSearchHintIcon), 1, 2, 33); spannableStringBuilder.append(charSequence); return spannableStringBuilder; } private void updateQueryHint() { CharSequence queryHint = getQueryHint(); SearchAutoComplete searchAutoComplete = this.mSearchSrcTextView; if (queryHint == null) { queryHint = ""; } searchAutoComplete.setHint(getDecoratedHint(queryHint)); } private void updateSearchAutoComplete() { this.mSearchSrcTextView.setThreshold(this.mSearchable.getSuggestThreshold()); this.mSearchSrcTextView.setImeOptions(this.mSearchable.getImeOptions()); int inputType = this.mSearchable.getInputType(); if ((inputType & 15) == 1) { inputType &= -65537; if (this.mSearchable.getSuggestAuthority() != null) { inputType = inputType | 65536 | 524288; } } this.mSearchSrcTextView.setInputType(inputType); CursorAdapter cursorAdapter = this.mSuggestionsAdapter; if (cursorAdapter != null) { cursorAdapter.changeCursor(null); } if (this.mSearchable.getSuggestAuthority() != null) { this.mSuggestionsAdapter = new SuggestionsAdapter(getContext(), this, this.mSearchable, this.mOutsideDrawablesCache); this.mSearchSrcTextView.setAdapter(this.mSuggestionsAdapter); ((SuggestionsAdapter) this.mSuggestionsAdapter).setQueryRefinement(this.mQueryRefinement ? 2 : 1); } } private void updateVoiceButton(boolean z) { int i; if (this.mVoiceButtonEnabled && !isIconified() && z) { i = 0; this.mGoButton.setVisibility(8); } else { i = 8; } this.mVoiceButton.setVisibility(i); } void onTextChanged(CharSequence charSequence) { Editable text = this.mSearchSrcTextView.getText(); this.mUserQuery = text; boolean z = !TextUtils.isEmpty(text); updateSubmitButton(z); updateVoiceButton(!z); updateCloseButton(); updateSubmitArea(); if (this.mOnQueryChangeListener != null && !TextUtils.equals(charSequence, this.mOldQueryText)) { this.mOnQueryChangeListener.onQueryTextChange(charSequence.toString()); } this.mOldQueryText = charSequence.toString(); } void onSubmitQuery() { Editable text = this.mSearchSrcTextView.getText(); if (text == null || TextUtils.getTrimmedLength(text) <= 0) { return; } OnQueryTextListener onQueryTextListener = this.mOnQueryChangeListener; if (onQueryTextListener == null || !onQueryTextListener.onQueryTextSubmit(text.toString())) { if (this.mSearchable != null) { launchQuerySearch(0, null, text.toString()); } this.mSearchSrcTextView.setImeVisibility(false); dismissSuggestions(); } } private void dismissSuggestions() { this.mSearchSrcTextView.dismissDropDown(); } void onCloseClicked() { if (TextUtils.isEmpty(this.mSearchSrcTextView.getText())) { if (this.mIconifiedByDefault) { OnCloseListener onCloseListener = this.mOnCloseListener; if (onCloseListener == null || !onCloseListener.onClose()) { clearFocus(); updateViewsVisibility(true); return; } return; } return; } this.mSearchSrcTextView.setText(""); this.mSearchSrcTextView.requestFocus(); this.mSearchSrcTextView.setImeVisibility(true); } void onSearchClicked() { updateViewsVisibility(false); this.mSearchSrcTextView.requestFocus(); this.mSearchSrcTextView.setImeVisibility(true); View.OnClickListener onClickListener = this.mOnSearchClickListener; if (onClickListener != null) { onClickListener.onClick(this); } } void onVoiceClicked() { SearchableInfo searchableInfo = this.mSearchable; if (searchableInfo == null) { return; } try { if (searchableInfo.getVoiceSearchLaunchWebSearch()) { getContext().startActivity(createVoiceWebSearchIntent(this.mVoiceWebSearchIntent, searchableInfo)); } else if (searchableInfo.getVoiceSearchLaunchRecognizer()) { getContext().startActivity(createVoiceAppSearchIntent(this.mVoiceAppSearchIntent, searchableInfo)); } } catch (ActivityNotFoundException unused) { Log.w(LOG_TAG, "Could not find voice search activity"); } } void onTextFocusChanged() { updateViewsVisibility(isIconified()); postUpdateFocusedState(); if (this.mSearchSrcTextView.hasFocus()) { forceSuggestionQuery(); } } @Override public void onWindowFocusChanged(boolean z) { super.onWindowFocusChanged(z); postUpdateFocusedState(); } @Override public void onActionViewCollapsed() { setQuery("", false); clearFocus(); updateViewsVisibility(true); this.mSearchSrcTextView.setImeOptions(this.mCollapsedImeOptions); this.mExpandedInActionView = false; } @Override public void onActionViewExpanded() { if (this.mExpandedInActionView) { return; } this.mExpandedInActionView = true; this.mCollapsedImeOptions = this.mSearchSrcTextView.getImeOptions(); this.mSearchSrcTextView.setImeOptions(this.mCollapsedImeOptions | 33554432); this.mSearchSrcTextView.setText(""); setIconified(false); } public static class SavedState extends AbsSavedState { public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.ClassLoaderCreator<SavedState>() { @Override public SavedState createFromParcel(Parcel parcel, ClassLoader classLoader) { return new SavedState(parcel, classLoader); } @Override public SavedState createFromParcel(Parcel parcel) { return new SavedState(parcel, null); } @Override public SavedState[] newArray(int i) { return new SavedState[i]; } }; boolean isIconified; SavedState(Parcelable parcelable) { super(parcelable); } public SavedState(Parcel parcel, ClassLoader classLoader) { super(parcel, classLoader); this.isIconified = ((Boolean) parcel.readValue(null)).booleanValue(); } @Override public void writeToParcel(Parcel parcel, int i) { super.writeToParcel(parcel, i); parcel.writeValue(Boolean.valueOf(this.isIconified)); } public String toString() { return "SearchView.SavedState{" + Integer.toHexString(System.identityHashCode(this)) + " isIconified=" + this.isIconified + "}"; } } @Override protected Parcelable onSaveInstanceState() { SavedState savedState = new SavedState(super.onSaveInstanceState()); savedState.isIconified = isIconified(); return savedState; } @Override protected void onRestoreInstanceState(Parcelable parcelable) { if (!(parcelable instanceof SavedState)) { super.onRestoreInstanceState(parcelable); return; } SavedState savedState = (SavedState) parcelable; super.onRestoreInstanceState(savedState.getSuperState()); updateViewsVisibility(savedState.isIconified); requestLayout(); } void adjustDropDownSizeAndPosition() { int i; if (this.mDropDownAnchor.getWidth() > 1) { Resources resources = getContext().getResources(); int paddingLeft = this.mSearchPlate.getPaddingLeft(); Rect rect = new Rect(); boolean isLayoutRtl = ViewUtils.isLayoutRtl(this); int dimensionPixelSize = this.mIconifiedByDefault ? resources.getDimensionPixelSize(R.dimen.abc_dropdownitem_icon_width) + resources.getDimensionPixelSize(R.dimen.abc_dropdownitem_text_padding_left) : 0; this.mSearchSrcTextView.getDropDownBackground().getPadding(rect); if (isLayoutRtl) { i = -rect.left; } else { i = paddingLeft - (rect.left + dimensionPixelSize); } this.mSearchSrcTextView.setDropDownHorizontalOffset(i); this.mSearchSrcTextView.setDropDownWidth((((this.mDropDownAnchor.getWidth() + rect.left) + rect.right) + dimensionPixelSize) - paddingLeft); } } boolean onItemClicked(int i, int i2, String str) { OnSuggestionListener onSuggestionListener = this.mOnSuggestionListener; if (onSuggestionListener != null && onSuggestionListener.onSuggestionClick(i)) { return false; } launchSuggestion(i, 0, null); this.mSearchSrcTextView.setImeVisibility(false); dismissSuggestions(); return true; } boolean onItemSelected(int i) { OnSuggestionListener onSuggestionListener = this.mOnSuggestionListener; if (onSuggestionListener != null && onSuggestionListener.onSuggestionSelect(i)) { return false; } rewriteQueryFromSuggestion(i); return true; } private void rewriteQueryFromSuggestion(int i) { Editable text = this.mSearchSrcTextView.getText(); Cursor cursor = this.mSuggestionsAdapter.getCursor(); if (cursor == null) { return; } if (cursor.moveToPosition(i)) { CharSequence convertToString = this.mSuggestionsAdapter.convertToString(cursor); if (convertToString != null) { setQuery(convertToString); return; } else { setQuery(text); return; } } setQuery(text); } private boolean launchSuggestion(int i, int i2, String str) { Cursor cursor = this.mSuggestionsAdapter.getCursor(); if (cursor == null || !cursor.moveToPosition(i)) { return false; } launchIntent(createIntentFromSuggestion(cursor, i2, str)); return true; } private void launchIntent(Intent intent) { if (intent == null) { return; } try { getContext().startActivity(intent); } catch (RuntimeException e) { Log.e(LOG_TAG, "Failed launch activity: " + intent, e); } } private void setQuery(CharSequence charSequence) { this.mSearchSrcTextView.setText(charSequence); this.mSearchSrcTextView.setSelection(TextUtils.isEmpty(charSequence) ? 0 : charSequence.length()); } void launchQuerySearch(int i, String str, String str2) { getContext().startActivity(createIntent("android.intent.action.SEARCH", null, null, str2, i, str)); } private Intent createIntent(String str, Uri uri, String str2, String str3, int i, String str4) { Intent intent = new Intent(str); intent.addFlags(268435456); if (uri != null) { intent.setData(uri); } intent.putExtra("user_query", this.mUserQuery); if (str3 != null) { intent.putExtra("query", str3); } if (str2 != null) { intent.putExtra("intent_extra_data_key", str2); } Bundle bundle = this.mAppSearchData; if (bundle != null) { intent.putExtra("app_data", bundle); } if (i != 0) { intent.putExtra("action_key", i); intent.putExtra("action_msg", str4); } intent.setComponent(this.mSearchable.getSearchActivity()); return intent; } private Intent createVoiceWebSearchIntent(Intent intent, SearchableInfo searchableInfo) { Intent intent2 = new Intent(intent); ComponentName searchActivity = searchableInfo.getSearchActivity(); intent2.putExtra("calling_package", searchActivity == null ? null : searchActivity.flattenToShortString()); return intent2; } private Intent createVoiceAppSearchIntent(Intent intent, SearchableInfo searchableInfo) { ComponentName searchActivity = searchableInfo.getSearchActivity(); Intent intent2 = new Intent("android.intent.action.SEARCH"); intent2.setComponent(searchActivity); PendingIntent activity = PendingIntent.getActivity(getContext(), 0, intent2, 1073741824); Bundle bundle = new Bundle(); Bundle bundle2 = this.mAppSearchData; if (bundle2 != null) { bundle.putParcelable("app_data", bundle2); } Intent intent3 = new Intent(intent); Resources resources = getResources(); String string = searchableInfo.getVoiceLanguageModeId() != 0 ? resources.getString(searchableInfo.getVoiceLanguageModeId()) : "free_form"; String string2 = searchableInfo.getVoicePromptTextId() != 0 ? resources.getString(searchableInfo.getVoicePromptTextId()) : null; String string3 = searchableInfo.getVoiceLanguageId() != 0 ? resources.getString(searchableInfo.getVoiceLanguageId()) : null; int voiceMaxResults = searchableInfo.getVoiceMaxResults() != 0 ? searchableInfo.getVoiceMaxResults() : 1; intent3.putExtra("android.speech.extra.LANGUAGE_MODEL", string); intent3.putExtra("android.speech.extra.PROMPT", string2); intent3.putExtra("android.speech.extra.LANGUAGE", string3); intent3.putExtra("android.speech.extra.MAX_RESULTS", voiceMaxResults); intent3.putExtra("calling_package", searchActivity != null ? searchActivity.flattenToShortString() : null); intent3.putExtra("android.speech.extra.RESULTS_PENDINGINTENT", activity); intent3.putExtra("android.speech.extra.RESULTS_PENDINGINTENT_BUNDLE", bundle); return intent3; } private Intent createIntentFromSuggestion(Cursor cursor, int i, String str) { int i2; String columnString; try { String columnString2 = SuggestionsAdapter.getColumnString(cursor, "suggest_intent_action"); if (columnString2 == null) { columnString2 = this.mSearchable.getSuggestIntentAction(); } if (columnString2 == null) { columnString2 = "android.intent.action.SEARCH"; } String str2 = columnString2; String columnString3 = SuggestionsAdapter.getColumnString(cursor, "suggest_intent_data"); if (columnString3 == null) { columnString3 = this.mSearchable.getSuggestIntentData(); } if (columnString3 != null && (columnString = SuggestionsAdapter.getColumnString(cursor, "suggest_intent_data_id")) != null) { columnString3 = columnString3 + "/" + Uri.encode(columnString); } return createIntent(str2, columnString3 == null ? null : Uri.parse(columnString3), SuggestionsAdapter.getColumnString(cursor, "suggest_intent_extra_data"), SuggestionsAdapter.getColumnString(cursor, "suggest_intent_query"), i, str); } catch (RuntimeException e) { try { i2 = cursor.getPosition(); } catch (RuntimeException unused) { i2 = -1; } Log.w(LOG_TAG, "Search suggestions cursor at row " + i2 + " returned exception.", e); return null; } } void forceSuggestionQuery() { HIDDEN_METHOD_INVOKER.doBeforeTextChanged(this.mSearchSrcTextView); HIDDEN_METHOD_INVOKER.doAfterTextChanged(this.mSearchSrcTextView); } static boolean isLandscapeMode(Context context) { return context.getResources().getConfiguration().orientation == 2; } private static class UpdatableTouchDelegate extends TouchDelegate { private final Rect mActualBounds; private boolean mDelegateTargeted; private final View mDelegateView; private final int mSlop; private final Rect mSlopBounds; private final Rect mTargetBounds; public UpdatableTouchDelegate(Rect rect, Rect rect2, View view) { super(rect, view); this.mSlop = ViewConfiguration.get(view.getContext()).getScaledTouchSlop(); this.mTargetBounds = new Rect(); this.mSlopBounds = new Rect(); this.mActualBounds = new Rect(); setBounds(rect, rect2); this.mDelegateView = view; } public void setBounds(Rect rect, Rect rect2) { this.mTargetBounds.set(rect); this.mSlopBounds.set(rect); Rect rect3 = this.mSlopBounds; int i = this.mSlop; rect3.inset(-i, -i); this.mActualBounds.set(rect2); } @Override public boolean onTouchEvent(MotionEvent motionEvent) { boolean z; int x = (int) motionEvent.getX(); int y = (int) motionEvent.getY(); int action = motionEvent.getAction(); boolean z2 = true; if (action == 0) { if (this.mTargetBounds.contains(x, y)) { this.mDelegateTargeted = true; z = true; } z = false; } else if (action == 1 || action == 2) { z = this.mDelegateTargeted; if (z && !this.mSlopBounds.contains(x, y)) { z2 = false; } } else { if (action == 3) { z = this.mDelegateTargeted; this.mDelegateTargeted = false; } z = false; } if (!z) { return false; } if (z2 && !this.mActualBounds.contains(x, y)) { motionEvent.setLocation(this.mDelegateView.getWidth() / 2, this.mDelegateView.getHeight() / 2); } else { motionEvent.setLocation(x - this.mActualBounds.left, y - this.mActualBounds.top); } return this.mDelegateView.dispatchTouchEvent(motionEvent); } } public static class SearchAutoComplete extends AppCompatAutoCompleteTextView { private boolean mHasPendingShowSoftInputRequest; final Runnable mRunShowSoftInputIfNecessary; private SearchView mSearchView; private int mThreshold; @Override public void performCompletion() { } @Override protected void replaceText(CharSequence charSequence) { } public SearchAutoComplete(Context context) { this(context, null); } public SearchAutoComplete(Context context, AttributeSet attributeSet) { this(context, attributeSet, R.attr.autoCompleteTextViewStyle); } public SearchAutoComplete(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); this.mRunShowSoftInputIfNecessary = new Runnable() { @Override public void run() { SearchAutoComplete.this.showSoftInputIfNecessary(); } }; this.mThreshold = getThreshold(); } @Override protected void onFinishInflate() { super.onFinishInflate(); setMinWidth((int) TypedValue.applyDimension(1, getSearchViewTextMinWidthDp(), getResources().getDisplayMetrics())); } void setSearchView(SearchView searchView) { this.mSearchView = searchView; } @Override public void setThreshold(int i) { super.setThreshold(i); this.mThreshold = i; } boolean isEmpty() { return TextUtils.getTrimmedLength(getText()) == 0; } @Override public void onWindowFocusChanged(boolean z) { super.onWindowFocusChanged(z); if (z && this.mSearchView.hasFocus() && getVisibility() == 0) { this.mHasPendingShowSoftInputRequest = true; if (SearchView.isLandscapeMode(getContext())) { SearchView.HIDDEN_METHOD_INVOKER.ensureImeVisible(this, true); } } } @Override protected void onFocusChanged(boolean z, int i, Rect rect) { super.onFocusChanged(z, i, rect); this.mSearchView.onTextFocusChanged(); } @Override public boolean enoughToFilter() { return this.mThreshold <= 0 || super.enoughToFilter(); } @Override public boolean onKeyPreIme(int i, KeyEvent keyEvent) { if (i == 4) { if (keyEvent.getAction() == 0 && keyEvent.getRepeatCount() == 0) { KeyEvent.DispatcherState keyDispatcherState = getKeyDispatcherState(); if (keyDispatcherState != null) { keyDispatcherState.startTracking(keyEvent, this); } return true; } if (keyEvent.getAction() == 1) { KeyEvent.DispatcherState keyDispatcherState2 = getKeyDispatcherState(); if (keyDispatcherState2 != null) { keyDispatcherState2.handleUpEvent(keyEvent); } if (keyEvent.isTracking() && !keyEvent.isCanceled()) { this.mSearchView.clearFocus(); setImeVisibility(false); return true; } } } return super.onKeyPreIme(i, keyEvent); } private int getSearchViewTextMinWidthDp() { Configuration configuration = getResources().getConfiguration(); int i = configuration.screenWidthDp; int i2 = configuration.screenHeightDp; if (i >= 960 && i2 >= 720 && configuration.orientation == 2) { return 256; } if (i < 600) { return (i < 640 || i2 < 480) ? 160 : 192; } return 192; } @Override public InputConnection onCreateInputConnection(EditorInfo editorInfo) { InputConnection onCreateInputConnection = super.onCreateInputConnection(editorInfo); if (this.mHasPendingShowSoftInputRequest) { removeCallbacks(this.mRunShowSoftInputIfNecessary); post(this.mRunShowSoftInputIfNecessary); } return onCreateInputConnection; } void showSoftInputIfNecessary() { if (this.mHasPendingShowSoftInputRequest) { ((InputMethodManager) getContext().getSystemService("input_method")).showSoftInput(this, 0); this.mHasPendingShowSoftInputRequest = false; } } void setImeVisibility(boolean z) { InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService("input_method"); if (!z) { this.mHasPendingShowSoftInputRequest = false; removeCallbacks(this.mRunShowSoftInputIfNecessary); inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); } else { if (inputMethodManager.isActive(this)) { this.mHasPendingShowSoftInputRequest = false; removeCallbacks(this.mRunShowSoftInputIfNecessary); inputMethodManager.showSoftInput(this, 0); return; } this.mHasPendingShowSoftInputRequest = true; } } } public static class AutoCompleteTextViewReflector { private Method doAfterTextChanged; private Method doBeforeTextChanged; private Method ensureImeVisible; private Method showSoftInputUnchecked; AutoCompleteTextViewReflector() { try { this.doBeforeTextChanged = AutoCompleteTextView.class.getDeclaredMethod("doBeforeTextChanged", new Class[0]); this.doBeforeTextChanged.setAccessible(true); } catch (NoSuchMethodException unused) { } try { this.doAfterTextChanged = AutoCompleteTextView.class.getDeclaredMethod("doAfterTextChanged", new Class[0]); this.doAfterTextChanged.setAccessible(true); } catch (NoSuchMethodException unused2) { } try { this.ensureImeVisible = AutoCompleteTextView.class.getMethod("ensureImeVisible", Boolean.TYPE); this.ensureImeVisible.setAccessible(true); } catch (NoSuchMethodException unused3) { } } void doBeforeTextChanged(AutoCompleteTextView autoCompleteTextView) { Method method = this.doBeforeTextChanged; if (method != null) { try { method.invoke(autoCompleteTextView, new Object[0]); } catch (Exception unused) { } } } void doAfterTextChanged(AutoCompleteTextView autoCompleteTextView) { Method method = this.doAfterTextChanged; if (method != null) { try { method.invoke(autoCompleteTextView, new Object[0]); } catch (Exception unused) { } } } void ensureImeVisible(AutoCompleteTextView autoCompleteTextView, boolean z) { Method method = this.ensureImeVisible; if (method != null) { try { method.invoke(autoCompleteTextView, Boolean.valueOf(z)); } catch (Exception unused) { } } } } }