package defpackage;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.media.SoundPool;
import android.os.Handler;
import android.speech.SpeechRecognizer;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import androidx.leanback.widget.SearchEditText;
import androidx.leanback.widget.SpeechOrbView;
import ar.tvplayer.tv.R;

/* renamed from: ᵛˊ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public abstract class AbstractC2730 extends RelativeLayout {

    /* renamed from: ᵳᵹᵺˋ, reason: contains not printable characters */
    public static final /* synthetic */ int f10569 = 0;

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public String f10570;

    /* renamed from: ˀᵗᵩ, reason: contains not printable characters */
    public final SparseIntArray f10571;

    /* renamed from: ˁˑᵰ, reason: contains not printable characters */
    public final int f10572;

    /* renamed from: ˆᵼᵷˊ, reason: contains not printable characters */
    public boolean f10573;

    /* renamed from: ˊᵸˊ, reason: contains not printable characters */
    public SoundPool f10574;

    /* renamed from: ˌᵪ, reason: contains not printable characters */
    public InterfaceC0716 f10575;

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public final InputMethodManager f10576;

    /* renamed from: ˑᵝﹳᵜ, reason: contains not printable characters */
    public boolean f10577;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public final Handler f10578;

    /* renamed from: ᐧﾞ, reason: contains not printable characters */
    public final int f10579;

    /* renamed from: ᵙᵢᵨᵳ, reason: contains not printable characters */
    public final int f10580;

    /* renamed from: ᵛˈᵤ, reason: contains not printable characters */
    public final Context f10581;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public Drawable f10582;

    /* renamed from: ᵡᵘˎʽ, reason: contains not printable characters */
    public SpeechRecognizer f10583;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public String f10584;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public SearchEditText f10585;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public String f10586;

    /* renamed from: ᵧـˌᵎ, reason: contains not printable characters */
    public Drawable f10587;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public InterfaceC3284 f10588;

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public boolean f10589;

    /* renamed from: ᵶʔᵢˊ, reason: contains not printable characters */
    public final int f10590;

    /* renamed from: ᵺʙ, reason: contains not printable characters */
    public final int f10591;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public ImageView f10592;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public SpeechOrbView f10593;

    /* renamed from: ﾞⁱ, reason: contains not printable characters */
    public final int f10594;

    public AbstractC2730(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.f10578 = new Handler();
        this.f10589 = false;
        this.f10571 = new SparseIntArray();
        this.f10573 = false;
        this.f10581 = context;
        Resources resources = getResources();
        LayoutInflater.from(getContext()).inflate(R.layout.lb_search_bar, (ViewGroup) this, true);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, getResources().getDimensionPixelSize(R.dimen._11_res_0x7f0701ba));
        layoutParams.addRule(10, -1);
        setLayoutParams(layoutParams);
        setBackgroundColor(0);
        setClipChildren(false);
        this.f10586 = "";
        this.f10576 = (InputMethodManager) context.getSystemService("input_method");
        this.f10579 = resources.getColor(R.color._11_res_0x7f0600f6);
        this.f10591 = resources.getColor(R.color._11_res_0x7f0600f5);
        this.f10580 = resources.getInteger(R.integer._11_res_0x7f0c002e);
        this.f10594 = resources.getInteger(R.integer._11_res_0x7f0c002f);
        this.f10572 = resources.getColor(R.color._11_res_0x7f0600f4);
        this.f10590 = resources.getColor(R.color._11_res_0x7f0600f3);
    }

    public Drawable getBadgeDrawable() {
        return this.f10582;
    }

    public CharSequence getHint() {
        return this.f10584;
    }

    public String getTitle() {
        return this.f10570;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.f10574 = new SoundPool(2, 1, 0);
        int[] iArr = {R.raw._11_res_0x7f120004, R.raw._11_res_0x7f120006, R.raw._11_res_0x7f120005, R.raw._11_res_0x7f120007};
        for (int i = 0; i < 4; i++) {
            int i2 = iArr[i];
            this.f10571.put(i2, this.f10574.load(this.f10581, i2, 1));
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onDetachedFromWindow() {
        m6774();
        this.f10574.release();
        super.onDetachedFromWindow();
    }

    @Override // android.view.View
    public void onFinishInflate() throws Resources.NotFoundException {
        super.onFinishInflate();
        this.f10587 = ((RelativeLayout) findViewById(R.id._11_res_0x7f0b0252)).getBackground();
        this.f10585 = (SearchEditText) findViewById(R.id._11_res_0x7f0b0255);
        ImageView imageView = (ImageView) findViewById(R.id._11_res_0x7f0b0251);
        this.f10592 = imageView;
        Drawable drawable = this.f10582;
        if (drawable != null) {
            imageView.setImageDrawable(drawable);
        }
        this.f10585.setOnFocusChangeListener(new ViewOnFocusChangeListenerC4245(this, 0));
        this.f10585.addTextChangedListener(new ᵘˀᵞ(this, new RunnableC5319(this, 0)));
        this.f10585.setOnKeyboardDismissListener(new ˊʘ(17, this));
        this.f10585.setOnEditorActionListener(new C4015(2, this));
        this.f10585.setPrivateImeOptions("escapeNorth,voiceDismiss");
        SpeechOrbView speechOrbView = (SpeechOrbView) findViewById(R.id._11_res_0x7f0b0253);
        this.f10593 = speechOrbView;
        speechOrbView.setOnOrbClickedListener(new ViewOnClickListenerC4018(4, this));
        this.f10593.setOnFocusChangeListener(new ViewOnFocusChangeListenerC4245(this, 1));
        m6773(hasFocus());
        m6777();
    }

    public void setBadgeDrawable(Drawable drawable) {
        this.f10582 = drawable;
        ImageView imageView = this.f10592;
        if (imageView != null) {
            imageView.setImageDrawable(drawable);
            ImageView imageView2 = this.f10592;
            if (drawable != null) {
                imageView2.setVisibility(0);
            } else {
                imageView2.setVisibility(8);
            }
        }
    }

    @Override // android.view.View
    public void setNextFocusDownId(int i) {
        this.f10593.setNextFocusDownId(i);
        this.f10585.setNextFocusDownId(i);
    }

    public void setPermissionListener(InterfaceC0716 interfaceC0716) {
        this.f10575 = interfaceC0716;
    }

    public void setSearchAffordanceColors(C3685 c3685) {
        SpeechOrbView speechOrbView = this.f10593;
        if (speechOrbView != null) {
            speechOrbView.setNotListeningOrbColors(c3685);
        }
    }

    public void setSearchAffordanceColorsInListening(C3685 c3685) {
        SpeechOrbView speechOrbView = this.f10593;
        if (speechOrbView != null) {
            speechOrbView.setListeningOrbColors(c3685);
        }
    }

    public void setSearchBarListener(InterfaceC3284 interfaceC3284) {
        this.f10588 = interfaceC3284;
    }

    public void setSearchQuery(String str) {
        m6774();
        this.f10585.setText(str);
        setSearchQueryInternal(str);
    }

    public void setSearchQueryInternal(String str) {
        if (TextUtils.equals(this.f10586, str)) {
            return;
        }
        this.f10586 = str;
        ˑᵽʾʦ r1 = this.f10588;
        if (r1 != null) {
            ᵱᵡᵸˑ r12 = (ᵱᵡᵸˑ) r1.ᵢˇᵭ;
            InterfaceC4302[] interfaceC4302Arr = ᵱᵡᵸˑ.ˁˊᵞ;
            r12.ˋᵪᵟ(str, false);
        }
    }

    @Deprecated
    public void setSpeechRecognitionCallback(InterfaceC4824 interfaceC4824) {
    }

    public void setSpeechRecognizer(SpeechRecognizer speechRecognizer) {
        m6774();
        SpeechRecognizer speechRecognizer2 = this.f10583;
        if (speechRecognizer2 != null) {
            speechRecognizer2.setRecognitionListener(null);
            if (this.f10577) {
                this.f10583.cancel();
                this.f10577 = false;
            }
        }
        this.f10583 = speechRecognizer;
    }

    public void setTitle(String str) throws Resources.NotFoundException {
        this.f10570 = str;
        m6777();
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final void m6773(boolean z) {
        Drawable drawable = this.f10587;
        if (z) {
            drawable.setAlpha(this.f10580);
            boolean zIsFocused = this.f10593.isFocused();
            SearchEditText searchEditText = this.f10585;
            int i = this.f10572;
            if (zIsFocused) {
                searchEditText.setTextColor(i);
                this.f10585.setHintTextColor(i);
            } else {
                searchEditText.setTextColor(this.f10579);
                this.f10585.setHintTextColor(i);
            }
        } else {
            drawable.setAlpha(this.f10594);
            this.f10585.setTextColor(this.f10591);
            this.f10585.setHintTextColor(this.f10590);
        }
        m6777();
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final void m6774() {
        if (this.f10573) {
            this.f10585.setText(this.f10586);
            this.f10585.setHint(this.f10584);
            this.f10573 = false;
            if (this.f10583 == null) {
                return;
            }
            this.f10593.m341();
            if (this.f10577) {
                this.f10583.cancel();
                this.f10577 = false;
            }
            this.f10583.setRecognitionListener(null);
        }
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m6775() {
        this.f10576.hideSoftInputFromWindow(this.f10585.getWindowToken(), 0);
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final void m6776() {
        if (this.f10573) {
            return;
        }
        if (!hasFocus()) {
            requestFocus();
        }
        if (this.f10583 == null) {
            return;
        }
        if (getContext().checkCallingOrSelfPermission("android.permission.RECORD_AUDIO") != 0) {
            ᵺˈᵣ r4 = this.f10575;
            if (r4 != null) {
                ᵹˉ.ᵥʩᵩˑ(r4.ᵢˇᵭ.ᵞː, "android.permission.RECORD_AUDIO");
                return;
            } else {
                ᵹˉᵞ.ᵳٴᵶ("android.permission.RECORD_AUDIO required for search");
                return;
            }
        }
        this.f10573 = true;
        this.f10585.setText("");
        Intent intent = new Intent("android.speech.action.RECOGNIZE_SPEECH");
        intent.putExtra("android.speech.extra.LANGUAGE_MODEL", "free_form");
        intent.putExtra("android.speech.extra.PARTIAL_RESULTS", true);
        this.f10583.setRecognitionListener(new C2926(this));
        this.f10577 = true;
        this.f10583.startListening(intent);
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final void m6777() throws Resources.NotFoundException {
        String string = getResources().getString(R.string.lb_search_bar_hint);
        boolean zIsEmpty = TextUtils.isEmpty(this.f10570);
        SpeechOrbView speechOrbView = this.f10593;
        if (!zIsEmpty) {
            string = speechOrbView.isFocused() ? getResources().getString(R.string._11_res_0x7f13010b, this.f10570) : getResources().getString(R.string._11_res_0x7f13010a, this.f10570);
        } else if (speechOrbView.isFocused()) {
            string = getResources().getString(R.string._11_res_0x7f130109);
        }
        this.f10584 = string;
        SearchEditText searchEditText = this.f10585;
        if (searchEditText != null) {
            searchEditText.setHint(string);
        }
    }
}
