package xyz.stream.view.input;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.media3.exoplayer.rtsp.SessionDescription;
import androidx.recyclerview.widget.q1;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import ve.i;
import xyz.stream.view.GridSpacingItemDecoration;
import xyz.stream.view.R;
import xyz.stream.view.UiUtils;
import xyz.stream.view.ViewRuntime;
import xyz.stream.view.databinding.LibInputViewBinding;
import xyz.stream.view.input.InputAdapter;
import xyz.stream.view.tvrecyclerview.V7GridLayoutManager;

/* JADX INFO: loaded from: classes3.dex */
public class InputView extends FrameLayout {

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public static final /* synthetic */ int f36507b0 = 0;
    public int Q;
    public int R;
    public int S;
    public int T;
    public int U;
    public int V;
    public CharSequence W;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public InputAdapter f36508a;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public CharSequence f36509a0;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public OnInputListener f36510b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public List f36511c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public LibInputViewBinding f36512d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f36513e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f36514f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int f36515g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f36516h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public int f36517i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public int f36518j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public int f36519k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public int f36520l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public int f36521m;

    public InputView(Context context) {
        super(context);
        this.Q = 0;
        this.R = -1;
        this.S = -1;
        this.T = -1;
        this.U = -3355444;
        this.V = Color.parseColor("#666666");
        a(null);
    }

    private List<String> getEnglishCharacters() {
        return Arrays.asList("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", SessionDescription.SUPPORTED_SDP_VERSION, "1", "2", "3", "4", "5", "6", "7", "8", "9");
    }

