package androidx.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.ImageView;
import android.widget.TextView;
import com.google.android.gms.actions.SearchIntents;
import com.google.firebase.sessions.settings.RemoteSettings;
import java.util.WeakHashMap;
import net.sqlcipher.database.SQLiteDatabase;

/* loaded from: classes.dex */
public class SearchView extends LinearLayoutCompat implements n.c {
    private final AdapterView.OnItemClickListener A0;
    private final AdapterView.OnItemSelectedListener B0;
    private TextWatcher C0;
    final SearchAutoComplete E;
    private final View F;
    private final View G;
    private final View H;
    final ImageView I;
    final ImageView J;
    final ImageView K;
    final ImageView L;
    private final View M;
    private o N;
    private Rect O;
    private Rect P;
    private int[] Q;
    private int[] R;
    private final ImageView S;
    private final Drawable T;
    private final int U;
    private final int V;
    private final Intent W;

    /* renamed from: a0, reason: collision with root package name */
    private final Intent f864a0;

    /* renamed from: b0, reason: collision with root package name */
    private final CharSequence f865b0;

    /* renamed from: c0, reason: collision with root package name */
    private l f866c0;

    /* renamed from: d0, reason: collision with root package name */
    View.OnFocusChangeListener f867d0;

    /* renamed from: e0, reason: collision with root package name */
    private View.OnClickListener f868e0;

    /* renamed from: f0, reason: collision with root package name */
    private boolean f869f0;

    /* renamed from: g0, reason: collision with root package name */
    private boolean f870g0;

    /* renamed from: h0, reason: collision with root package name */
    x3.a f871h0;

    /* renamed from: i0, reason: collision with root package name */
    private boolean f872i0;

    /* renamed from: j0, reason: collision with root package name */
    private CharSequence f873j0;

    /* renamed from: k0, reason: collision with root package name */
    private boolean f874k0;

    /* renamed from: l0, reason: collision with root package name */
    private boolean f875l0;

    /* renamed from: m0, reason: collision with root package name */
    private int f876m0;

    /* renamed from: n0, reason: collision with root package name */
    private boolean f877n0;

    /* renamed from: o0, reason: collision with root package name */
    private CharSequence f878o0;

    /* renamed from: p0, reason: collision with root package name */
    private CharSequence f879p0;

    /* renamed from: q0, reason: collision with root package name */
    private boolean f880q0;

    /* renamed from: r0, reason: collision with root package name */
    private int f881r0;

    /* renamed from: s0, reason: collision with root package name */
    SearchableInfo f882s0;

    /* renamed from: t0, reason: collision with root package name */
    private Bundle f883t0;

    /* renamed from: u0, reason: collision with root package name */
    private final Runnable f884u0;

    /* renamed from: v0, reason: collision with root package name */
    private Runnable f885v0;

    /* renamed from: w0, reason: collision with root package name */
    private final WeakHashMap f886w0;

    /* renamed from: x0, reason: collision with root package name */
    private final View.OnClickListener f887x0;

    /* renamed from: y0, reason: collision with root package name */
    View.OnKeyListener f888y0;

    /* renamed from: z0, reason: collision with root package name */
    private final TextView.OnEditorActionListener f889z0;

    /* loaded from: classes.dex */
    public static class SearchAutoComplete extends androidx.appcompat.widget.d {

        /* renamed from: t, reason: collision with root package name */
        private int f890t;

        /* renamed from: u, reason: collision with root package name */
        private SearchView f891u;

        /* renamed from: v, reason: collision with root package name */
        private boolean f892v;

        /* renamed from: w, reason: collision with root package name */
        final Runnable f893w;

        /* loaded from: classes.dex */
        class a implements Runnable {
            a() {
            }

            @Override // java.lang.Runnable
            public void run() {
                SearchAutoComplete.this.d();
            }
        }

        public SearchAutoComplete(Context context, AttributeSet attributeSet) {
            this(context, attributeSet, h.a.f20159m);
        }

        private int getSearchViewTextMinWidthDp() {
            Configuration configuration = getResources().getConfiguration();
            int i10 = configuration.screenWidthDp;
            int i11 = configuration.screenHeightDp;
            if (i10 >= 960 && i11 >= 720 && configuration.orientation == 2) {
                return 256;
            }
            if (i10 < 600) {
                return (i10 < 640 || i11 < 480) ? 160 : 192;
            }
            return 192;
        }

        void b() {
            setInputMethodMode(1);
            if (enoughToFilter()) {
                showDropDown();
            }
        }

        boolean c() {
            return TextUtils.getTrimmedLength(getText()) == 0;
        }

        void d() {
            if (this.f892v) {
                ((InputMethodManager) getContext().getSystemService("input_method")).showSoftInput(this, 0);
                this.f892v = false;
            }
        }

        @Override // android.widget.AutoCompleteTextView
        public boolean enoughToFilter() {
            return this.f890t <= 0 || super.enoughToFilter();
        }