    public final void a(AttributeSet attributeSet) {
        ColorStateList colorStateList;
        final int i10 = 0;
        if (attributeSet != null) {
            TypedArray typedArrayObtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, R.styleable.InputView);
            try {
                this.f36513e = typedArrayObtainStyledAttributes.getResourceId(R.styleable.InputView_iv_previewIcon, 0);
                this.f36514f = typedArrayObtainStyledAttributes.getResourceId(R.styleable.InputView_iv_searchButtonIcon, 0);
                this.f36515g = typedArrayObtainStyledAttributes.getResourceId(R.styleable.InputView_iv_spaceButtonIcon, 0);
                this.f36516h = typedArrayObtainStyledAttributes.getResourceId(R.styleable.InputView_iv_deleteButtonIcon, 0);
                this.f36517i = typedArrayObtainStyledAttributes.getResourceId(R.styleable.InputView_iv_systemInputIcon, 0);
                this.f36518j = typedArrayObtainStyledAttributes.getResourceId(R.styleable.InputView_iv_actionButtonBackground, 0);
                this.f36519k = typedArrayObtainStyledAttributes.getResourceId(R.styleable.InputView_iv_keyButtonBackground, 0);
                this.f36520l = typedArrayObtainStyledAttributes.getResourceId(R.styleable.InputView_iv_itemTextColor, 0);
                this.f36521m = typedArrayObtainStyledAttributes.getResourceId(R.styleable.InputView_iv_systemInputTextColor, 0);
                this.Q = typedArrayObtainStyledAttributes.getColor(R.styleable.InputView_iv_previewIconTint, this.Q);
                this.R = typedArrayObtainStyledAttributes.getColor(R.styleable.InputView_iv_iconDefaultTint, this.R);
                this.S = typedArrayObtainStyledAttributes.getColor(R.styleable.InputView_iv_iconFocusedTint, this.S);
                this.T = typedArrayObtainStyledAttributes.getColor(R.styleable.InputView_iv_previewTextColor, this.T);
                this.U = typedArrayObtainStyledAttributes.getColor(R.styleable.InputView_iv_previewHintTextColor, this.U);
                this.V = typedArrayObtainStyledAttributes.getColor(R.styleable.InputView_iv_dividerColor, this.V);
                this.W = typedArrayObtainStyledAttributes.getText(R.styleable.InputView_iv_searchHint);
                this.f36509a0 = typedArrayObtainStyledAttributes.getText(R.styleable.InputView_iv_systemInputText);
                typedArrayObtainStyledAttributes.recycle();
            } catch (Throwable th) {
                if (typedArrayObtainStyledAttributes != null) {
                    try {
                        typedArrayObtainStyledAttributes.recycle();
                    } catch (Throwable th2) {
                        th.addSuppressed(th2);
                    }
                }
                throw th;
            }
        }
        LibInputViewBinding libInputViewBindingInflate = LibInputViewBinding.inflate(LayoutInflater.from(getContext()), this, false);
        this.f36512d = libInputViewBindingInflate;
        addView(libInputViewBindingInflate.getRoot());
        d(this.f36512d.iconPreview, this.f36513e, this.Q);
        d(this.f36512d.btnSearch, this.f36514f, this.R);
        d(this.f36512d.btnSpace, this.f36515g, this.R);
        d(this.f36512d.btnDelete, this.f36516h, this.R);
        d(this.f36512d.iconSystemInput, this.f36517i, this.R);
        int i11 = this.f36518j;
        if (i11 != 0) {
            this.f36512d.layoutDelete.setBackgroundResource(i11);
            this.f36512d.layoutSpace.setBackgroundResource(this.f36518j);
            this.f36512d.layoutSearch.setBackgroundResource(this.f36518j);
            this.f36512d.btInputSystem.setBackgroundResource(this.f36518j);
        }
        this.f36512d.divider.setBackgroundColor(this.V);
        this.f36512d.inputPreview.setTextColor(this.T);
        this.f36512d.inputPreview.setHintTextColor(this.U);
        CharSequence charSequence = this.W;
        if (charSequence != null) {
            this.f36512d.inputPreview.setHint(charSequence);
        }
        CharSequence charSequence2 = this.f36509a0;
        if (charSequence2 != null) {
            this.f36512d.tvSystemInput.setText(charSequence2);
        }
        if (this.f36521m != 0 && (colorStateList = g0.d.getColorStateList(getContext(), this.f36521m)) != null) {
            this.f36512d.tvSystemInput.setTextColor(colorStateList);
        }
        this.f36512d.inputGrid.setAnimation(null);
        this.f36511c = getEnglishCharacters();
        V7GridLayoutManager v7GridLayoutManager = new V7GridLayoutManager(getContext(), 6);
        this.f36512d.inputGrid.addItemDecoration(new GridSpacingItemDecoration(6, UiUtils.dp2px(30.0f), false));
        this.f36512d.inputGrid.setLayoutManager(v7GridLayoutManager);
        InputAdapter inputAdapter = new InputAdapter(getContext());
        this.f36508a = inputAdapter;
        inputAdapter.setKeyBackgroundResId(this.f36519k);
        this.f36508a.setItemTextColorResId(this.f36520l);
        this.f36512d.inputGrid.setAdapter(this.f36508a);
        final int i12 = 1;
        this.f36512d.inputGrid.setSelectedItemAtCentered(true);
        if (ViewRuntime.isTablet()) {
            UiUtils.setUnFocusable(this.f36512d.layoutSpace);
            UiUtils.setUnFocusable(this.f36512d.layoutDelete);
            UiUtils.setUnFocusable(this.f36512d.btInputSystem);
            UiUtils.setUnFocusable(this.f36512d.layoutSearch);
        }
        this.f36508a.f36504c = new InputAdapter.OnItemListener() { // from class: xyz.stream.view.input.InputView.1
            @Override // xyz.stream.view.input.InputAdapter.OnItemListener
            public void onItemClick(View view, int i13) {
                if (i13 != -1) {
                    InputView inputView = InputView.this;
                    inputView.f36512d.inputPreview.append(inputView.f36508a.getItem(i13));
                }
            }

            @Override // xyz.stream.view.input.InputAdapter.OnItemListener
            public boolean onItemKey(View view, int i13, KeyEvent keyEvent, int i14) {
                OnInputListener onInputListener;
                OnInputListener onInputListener2;
                InputView inputView = InputView.this;
                if (i13 == 19 && keyEvent.getAction() == 0 && i14 < 6 && !inputView.f36512d.inputPreview.isFocusable()) {
                    return true;
                }
                int i15 = InputView.f36507b0;
                if (inputView.b(i13) && keyEvent.getAction() == 0 && i14 % 6 == 0 && (onInputListener2 = inputView.f36510b) != null) {
                    q1 layoutManager = inputView.f36512d.inputGrid.getLayoutManager();
                    Objects.requireNonNull(layoutManager);
                    onInputListener2.onKeyLeft(layoutManager.findViewByPosition(i14));
                    return true;
                }
                if (inputView.c(i13) && keyEvent.getAction() == 0 && i14 % 6 == 5 && (onInputListener = inputView.f36510b) != null) {
                    return onInputListener.onKeyRight(view);
                }
                return false;
            }
        };
        this.f36512d.layoutSearch.setOnClickListener(new View.OnClickListener(this) { // from class: xyz.stream.view.input.a

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36525b;

            {
                this.f36525b = this;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i13 = i10;
                InputView inputView = this.f36525b;
                switch (i13) {
                    case 0:
                        if (inputView.f36510b != null) {
                            String string = inputView.f36512d.inputPreview.getText().toString();
                            if (!string.isEmpty()) {
                                inputView.f36510b.onDone(string);
                            }
                        }
                        break;
                    case 1:
                        inputView.f36512d.inputPreview.append(" ");
                        break;
                    case 2:
                        String string2 = inputView.f36512d.inputPreview.getText().toString();
                        if (!string2.isEmpty()) {
                            inputView.f36512d.inputPreview.setText(string2.substring(0, string2.length() - 1));
                        }
                        break;
                    case 3:
                        inputView.f36512d.inputPreview.setFocusable(true);
                        inputView.f36512d.inputPreview.setFocusableInTouchMode(true);
                        inputView.f36512d.inputPreview.requestFocus();
                        break;
                    default:
                        inputView.f36512d.inputPreview.post(new d(inputView, 1));
                        break;
                }
            }
        });
        this.f36512d.layoutSpace.setOnClickListener(new View.OnClickListener(this) { // from class: xyz.stream.view.input.a

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36525b;

            {
                this.f36525b = this;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i13 = i12;
                InputView inputView = this.f36525b;
                switch (i13) {
                    case 0:
                        if (inputView.f36510b != null) {
                            String string = inputView.f36512d.inputPreview.getText().toString();
                            if (!string.isEmpty()) {
                                inputView.f36510b.onDone(string);
                            }
                        }
                        break;
                    case 1:
                        inputView.f36512d.inputPreview.append(" ");
                        break;
                    case 2:
                        String string2 = inputView.f36512d.inputPreview.getText().toString();
                        if (!string2.isEmpty()) {
                            inputView.f36512d.inputPreview.setText(string2.substring(0, string2.length() - 1));
                        }
                        break;
                    case 3:
                        inputView.f36512d.inputPreview.setFocusable(true);
                        inputView.f36512d.inputPreview.setFocusableInTouchMode(true);
                        inputView.f36512d.inputPreview.requestFocus();
                        break;
                    default:
                        inputView.f36512d.inputPreview.post(new d(inputView, 1));
                        break;
                }
            }
        });
        final int i13 = 2;
        this.f36512d.layoutDelete.setOnClickListener(new View.OnClickListener(this) { // from class: xyz.stream.view.input.a

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36525b;

            {
                this.f36525b = this;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i132 = i13;
                InputView inputView = this.f36525b;
                switch (i132) {
                    case 0:
                        if (inputView.f36510b != null) {
                            String string = inputView.f36512d.inputPreview.getText().toString();
                            if (!string.isEmpty()) {
                                inputView.f36510b.onDone(string);
                            }
                        }
                        break;
                    case 1:
                        inputView.f36512d.inputPreview.append(" ");
                        break;
                    case 2:
                        String string2 = inputView.f36512d.inputPreview.getText().toString();
                        if (!string2.isEmpty()) {
                            inputView.f36512d.inputPreview.setText(string2.substring(0, string2.length() - 1));
                        }
                        break;
                    case 3:
                        inputView.f36512d.inputPreview.setFocusable(true);
                        inputView.f36512d.inputPreview.setFocusableInTouchMode(true);
                        inputView.f36512d.inputPreview.requestFocus();
                        break;
                    default:
                        inputView.f36512d.inputPreview.post(new d(inputView, 1));
                        break;
                }
            }
        });
        this.f36512d.layoutDelete.setOnKeyListener(new View.OnKeyListener(this) { // from class: xyz.stream.view.input.b

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36527b;

            {
                this.f36527b = this;
            }

            @Override // android.view.View.OnKeyListener
            public final boolean onKey(View view, int i14, KeyEvent keyEvent) {
                OnInputListener onInputListener;
                OnInputListener onInputListener2;
                OnInputListener onInputListener3;
                OnInputListener onInputListener4;
                int i15 = i12;
                InputView inputView = this.f36527b;
                switch (i15) {
                    case 0:
                        int i16 = InputView.f36507b0;
                        if (i14 == 20) {
                            inputView.getClass();
                            if (keyEvent.getAction() == 0) {
                                return true;
                            }
                        }
                        if (inputView.b(i14) && keyEvent.getAction() == 0 && (onInputListener2 = inputView.f36510b) != null) {
                            onInputListener2.onKeyLeft(view);
                            return true;
                        }
                        if (inputView.c(i14) && keyEvent.getAction() == 0 && (onInputListener = inputView.f36510b) != null) {
                            return onInputListener.onKeyRight(view);
                        }
                        return false;
                    case 1:
                        int i17 = InputView.f36507b0;
                        if (!inputView.b(i14) || keyEvent.getAction() != 0 || (onInputListener3 = inputView.f36510b) == null) {
                            return false;
                        }
                        onInputListener3.onKeyLeft(view);
                        return true;
                    default:
                        int i18 = InputView.f36507b0;
                        if (inputView.c(i14) && keyEvent.getAction() == 0 && (onInputListener4 = inputView.f36510b) != null) {
                            return onInputListener4.onKeyRight(view);
                        }
                        return false;
                }
            }
        });
        this.f36512d.layoutDelete.setOnFocusChangeListener(new View.OnFocusChangeListener(this) { // from class: xyz.stream.view.input.c

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36529b;

            {
                this.f36529b = this;
            }

            @Override // android.view.View.OnFocusChangeListener
            public final void onFocusChange(View view, boolean z10) {
                int i14 = i12;
                InputView inputView = this.f36529b;
                switch (i14) {
                    case 0:
                        int i15 = InputView.f36507b0;
                        InputMethodManager inputMethodManager = (InputMethodManager) inputView.getContext().getSystemService("input_method");
                        if (!z10) {
                            inputView.f36512d.inputPreview.setFocusable(false);
                            inputView.f36512d.inputPreview.setFocusableInTouchMode(false);
                            if (inputMethodManager != null) {
                                inputMethodManager.hideSoftInputFromWindow(inputView.f36512d.inputPreview.getWindowToken(), 0);
                            }
                        } else if (inputMethodManager != null) {
                            inputMethodManager.showSoftInput(inputView.f36512d.inputPreview, 1);
                        }
                        break;
                    case 1:
                        inputView.d(inputView.f36512d.btnDelete, inputView.f36516h, z10 ? inputView.S : inputView.R);
                        break;
                    case 2:
                        inputView.d(inputView.f36512d.btnSearch, inputView.f36514f, z10 ? inputView.S : inputView.R);
                        break;
                    default:
                        inputView.d(inputView.f36512d.btnSpace, inputView.f36515g, z10 ? inputView.S : inputView.R);
                        break;
                }
            }
        });
        this.f36512d.layoutSearch.setOnFocusChangeListener(new View.OnFocusChangeListener(this) { // from class: xyz.stream.view.input.c

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36529b;

            {
                this.f36529b = this;
            }

            @Override // android.view.View.OnFocusChangeListener
            public final void onFocusChange(View view, boolean z10) {
                int i14 = i13;
                InputView inputView = this.f36529b;
                switch (i14) {
                    case 0:
                        int i15 = InputView.f36507b0;
                        InputMethodManager inputMethodManager = (InputMethodManager) inputView.getContext().getSystemService("input_method");
                        if (!z10) {
                            inputView.f36512d.inputPreview.setFocusable(false);
                            inputView.f36512d.inputPreview.setFocusableInTouchMode(false);
                            if (inputMethodManager != null) {
                                inputMethodManager.hideSoftInputFromWindow(inputView.f36512d.inputPreview.getWindowToken(), 0);
                            }
                        } else if (inputMethodManager != null) {
                            inputMethodManager.showSoftInput(inputView.f36512d.inputPreview, 1);
                        }
                        break;
                    case 1:
                        inputView.d(inputView.f36512d.btnDelete, inputView.f36516h, z10 ? inputView.S : inputView.R);
                        break;
                    case 2:
                        inputView.d(inputView.f36512d.btnSearch, inputView.f36514f, z10 ? inputView.S : inputView.R);
                        break;
                    default:
                        inputView.d(inputView.f36512d.btnSpace, inputView.f36515g, z10 ? inputView.S : inputView.R);
                        break;
                }
            }
        });
        final int i14 = 3;
        this.f36512d.layoutSpace.setOnFocusChangeListener(new View.OnFocusChangeListener(this) { // from class: xyz.stream.view.input.c

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36529b;

            {
                this.f36529b = this;
            }

            @Override // android.view.View.OnFocusChangeListener
            public final void onFocusChange(View view, boolean z10) {
                int i142 = i14;
                InputView inputView = this.f36529b;
                switch (i142) {
                    case 0:
                        int i15 = InputView.f36507b0;
                        InputMethodManager inputMethodManager = (InputMethodManager) inputView.getContext().getSystemService("input_method");
                        if (!z10) {
                            inputView.f36512d.inputPreview.setFocusable(false);
                            inputView.f36512d.inputPreview.setFocusableInTouchMode(false);
                            if (inputMethodManager != null) {
                                inputMethodManager.hideSoftInputFromWindow(inputView.f36512d.inputPreview.getWindowToken(), 0);
                            }
                        } else if (inputMethodManager != null) {
                            inputMethodManager.showSoftInput(inputView.f36512d.inputPreview, 1);
                        }
                        break;
                    case 1:
                        inputView.d(inputView.f36512d.btnDelete, inputView.f36516h, z10 ? inputView.S : inputView.R);
                        break;
                    case 2:
                        inputView.d(inputView.f36512d.btnSearch, inputView.f36514f, z10 ? inputView.S : inputView.R);
                        break;
                    default:
                        inputView.d(inputView.f36512d.btnSpace, inputView.f36515g, z10 ? inputView.S : inputView.R);
                        break;
                }
            }
        });
        this.f36512d.layoutSearch.setOnKeyListener(new View.OnKeyListener(this) { // from class: xyz.stream.view.input.b

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36527b;

            {
                this.f36527b = this;
            }

            @Override // android.view.View.OnKeyListener
            public final boolean onKey(View view, int i142, KeyEvent keyEvent) {
                OnInputListener onInputListener;
                OnInputListener onInputListener2;
                OnInputListener onInputListener3;
                OnInputListener onInputListener4;
                int i15 = i13;
                InputView inputView = this.f36527b;
                switch (i15) {
                    case 0:
                        int i16 = InputView.f36507b0;
                        if (i142 == 20) {
                            inputView.getClass();
                            if (keyEvent.getAction() == 0) {
                                return true;
                            }
                        }
                        if (inputView.b(i142) && keyEvent.getAction() == 0 && (onInputListener2 = inputView.f36510b) != null) {
                            onInputListener2.onKeyLeft(view);
                            return true;
                        }
                        if (inputView.c(i142) && keyEvent.getAction() == 0 && (onInputListener = inputView.f36510b) != null) {
                            return onInputListener.onKeyRight(view);
                        }
                        return false;
                    case 1:
                        int i17 = InputView.f36507b0;
                        if (!inputView.b(i142) || keyEvent.getAction() != 0 || (onInputListener3 = inputView.f36510b) == null) {
                            return false;
                        }
                        onInputListener3.onKeyLeft(view);
                        return true;
                    default:
                        int i18 = InputView.f36507b0;
                        if (inputView.c(i142) && keyEvent.getAction() == 0 && (onInputListener4 = inputView.f36510b) != null) {
                            return onInputListener4.onKeyRight(view);
                        }
                        return false;
                }
            }
        });
        this.f36512d.inputPreview.setOnClickListener(new View.OnClickListener(this) { // from class: xyz.stream.view.input.a

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36525b;

            {
                this.f36525b = this;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i132 = i14;
                InputView inputView = this.f36525b;
                switch (i132) {
                    case 0:
                        if (inputView.f36510b != null) {
                            String string = inputView.f36512d.inputPreview.getText().toString();
                            if (!string.isEmpty()) {
                                inputView.f36510b.onDone(string);
                            }
                        }
                        break;
                    case 1:
                        inputView.f36512d.inputPreview.append(" ");
                        break;
                    case 2:
                        String string2 = inputView.f36512d.inputPreview.getText().toString();
                        if (!string2.isEmpty()) {
                            inputView.f36512d.inputPreview.setText(string2.substring(0, string2.length() - 1));
                        }
                        break;
                    case 3:
                        inputView.f36512d.inputPreview.setFocusable(true);
                        inputView.f36512d.inputPreview.setFocusableInTouchMode(true);
                        inputView.f36512d.inputPreview.requestFocus();
                        break;
                    default:
                        inputView.f36512d.inputPreview.post(new d(inputView, 1));
                        break;
                }
            }
        });
        final int i15 = 4;
        this.f36512d.btInputSystem.setOnClickListener(new View.OnClickListener(this) { // from class: xyz.stream.view.input.a

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36525b;

            {
                this.f36525b = this;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i132 = i15;
                InputView inputView = this.f36525b;
                switch (i132) {
                    case 0:
                        if (inputView.f36510b != null) {
                            String string = inputView.f36512d.inputPreview.getText().toString();
                            if (!string.isEmpty()) {
                                inputView.f36510b.onDone(string);
                            }
                        }
                        break;
                    case 1:
                        inputView.f36512d.inputPreview.append(" ");
                        break;
                    case 2:
                        String string2 = inputView.f36512d.inputPreview.getText().toString();
                        if (!string2.isEmpty()) {
                            inputView.f36512d.inputPreview.setText(string2.substring(0, string2.length() - 1));
                        }
                        break;
                    case 3:
                        inputView.f36512d.inputPreview.setFocusable(true);
                        inputView.f36512d.inputPreview.setFocusableInTouchMode(true);
                        inputView.f36512d.inputPreview.requestFocus();
                        break;
                    default:
                        inputView.f36512d.inputPreview.post(new d(inputView, 1));
                        break;
                }
            }
        });
        this.f36512d.btInputSystem.setOnKeyListener(new View.OnKeyListener(this) { // from class: xyz.stream.view.input.b

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36527b;

            {
                this.f36527b = this;
            }

            @Override // android.view.View.OnKeyListener
            public final boolean onKey(View view, int i142, KeyEvent keyEvent) {
                OnInputListener onInputListener;
                OnInputListener onInputListener2;
                OnInputListener onInputListener3;
                OnInputListener onInputListener4;
                int i152 = i10;
                InputView inputView = this.f36527b;
                switch (i152) {
                    case 0:
                        int i16 = InputView.f36507b0;
                        if (i142 == 20) {
                            inputView.getClass();
                            if (keyEvent.getAction() == 0) {
                                return true;
                            }
                        }
                        if (inputView.b(i142) && keyEvent.getAction() == 0 && (onInputListener2 = inputView.f36510b) != null) {
                            onInputListener2.onKeyLeft(view);
                            return true;
                        }
                        if (inputView.c(i142) && keyEvent.getAction() == 0 && (onInputListener = inputView.f36510b) != null) {
                            return onInputListener.onKeyRight(view);
                        }
                        return false;
                    case 1:
                        int i17 = InputView.f36507b0;
                        if (!inputView.b(i142) || keyEvent.getAction() != 0 || (onInputListener3 = inputView.f36510b) == null) {
                            return false;
                        }
                        onInputListener3.onKeyLeft(view);
                        return true;
                    default:
                        int i18 = InputView.f36507b0;
                        if (inputView.c(i142) && keyEvent.getAction() == 0 && (onInputListener4 = inputView.f36510b) != null) {
                            return onInputListener4.onKeyRight(view);
                        }
                        return false;
                }
            }
        });
        this.f36512d.inputPreview.addTextChangedListener(new TextWatcher() { // from class: xyz.stream.view.input.InputView.2
            @Override // android.text.TextWatcher
            public void afterTextChanged(Editable editable) {
                OnInputListener onInputListener = InputView.this.f36510b;
                if (onInputListener != null) {
                    onInputListener.onInput(editable.toString());
                }
            }

            @Override // android.text.TextWatcher
            public void beforeTextChanged(CharSequence charSequence3, int i16, int i17, int i18) {
            }

            @Override // android.text.TextWatcher
            public void onTextChanged(CharSequence charSequence3, int i16, int i17, int i18) {
            }
        });
        this.f36512d.inputPreview.setOnFocusChangeListener(new View.OnFocusChangeListener(this) { // from class: xyz.stream.view.input.c

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ InputView f36529b;

            {
                this.f36529b = this;
            }

            @Override // android.view.View.OnFocusChangeListener
            public final void onFocusChange(View view, boolean z10) {
                int i142 = i10;
                InputView inputView = this.f36529b;
                switch (i142) {
                    case 0:
                        int i152 = InputView.f36507b0;
                        InputMethodManager inputMethodManager = (InputMethodManager) inputView.getContext().getSystemService("input_method");
                        if (!z10) {
                            inputView.f36512d.inputPreview.setFocusable(false);
                            inputView.f36512d.inputPreview.setFocusableInTouchMode(false);
                            if (inputMethodManager != null) {
                                inputMethodManager.hideSoftInputFromWindow(inputView.f36512d.inputPreview.getWindowToken(), 0);
                            }
                        } else if (inputMethodManager != null) {
                            inputMethodManager.showSoftInput(inputView.f36512d.inputPreview, 1);
                        }
                        break;
                    case 1:
                        inputView.d(inputView.f36512d.btnDelete, inputView.f36516h, z10 ? inputView.S : inputView.R);
                        break;
                    case 2:
                        inputView.d(inputView.f36512d.btnSearch, inputView.f36514f, z10 ? inputView.S : inputView.R);
                        break;
                    default:
                        inputView.d(inputView.f36512d.btnSpace, inputView.f36515g, z10 ? inputView.S : inputView.R);
                        break;
                }
            }
        });
        this.f36512d.inputPreview.setOnEditorActionListener(new i(this, 2));
        this.f36508a.setCharacters(this.f36511c);
        this.f36508a.notifyDataSetChanged();
    }

    public final boolean b(int i10) {
        if (getLayoutDirection() == 1) {
            if (i10 != 22) {
                return false;
            }
        } else if (i10 != 21) {
            return false;
        }
        return true;
    }

    public final boolean c(int i10) {
        if (getLayoutDirection() == 1) {
            if (i10 != 21) {
                return false;
            }
        } else if (i10 != 22) {
            return false;
        }
        return true;
    }

    public final void d(ImageView imageView, int i10, int i11) {
        Drawable drawable;
        if (i10 == 0 || (drawable = f.a.getDrawable(getContext(), i10)) == null) {
            return;
        }
        Drawable drawableMutate = drawable.mutate();
        if (i11 != 0) {
            drawableMutate.setTint(i11);
        }
        imageView.setImageDrawable(drawableMutate);
    }

    public void focus() {
        this.f36512d.inputGrid.post(new d(this, 0));
    }

    public String getInputText() {
        return this.f36512d.inputPreview.getText().toString();
    }

    public void setInputHint(String str) {
        this.f36512d.inputPreview.setHint(str);
    }

    public void setInputText(String str) {
        this.f36512d.inputPreview.setText(str);
    }

    public void setOnInputListener(OnInputListener onInputListener) {
        this.f36510b = onInputListener;
    }

    public InputView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.Q = 0;
        this.R = -1;
        this.S = -1;
        this.T = -1;
        this.U = -3355444;
        this.V = Color.parseColor("#666666");
        a(attributeSet);
    }
}