        @Override // androidx.appcompat.widget.d, android.widget.TextView, android.view.View
        public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
            InputConnection onCreateInputConnection = super.onCreateInputConnection(editorInfo);
            if (this.f892v) {
                removeCallbacks(this.f893w);
                post(this.f893w);
            }
            return onCreateInputConnection;
        }

        @Override // android.view.View
        protected void onFinishInflate() {
            super.onFinishInflate();
            setMinWidth((int) TypedValue.applyDimension(1, getSearchViewTextMinWidthDp(), getResources().getDisplayMetrics()));
        }

        @Override // android.widget.AutoCompleteTextView, android.widget.TextView, android.view.View
        protected void onFocusChanged(boolean z10, int i10, Rect rect) {
            super.onFocusChanged(z10, i10, rect);
            this.f891u.Z();
        }

        @Override // android.widget.AutoCompleteTextView, android.widget.TextView, android.view.View
        public boolean onKeyPreIme(int i10, KeyEvent keyEvent) {
            if (i10 == 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.f891u.clearFocus();
                        setImeVisibility(false);
                        return true;
                    }
                }
            }
            return super.onKeyPreIme(i10, keyEvent);
        }

        @Override // android.widget.AutoCompleteTextView, android.widget.TextView, android.view.View
        public void onWindowFocusChanged(boolean z10) {
            super.onWindowFocusChanged(z10);
            if (z10 && this.f891u.hasFocus() && getVisibility() == 0) {
                this.f892v = true;
                if (SearchView.M(getContext())) {
                    b();
                }
            }
        }

        @Override // android.widget.AutoCompleteTextView
        public void performCompletion() {
        }

        @Override // android.widget.AutoCompleteTextView
        protected void replaceText(CharSequence charSequence) {
        }

        void setImeVisibility(boolean z10) {
            InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService("input_method");
            if (!z10) {
                this.f892v = false;
                removeCallbacks(this.f893w);
                inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
            } else {
                if (!inputMethodManager.isActive(this)) {
                    this.f892v = true;
                    return;
                }
                this.f892v = false;
                removeCallbacks(this.f893w);
                inputMethodManager.showSoftInput(this, 0);
            }
        }

        void setSearchView(SearchView searchView) {
            this.f891u = searchView;
        }

        @Override // android.widget.AutoCompleteTextView
        public void setThreshold(int i10) {
            super.setThreshold(i10);
            this.f890t = i10;
        }

        public SearchAutoComplete(Context context, AttributeSet attributeSet, int i10) {
            super(context, attributeSet, i10);
            this.f893w = new a();
            this.f890t = getThreshold();
        }
    }

    /* loaded from: classes.dex */
    class a implements TextWatcher {
        a() {
        }

        @Override // android.text.TextWatcher
        public void afterTextChanged(Editable editable) {
        }

        @Override // android.text.TextWatcher
        public void beforeTextChanged(CharSequence charSequence, int i10, int i11, int i12) {
        }

        @Override // android.text.TextWatcher
        public void onTextChanged(CharSequence charSequence, int i10, int i11, int i12) {
            SearchView.this.Y(charSequence);
        }
    }

    /* loaded from: classes.dex */
    class b implements Runnable {
        b() {
        }

        @Override // java.lang.Runnable
        public void run() {
            SearchView.this.f0();
        }
    }

    /* loaded from: classes.dex */
    class c implements Runnable {
        c() {
        }

        @Override // java.lang.Runnable
        public void run() {
            x3.a aVar = SearchView.this.f871h0;
            if (aVar instanceof q0) {
                aVar.a(null);
            }
        }
    }

    /* loaded from: classes.dex */
    class d implements View.OnFocusChangeListener {
        d() {
        }

        @Override // android.view.View.OnFocusChangeListener
        public void onFocusChange(View view, boolean z10) {
            SearchView searchView = SearchView.this;
            View.OnFocusChangeListener onFocusChangeListener = searchView.f867d0;
            if (onFocusChangeListener != null) {
                onFocusChangeListener.onFocusChange(searchView, z10);
            }
        }
    }

    /* loaded from: classes.dex */
    class e implements View.OnLayoutChangeListener {
        e() {
        }

        @Override // android.view.View.OnLayoutChangeListener
        public void onLayoutChange(View view, int i10, int i11, int i12, int i13, int i14, int i15, int i16, int i17) {
            SearchView.this.B();
        }
    }

    /* loaded from: classes.dex */
    class f implements View.OnClickListener {
        f() {
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            SearchView searchView = SearchView.this;
            if (view == searchView.I) {
                searchView.V();
                return;
            }
            if (view == searchView.K) {
                searchView.R();
                return;
            }
            if (view == searchView.J) {
                searchView.W();
            } else if (view == searchView.L) {
                searchView.a0();
            } else if (view == searchView.E) {
                searchView.H();
            }
        }
    }

    /* loaded from: classes.dex */
    class g implements View.OnKeyListener {
        g() {
        }

        @Override // android.view.View.OnKeyListener
        public boolean onKey(View view, int i10, KeyEvent keyEvent) {
            SearchView searchView = SearchView.this;
            if (searchView.f882s0 == null) {
                return false;
            }
            if (searchView.E.isPopupShowing() && SearchView.this.E.getListSelection() != -1) {
                return SearchView.this.X(view, i10, keyEvent);
            }
            if (SearchView.this.E.c() || !keyEvent.hasNoModifiers() || keyEvent.getAction() != 1 || i10 != 66) {
                return false;
            }
            view.cancelLongPress();
            SearchView searchView2 = SearchView.this;
            searchView2.P(0, null, searchView2.E.getText().toString());
            return true;
        }
    }

    /* loaded from: classes.dex */
    class h implements TextView.OnEditorActionListener {
        h() {
        }

        @Override // android.widget.TextView.OnEditorActionListener
        public boolean onEditorAction(TextView textView, int i10, KeyEvent keyEvent) {
            SearchView.this.W();
            return true;
        }
    }

    /* loaded from: classes.dex */
    class i implements AdapterView.OnItemClickListener {
        i() {
        }

        @Override // android.widget.AdapterView.OnItemClickListener
        public void onItemClick(AdapterView adapterView, View view, int i10, long j10) {
            SearchView.this.S(i10, 0, null);
        }
    }

    /* loaded from: classes.dex */
    class j implements AdapterView.OnItemSelectedListener {
        j() {
        }

        @Override // android.widget.AdapterView.OnItemSelectedListener
        public void onItemSelected(AdapterView adapterView, View view, int i10, long j10) {
            SearchView.this.T(i10);
        }

        @Override // android.widget.AdapterView.OnItemSelectedListener
        public void onNothingSelected(AdapterView adapterView) {
        }
    }

    /* loaded from: classes.dex */
    public interface k {
    }

    /* loaded from: classes.dex */
    public interface l {
        boolean onQueryTextChange(String str);

        boolean onQueryTextSubmit(String str);
    }

    /* loaded from: classes.dex */
    public interface m {
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class n extends z3.a {
        public static final Parcelable.Creator<n> CREATOR = new a();

        /* renamed from: r, reason: collision with root package name */
        boolean f905r;

        /* loaded from: classes.dex */
        class a implements Parcelable.ClassLoaderCreator {
            a() {
            }

            @Override // android.os.Parcelable.Creator
            /* renamed from: a, reason: merged with bridge method [inline-methods] */
            public n createFromParcel(Parcel parcel) {
                return new n(parcel, null);
            }

            @Override // android.os.Parcelable.ClassLoaderCreator
            /* renamed from: b, reason: merged with bridge method [inline-methods] */
            public n createFromParcel(Parcel parcel, ClassLoader classLoader) {
                return new n(parcel, classLoader);
            }

            @Override // android.os.Parcelable.Creator
            /* renamed from: c, reason: merged with bridge method [inline-methods] */
            public n[] newArray(int i10) {
                return new n[i10];
            }
        }

        n(Parcelable parcelable) {
            super(parcelable);
        }

        public String toString() {
            return "SearchView.SavedState{" + Integer.toHexString(System.identityHashCode(this)) + " isIconified=" + this.f905r + "}";
        }

        @Override // z3.a, android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i10) {
            super.writeToParcel(parcel, i10);
            parcel.writeValue(Boolean.valueOf(this.f905r));
        }

        public n(Parcel parcel, ClassLoader classLoader) {
            super(parcel, classLoader);
            this.f905r = ((Boolean) parcel.readValue(null)).booleanValue();
        }
    }

    /* loaded from: classes.dex */
    private static class o extends TouchDelegate {

        /* renamed from: a, reason: collision with root package name */
        private final View f906a;

        /* renamed from: b, reason: collision with root package name */
        private final Rect f907b;

        /* renamed from: c, reason: collision with root package name */
        private final Rect f908c;

        /* renamed from: d, reason: collision with root package name */
        private final Rect f909d;

        /* renamed from: e, reason: collision with root package name */
        private final int f910e;

        /* renamed from: f, reason: collision with root package name */
        private boolean f911f;

        public o(Rect rect, Rect rect2, View view) {
            super(rect, view);
            this.f910e = ViewConfiguration.get(view.getContext()).getScaledTouchSlop();
            this.f907b = new Rect();
            this.f909d = new Rect();
            this.f908c = new Rect();
            a(rect, rect2);
            this.f906a = view;
        }

        public void a(Rect rect, Rect rect2) {
            this.f907b.set(rect);
            this.f909d.set(rect);
            Rect rect3 = this.f909d;
            int i10 = this.f910e;
            rect3.inset(-i10, -i10);
            this.f908c.set(rect2);
        }

        @Override // android.view.TouchDelegate
        public boolean onTouchEvent(MotionEvent motionEvent) {
            boolean z10;
            boolean z11;
            int x10 = (int) motionEvent.getX();
            int y10 = (int) motionEvent.getY();
            int action = motionEvent.getAction();
            boolean z12 = true;
            if (action != 0) {
                if (action == 1 || action == 2) {
                    z11 = this.f911f;
                    if (z11 && !this.f909d.contains(x10, y10)) {
                        z12 = z11;
                        z10 = false;
                    }
                } else {
                    if (action == 3) {
                        z11 = this.f911f;
                        this.f911f = false;
                    }
                    z10 = true;
                    z12 = false;
                }
                z12 = z11;
                z10 = true;
            } else {
                if (this.f907b.contains(x10, y10)) {
                    this.f911f = true;
                    z10 = true;
                }
                z10 = true;
                z12 = false;
            }
            if (!z12) {
                return false;
            }
            if (!z10 || this.f908c.contains(x10, y10)) {
                Rect rect = this.f908c;
                motionEvent.setLocation(x10 - rect.left, y10 - rect.top);
            } else {
                motionEvent.setLocation(this.f906a.getWidth() / 2, this.f906a.getHeight() / 2);
            }
            return this.f906a.dispatchTouchEvent(motionEvent);
        }
    }

    public SearchView(Context context) {
        this(context, null);
    }

    private Intent C(String str, Uri uri, String str2, String str3, int i10, String str4) {
        Intent intent = new Intent(str);
        intent.addFlags(SQLiteDatabase.CREATE_IF_NECESSARY);
        if (uri != null) {
            intent.setData(uri);
        }
        intent.putExtra("user_query", this.f879p0);
        if (str3 != null) {
            intent.putExtra(SearchIntents.EXTRA_QUERY, str3);
        }
        if (str2 != null) {
            intent.putExtra("intent_extra_data_key", str2);
        }
        Bundle bundle = this.f883t0;
        if (bundle != null) {
            intent.putExtra("app_data", bundle);
        }
        if (i10 != 0) {
            intent.putExtra("action_key", i10);
            intent.putExtra("action_msg", str4);
        }
        intent.setComponent(this.f882s0.getSearchActivity());
        return intent;
    }

    private Intent D(Cursor cursor, int i10, String str) {
        int i11;
        String o10;
        try {
            String o11 = q0.o(cursor, "suggest_intent_action");
            if (o11 == null) {
                o11 = this.f882s0.getSuggestIntentAction();
            }
            if (o11 == null) {
                o11 = "android.intent.action.SEARCH";
            }
            String str2 = o11;
            String o12 = q0.o(cursor, "suggest_intent_data");
            if (o12 == null) {
                o12 = this.f882s0.getSuggestIntentData();
            }
            if (o12 != null && (o10 = q0.o(cursor, "suggest_intent_data_id")) != null) {
                o12 = o12 + RemoteSettings.FORWARD_SLASH_STRING + Uri.encode(o10);
            }
            return C(str2, o12 == null ? null : Uri.parse(o12), q0.o(cursor, "suggest_intent_extra_data"), q0.o(cursor, "suggest_intent_query"), i10, str);
        } catch (RuntimeException e10) {
            try {
                i11 = cursor.getPosition();
            } catch (RuntimeException unused) {
                i11 = -1;
            }
            Log.w("SearchView", "Search suggestions cursor at row " + i11 + " returned exception.", e10);
            return null;
        }
    }

    private Intent E(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, 1107296256);
        Bundle bundle = new Bundle();
        Bundle bundle2 = this.f883t0;
        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 F(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 void G() {
        this.E.dismissDropDown();
    }

    private void I(View view, Rect rect) {
        view.getLocationInWindow(this.Q);
        getLocationInWindow(this.R);
        int[] iArr = this.Q;
        int i10 = iArr[1];
        int[] iArr2 = this.R;
        int i11 = i10 - iArr2[1];
        int i12 = iArr[0] - iArr2[0];
        rect.set(i12, i11, view.getWidth() + i12, view.getHeight() + i11);
    }

    private CharSequence J(CharSequence charSequence) {
        if (!this.f869f0 || this.T == null) {
            return charSequence;
        }
        int textSize = (int) (this.E.getTextSize() * 1.25d);
        this.T.setBounds(0, 0, textSize, textSize);
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("   ");
        spannableStringBuilder.setSpan(new ImageSpan(this.T), 1, 2, 33);
        spannableStringBuilder.append(charSequence);
        return spannableStringBuilder;
    }

    private boolean K() {
        SearchableInfo searchableInfo = this.f882s0;
        if (searchableInfo == null || !searchableInfo.getVoiceSearchEnabled()) {
            return false;
        }
        Intent intent = this.f882s0.getVoiceSearchLaunchWebSearch() ? this.W : this.f882s0.getVoiceSearchLaunchRecognizer() ? this.f864a0 : null;
        return (intent == null || getContext().getPackageManager().resolveActivity(intent, 65536) == null) ? false : true;
    }

    static boolean M(Context context) {
        return context.getResources().getConfiguration().orientation == 2;
    }

    private boolean N() {
        return (this.f872i0 || this.f877n0) && !L();
    }

    private void O(Intent intent) {
        if (intent == null) {
            return;
        }
        try {
            getContext().startActivity(intent);
        } catch (RuntimeException e10) {
            Log.e("SearchView", "Failed launch activity: " + intent, e10);
        }
    }

    private boolean Q(int i10, int i11, String str) {
        Cursor b10 = this.f871h0.b();
        if (b10 == null || !b10.moveToPosition(i10)) {
            return false;
        }
        O(D(b10, i11, str));
        return true;
    }

    private void b0() {
        post(this.f884u0);
    }

    private void c0(int i10) {
        Editable text = this.E.getText();
        Cursor b10 = this.f871h0.b();
        if (b10 == null) {
            return;
        }
        if (!b10.moveToPosition(i10)) {
            setQuery(text);
            return;
        }
        CharSequence c10 = this.f871h0.c(b10);
        if (c10 != null) {
            setQuery(c10);
        } else {
            setQuery(text);
        }
    }

    private void e0() {
        boolean z10 = true;
        boolean z11 = !TextUtils.isEmpty(this.E.getText());
        if (!z11 && (!this.f869f0 || this.f880q0)) {
            z10 = false;
        }
        this.K.setVisibility(z10 ? 0 : 8);
        Drawable drawable = this.K.getDrawable();
        if (drawable != null) {
            drawable.setState(z11 ? ViewGroup.ENABLED_STATE_SET : ViewGroup.EMPTY_STATE_SET);
        }
    }

    private void g0() {
        CharSequence queryHint = getQueryHint();
        SearchAutoComplete searchAutoComplete = this.E;
        if (queryHint == null) {
            queryHint = "";
        }
        searchAutoComplete.setHint(J(queryHint));
    }

    private int getPreferredHeight() {
        return getContext().getResources().getDimensionPixelSize(h.d.f20186e);
    }

    private int getPreferredWidth() {
        return getContext().getResources().getDimensionPixelSize(h.d.f20187f);
    }

    private void h0() {
        this.E.setThreshold(this.f882s0.getSuggestThreshold());
        this.E.setImeOptions(this.f882s0.getImeOptions());
        int inputType = this.f882s0.getInputType();
        if ((inputType & 15) == 1) {
            inputType &= -65537;
            if (this.f882s0.getSuggestAuthority() != null) {
                inputType = inputType | 65536 | 524288;
            }
        }
        this.E.setInputType(inputType);
        x3.a aVar = this.f871h0;
        if (aVar != null) {
            aVar.a(null);
        }
        if (this.f882s0.getSuggestAuthority() != null) {
            q0 q0Var = new q0(getContext(), this, this.f882s0, this.f886w0);
            this.f871h0 = q0Var;
            this.E.setAdapter(q0Var);
            ((q0) this.f871h0).x(this.f874k0 ? 2 : 1);
        }
    }

    private void i0() {
        this.H.setVisibility((N() && (this.J.getVisibility() == 0 || this.L.getVisibility() == 0)) ? 0 : 8);
    }

    private void j0(boolean z10) {
        this.J.setVisibility((this.f872i0 && N() && hasFocus() && (z10 || !this.f877n0)) ? 0 : 8);
    }

    private void k0(boolean z10) {
        this.f870g0 = z10;
        int i10 = z10 ? 0 : 8;
        boolean z11 = !TextUtils.isEmpty(this.E.getText());
        this.I.setVisibility(i10);
        j0(z11);
        this.F.setVisibility(z10 ? 8 : 0);
        this.S.setVisibility((this.S.getDrawable() == null || this.f869f0) ? 8 : 0);
        e0();
        l0(!z11);
        i0();
    }

    private void l0(boolean z10) {
        int i10 = 8;
        if (this.f877n0 && !L() && z10) {
            this.J.setVisibility(8);
            i10 = 0;
        }
        this.L.setVisibility(i10);
    }

    private void setQuery(CharSequence charSequence) {
        this.E.setText(charSequence);
        this.E.setSelection(TextUtils.isEmpty(charSequence) ? 0 : charSequence.length());
    }

    void B() {
        if (this.M.getWidth() > 1) {
            Resources resources = getContext().getResources();
            int paddingLeft = this.G.getPaddingLeft();
            Rect rect = new Rect();
            boolean b10 = a1.b(this);
            int dimensionPixelSize = this.f869f0 ? resources.getDimensionPixelSize(h.d.f20184c) + resources.getDimensionPixelSize(h.d.f20185d) : 0;
            this.E.getDropDownBackground().getPadding(rect);
            this.E.setDropDownHorizontalOffset(b10 ? -rect.left : paddingLeft - (rect.left + dimensionPixelSize));
            this.E.setDropDownWidth((((this.M.getWidth() + rect.left) + rect.right) + dimensionPixelSize) - paddingLeft);
        }
    }

    void H() {
        this.E.refreshAutoCompleteResults();
    }

    public boolean L() {
        return this.f870g0;
    }

    void P(int i10, String str, String str2) {
        getContext().startActivity(C("android.intent.action.SEARCH", null, null, str2, i10, str));
    }

    void R() {
        if (!TextUtils.isEmpty(this.E.getText())) {
            this.E.setText("");
            this.E.requestFocus();
            this.E.setImeVisibility(true);
        } else if (this.f869f0) {
            clearFocus();
            k0(true);
        }
    }

    boolean S(int i10, int i11, String str) {
        Q(i10, 0, null);
        this.E.setImeVisibility(false);
        G();
        return true;
    }

    boolean T(int i10) {
        c0(i10);
        return true;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void U(CharSequence charSequence) {
        setQuery(charSequence);
    }

    void V() {
        k0(false);
        this.E.requestFocus();
        this.E.setImeVisibility(true);
        View.OnClickListener onClickListener = this.f868e0;
        if (onClickListener != null) {
            onClickListener.onClick(this);
        }
    }

    void W() {
        Editable text = this.E.getText();
        if (text == null || TextUtils.getTrimmedLength(text) <= 0) {
            return;
        }
        l lVar = this.f866c0;
        if (lVar == null || !lVar.onQueryTextSubmit(text.toString())) {
            if (this.f882s0 != null) {
                P(0, null, text.toString());
            }
            this.E.setImeVisibility(false);
            G();
        }
    }

    boolean X(View view, int i10, KeyEvent keyEvent) {
        if (this.f882s0 != null && this.f871h0 != null && keyEvent.getAction() == 0 && keyEvent.hasNoModifiers()) {
            if (i10 == 66 || i10 == 84 || i10 == 61) {
                return S(this.E.getListSelection(), 0, null);
            }
            if (i10 == 21 || i10 == 22) {
                this.E.setSelection(i10 == 21 ? 0 : this.E.length());
                this.E.setListSelection(0);
                this.E.clearListSelection();
                this.E.b();
                return true;
            }
            if (i10 == 19) {
                this.E.getListSelection();
                return false;
            }
        }
        return false;
    }

    void Y(CharSequence charSequence) {
        Editable text = this.E.getText();
        this.f879p0 = text;
        boolean z10 = !TextUtils.isEmpty(text);
        j0(z10);
        l0(!z10);
        e0();
        i0();
        if (this.f866c0 != null && !TextUtils.equals(charSequence, this.f878o0)) {
            this.f866c0.onQueryTextChange(charSequence.toString());
        }
        this.f878o0 = charSequence.toString();
    }

    void Z() {
        k0(L());
        b0();
        if (this.E.hasFocus()) {
            H();
        }
    }

    void a0() {
        SearchableInfo searchableInfo = this.f882s0;
        if (searchableInfo == null) {
            return;
        }
        try {
            if (searchableInfo.getVoiceSearchLaunchWebSearch()) {
                getContext().startActivity(F(this.W, searchableInfo));
            } else if (searchableInfo.getVoiceSearchLaunchRecognizer()) {
                getContext().startActivity(E(this.f864a0, searchableInfo));
            }
        } catch (ActivityNotFoundException unused) {
            Log.w("SearchView", "Could not find voice search activity");
        }
    }

    @Override // n.c
    public void c() {
        if (this.f880q0) {
            return;
        }
        this.f880q0 = true;
        int imeOptions = this.E.getImeOptions();
        this.f881r0 = imeOptions;
        this.E.setImeOptions(imeOptions | 33554432);
        this.E.setText("");
        setIconified(false);
    }

    @Override // android.view.ViewGroup, android.view.View
    public void clearFocus() {
        this.f875l0 = true;
        super.clearFocus();
        this.E.clearFocus();
        this.E.setImeVisibility(false);
        this.f875l0 = false;
    }

    public void d0(CharSequence charSequence, boolean z10) {
        this.E.setText(charSequence);
        if (charSequence != null) {
            SearchAutoComplete searchAutoComplete = this.E;
            searchAutoComplete.setSelection(searchAutoComplete.length());
            this.f879p0 = charSequence;
        }
        if (!z10 || TextUtils.isEmpty(charSequence)) {
            return;
        }
        W();
    }

    @Override // n.c
    public void f() {
        d0("", false);
        clearFocus();
        k0(true);
        this.E.setImeOptions(this.f881r0);
        this.f880q0 = false;
    }

    void f0() {
        int[] iArr = this.E.hasFocus() ? ViewGroup.FOCUSED_STATE_SET : ViewGroup.EMPTY_STATE_SET;
        Drawable background = this.G.getBackground();
        if (background != null) {
            background.setState(iArr);
        }
        Drawable background2 = this.H.getBackground();
        if (background2 != null) {
            background2.setState(iArr);
        }
        invalidate();
    }

    public int getImeOptions() {
        return this.E.getImeOptions();
    }

    public int getInputType() {
        return this.E.getInputType();
    }

    public int getMaxWidth() {
        return this.f876m0;
    }

    public CharSequence getQuery() {
        return this.E.getText();
    }

    public CharSequence getQueryHint() {
        CharSequence charSequence = this.f873j0;
        if (charSequence != null) {
            return charSequence;
        }
        SearchableInfo searchableInfo = this.f882s0;
        return (searchableInfo == null || searchableInfo.getHintId() == 0) ? this.f865b0 : getContext().getText(this.f882s0.getHintId());
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public int getSuggestionCommitIconResId() {
        return this.V;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public int getSuggestionRowLayout() {
        return this.U;
    }

    public x3.a getSuggestionsAdapter() {
        return this.f871h0;
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onDetachedFromWindow() {
        removeCallbacks(this.f884u0);
        post(this.f885v0);
        super.onDetachedFromWindow();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.appcompat.widget.LinearLayoutCompat, android.view.ViewGroup, android.view.View
    public void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        super.onLayout(z10, i10, i11, i12, i13);
        if (z10) {
            I(this.E, this.O);
            Rect rect = this.P;
            Rect rect2 = this.O;
            rect.set(rect2.left, 0, rect2.right, i13 - i11);
            o oVar = this.N;
            if (oVar != null) {
                oVar.a(this.P, this.O);
                return;
            }
            o oVar2 = new o(this.P, this.O, this.E);
            this.N = oVar2;
            setTouchDelegate(oVar2);
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.appcompat.widget.LinearLayoutCompat, android.view.View
    public void onMeasure(int i10, int i11) {
        int i12;
        if (L()) {
            super.onMeasure(i10, i11);
            return;
        }
        int mode = View.MeasureSpec.getMode(i10);
        int size = View.MeasureSpec.getSize(i10);
        if (mode == Integer.MIN_VALUE) {
            int i13 = this.f876m0;
            size = i13 > 0 ? Math.min(i13, size) : Math.min(getPreferredWidth(), size);
        } else if (mode == 0) {
            size = this.f876m0;
            if (size <= 0) {
                size = getPreferredWidth();
            }
        } else if (mode == 1073741824 && (i12 = this.f876m0) > 0) {
            size = Math.min(i12, size);
        }
        int mode2 = View.MeasureSpec.getMode(i11);
        int size2 = View.MeasureSpec.getSize(i11);
        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 // android.view.View
    protected void onRestoreInstanceState(Parcelable parcelable) {
        if (!(parcelable instanceof n)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        n nVar = (n) parcelable;
        super.onRestoreInstanceState(nVar.a());
        k0(nVar.f905r);
        requestLayout();
    }

    @Override // android.view.View
    protected Parcelable onSaveInstanceState() {
        n nVar = new n(super.onSaveInstanceState());
        nVar.f905r = L();
        return nVar;
    }

    @Override // android.view.View
    public void onWindowFocusChanged(boolean z10) {
        super.onWindowFocusChanged(z10);
        b0();
    }

    @Override // android.view.ViewGroup, android.view.View
    public boolean requestFocus(int i10, Rect rect) {
        if (this.f875l0 || !isFocusable()) {
            return false;
        }
        if (L()) {
            return super.requestFocus(i10, rect);
        }
        boolean requestFocus = this.E.requestFocus(i10, rect);
        if (requestFocus) {
            k0(false);
        }
        return requestFocus;
    }

    public void setAppSearchData(Bundle bundle) {
        this.f883t0 = bundle;
    }

    public void setIconified(boolean z10) {
        if (z10) {
            R();
        } else {
            V();
        }
    }

    public void setIconifiedByDefault(boolean z10) {
        if (this.f869f0 == z10) {
            return;
        }
        this.f869f0 = z10;
        k0(z10);
        g0();
    }

    public void setImeOptions(int i10) {
        this.E.setImeOptions(i10);
    }

    public void setInputType(int i10) {
        this.E.setInputType(i10);
    }

    public void setMaxWidth(int i10) {
        this.f876m0 = i10;
        requestLayout();
    }

    public void setOnCloseListener(k kVar) {
    }

    public void setOnQueryTextFocusChangeListener(View.OnFocusChangeListener onFocusChangeListener) {
        this.f867d0 = onFocusChangeListener;
    }

    public void setOnQueryTextListener(l lVar) {
        this.f866c0 = lVar;
    }

    public void setOnSearchClickListener(View.OnClickListener onClickListener) {
        this.f868e0 = onClickListener;
    }

    public void setOnSuggestionListener(m mVar) {
    }

    public void setQueryHint(CharSequence charSequence) {
        this.f873j0 = charSequence;
        g0();
    }

    public void setQueryRefinementEnabled(boolean z10) {
        this.f874k0 = z10;
        x3.a aVar = this.f871h0;
        if (aVar instanceof q0) {
            ((q0) aVar).x(z10 ? 2 : 1);
        }
    }

    public void setSearchableInfo(SearchableInfo searchableInfo) {
        this.f882s0 = searchableInfo;
        if (searchableInfo != null) {
            h0();
            g0();
        }
        boolean K = K();
        this.f877n0 = K;
        if (K) {
            this.E.setPrivateImeOptions("nm");
        }
        k0(L());
    }

    public void setSubmitButtonEnabled(boolean z10) {
        this.f872i0 = z10;
        k0(L());
    }

    public void setSuggestionsAdapter(x3.a aVar) {
        this.f871h0 = aVar;
        this.E.setAdapter(aVar);
    }

    public SearchView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, h.a.H);
    }

    public SearchView(Context context, AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        this.O = new Rect();
        this.P = new Rect();
        this.Q = new int[2];
        this.R = new int[2];
        this.f884u0 = new b();
        this.f885v0 = new c();
        this.f886w0 = new WeakHashMap();
        f fVar = new f();
        this.f887x0 = fVar;
        this.f888y0 = new g();
        h hVar = new h();
        this.f889z0 = hVar;
        i iVar = new i();
        this.A0 = iVar;
        j jVar = new j();
        this.B0 = jVar;
        this.C0 = new a();
        int[] iArr = h.j.f20349n2;
        v0 v10 = v0.v(context, attributeSet, iArr, i10, 0);
        androidx.core.view.s0.k0(this, context, iArr, attributeSet, v10.r(), i10, 0);
        LayoutInflater.from(context).inflate(v10.n(h.j.f20399x2, h.g.f20260r), (ViewGroup) this, true);
        SearchAutoComplete searchAutoComplete = (SearchAutoComplete) findViewById(h.f.C);
        this.E = searchAutoComplete;
        searchAutoComplete.setSearchView(this);
        this.F = findViewById(h.f.f20241y);
        View findViewById = findViewById(h.f.B);
        this.G = findViewById;
        View findViewById2 = findViewById(h.f.I);
        this.H = findViewById2;
        ImageView imageView = (ImageView) findViewById(h.f.f20239w);
        this.I = imageView;
        ImageView imageView2 = (ImageView) findViewById(h.f.f20242z);
        this.J = imageView2;
        ImageView imageView3 = (ImageView) findViewById(h.f.f20240x);
        this.K = imageView3;
        ImageView imageView4 = (ImageView) findViewById(h.f.D);
        this.L = imageView4;
        ImageView imageView5 = (ImageView) findViewById(h.f.A);
        this.S = imageView5;
        androidx.core.view.s0.q0(findViewById, v10.g(h.j.f20404y2));
        androidx.core.view.s0.q0(findViewById2, v10.g(h.j.C2));
        int i11 = h.j.B2;
        imageView.setImageDrawable(v10.g(i11));
        imageView2.setImageDrawable(v10.g(h.j.f20389v2));
        imageView3.setImageDrawable(v10.g(h.j.f20374s2));
        imageView4.setImageDrawable(v10.g(h.j.E2));
        imageView5.setImageDrawable(v10.g(i11));
        this.T = v10.g(h.j.A2);
        y0.a(imageView, getResources().getString(h.h.f20275n));
        this.U = v10.n(h.j.D2, h.g.f20259q);
        this.V = v10.n(h.j.f20379t2, 0);
        imageView.setOnClickListener(fVar);
        imageView3.setOnClickListener(fVar);
        imageView2.setOnClickListener(fVar);
        imageView4.setOnClickListener(fVar);
        searchAutoComplete.setOnClickListener(fVar);
        searchAutoComplete.addTextChangedListener(this.C0);
        searchAutoComplete.setOnEditorActionListener(hVar);
        searchAutoComplete.setOnItemClickListener(iVar);
        searchAutoComplete.setOnItemSelectedListener(jVar);
        searchAutoComplete.setOnKeyListener(this.f888y0);
        searchAutoComplete.setOnFocusChangeListener(new d());
        setIconifiedByDefault(v10.a(h.j.f20394w2, true));
        int f10 = v10.f(h.j.f20359p2, -1);
        if (f10 != -1) {
            setMaxWidth(f10);
        }
        this.f865b0 = v10.p(h.j.f20384u2);
        this.f873j0 = v10.p(h.j.f20409z2);
        int k10 = v10.k(h.j.f20369r2, -1);
        if (k10 != -1) {
            setImeOptions(k10);
        }
        int k11 = v10.k(h.j.f20364q2, -1);
        if (k11 != -1) {
            setInputType(k11);
        }
        setFocusable(v10.a(h.j.f20354o2, true));
        v10.w();
        Intent intent = new Intent("android.speech.action.WEB_SEARCH");
        this.W = intent;
        intent.addFlags(SQLiteDatabase.CREATE_IF_NECESSARY);
        intent.putExtra("android.speech.extra.LANGUAGE_MODEL", "web_search");
        Intent intent2 = new Intent("android.speech.action.RECOGNIZE_SPEECH");
        this.f864a0 = intent2;
        intent2.addFlags(SQLiteDatabase.CREATE_IF_NECESSARY);
        View findViewById3 = findViewById(searchAutoComplete.getDropDownAnchor());
        this.M = findViewById3;
        if (findViewById3 != null) {
            findViewById3.addOnLayoutChangeListener(new e());
        }
        k0(this.f869f0);
        g0();
    }
}
