package androidx.appcompat.widget;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.method.KeyListener;
import android.text.method.NumberKeyListener;
import android.util.AttributeSet;
import android.view.ActionMode;
import android.view.DragEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.view.textclassifier.TextClassifier;
import android.widget.EditText;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.UiThread;
import androidx.core.app.e;
import androidx.core.view.f;
import androidx.core.view.h;
import androidx.core.view.m;
import androidx.core.view.n0;
import androidx.core.view.s1;
import androidx.core.view.x0;
import java.util.Objects;
import l.a1;
import l.d0;
import l.e0;
import l.j0;
import l.k0;
import l.l3;
import l.m3;
import l.u0;
import l.y;
import p0.g;
import u0.p;
import u0.q;
import u0.t;

/* JADX INFO: loaded from: classes.dex */
public class AppCompatEditText extends EditText implements x0, n0, t {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final y f660a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final a1 f661b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final u0 f662c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final q f663d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final e0 f664e;

    @Nullable
    private d0 mSuperCaller;

    public AppCompatEditText(@NonNull Context context) {
        this(context, null);
    }

    @NonNull
    @RequiresApi(26)
    @UiThread
    private d0 getSuperCaller() {
        if (this.mSuperCaller == null) {
            this.mSuperCaller = new d0(this);
        }
        return this.mSuperCaller;
    }

    @Override // android.widget.TextView, android.view.View
    public final void drawableStateChanged() {
        super.drawableStateChanged();
        y yVar = this.f660a;
        if (yVar != null) {
            yVar.a();
        }
        a1 a1Var = this.f661b;
        if (a1Var != null) {
            a1Var.b();
        }
    }

    @Override // android.widget.TextView
    @Nullable
    public ActionMode.Callback getCustomSelectionActionModeCallback() {
        return p.unwrapCustomSelectionActionModeCallback(super.getCustomSelectionActionModeCallback());
    }

    @Override // androidx.core.view.x0
    @Nullable
    @RestrictTo({RestrictTo.Scope.f557c})
    public ColorStateList getSupportBackgroundTintList() {
        y yVar = this.f660a;
        if (yVar != null) {
            return yVar.b();
        }
        return null;
    }

    @Override // androidx.core.view.x0
    @Nullable
    @RestrictTo({RestrictTo.Scope.f557c})
    public PorterDuff.Mode getSupportBackgroundTintMode() {
        y yVar = this.f660a;
        if (yVar != null) {
            return yVar.c();
        }
        return null;
    }

    @Override // u0.t
    @Nullable
    @RestrictTo({RestrictTo.Scope.f557c})
    public ColorStateList getSupportCompoundDrawablesTintList() {
        return this.f661b.getCompoundDrawableTintList();
    }

    @Override // u0.t
    @Nullable
    @RestrictTo({RestrictTo.Scope.f557c})
    public PorterDuff.Mode getSupportCompoundDrawablesTintMode() {
        return this.f661b.getCompoundDrawableTintMode();
    }

    @Override // android.widget.TextView
    @NonNull
    @RequiresApi(api = 26)
    public TextClassifier getTextClassifier() {
        u0 u0Var;
        return (Build.VERSION.SDK_INT >= 28 || (u0Var = this.f662c) == null) ? getSuperCaller().getTextClassifier() : u0Var.a();
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x004a A[PHI: r1
      0x004a: PHI (r1v10 java.lang.String[]) = (r1v5 java.lang.String[]), (r1v11 java.lang.String[]) binds: [B:23:0x0061, B:15:0x0048] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:28:0x0068  */
    @Override // android.widget.TextView, android.view.View
    @Nullable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public InputConnection onCreateInputConnection(@NonNull EditorInfo editorInfo) {
        int i10;
        String[] onReceiveContentMimeTypes;
        String[] stringArray;
        InputConnection dVar;
        InputConnection inputConnectionOnCreateInputConnection = super.onCreateInputConnection(editorInfo);
        this.f661b.populateSurroundingTextIfNeeded(this, inputConnectionOnCreateInputConnection, editorInfo);
        kotlinx.coroutines.y.Q(this, editorInfo, inputConnectionOnCreateInputConnection);
        if (inputConnectionOnCreateInputConnection != null && (i10 = Build.VERSION.SDK_INT) <= 30 && (onReceiveContentMimeTypes = s1.getOnReceiveContentMimeTypes(this)) != null) {
            t0.b.setContentMimeTypes(editorInfo, onReceiveContentMimeTypes);
            g.checkNotNull(this);
            e eVar = new e(this, 1);
            p0.c.requireNonNull(inputConnectionOnCreateInputConnection, "inputConnection must be non-null");
            p0.c.requireNonNull(editorInfo, "editorInfo must be non-null");
            p0.c.requireNonNull(eVar, "onCommitContentListener must be non-null");
            if (i10 >= 25) {
                dVar = new t0.c(inputConnectionOnCreateInputConnection, eVar);
            } else {
                String[] strArr = t0.b.f32768a;
                if (i10 >= 25) {
                    stringArray = editorInfo.contentMimeTypes;
                    if (stringArray != null) {
                        strArr = stringArray;
                    }
                    if (strArr.length != 0) {
                        dVar = new t0.d(inputConnectionOnCreateInputConnection, eVar);
                    }
                } else {
                    Bundle bundle = editorInfo.extras;
                    if (bundle != null) {
                        stringArray = bundle.getStringArray("androidx.core.view.inputmethod.EditorInfoCompat.CONTENT_MIME_TYPES");
                        if (stringArray == null) {
                            stringArray = editorInfo.extras.getStringArray("android.support.v13.view.inputmethod.EditorInfoCompat.CONTENT_MIME_TYPES");
                        }
                        if (stringArray != null) {
                        }
                    }
                    if (strArr.length != 0) {
                    }
                }
            }
            inputConnectionOnCreateInputConnection = dVar;
        }
        return this.f664e.onCreateInputConnection(inputConnectionOnCreateInputConnection, editorInfo);
    }

    @Override // android.view.View
    public final void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        int i10 = Build.VERSION.SDK_INT;
        if (i10 < 30 || i10 >= 33) {
            return;
        }
        ((InputMethodManager) getContext().getSystemService("input_method")).isActive(this);
    }

    @Override // android.widget.TextView, android.view.View
    public final boolean onDragEvent(DragEvent dragEvent) {
        if (Build.VERSION.SDK_INT < 31 && dragEvent.getLocalState() == null && s1.getOnReceiveContentMimeTypes(this) != null) {
            Activity activityTryGetActivity = k0.tryGetActivity(this);
            if (activityTryGetActivity == null) {
                Objects.toString(this);
            } else if (dragEvent.getAction() != 1 && dragEvent.getAction() == 3 && j0.a(dragEvent, this, activityTryGetActivity)) {
                return true;
            }
        }
        return super.onDragEvent(dragEvent);
    }

    @Override // androidx.core.view.n0
    @Nullable
    public m onReceiveContent(@NonNull m mVar) {
        return this.f663d.onReceiveContent(this, mVar);
    }

    @Override // android.widget.EditText, android.widget.TextView
    public final boolean onTextContextMenuItem(int i10) {
        if (Build.VERSION.SDK_INT >= 31 || s1.getOnReceiveContentMimeTypes(this) == null || !(i10 == 16908322 || i10 == 16908337)) {
            return super.onTextContextMenuItem(i10);
        }
        ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService("clipboard");
        ClipData primaryClip = clipboardManager == null ? null : clipboardManager.getPrimaryClip();
        if (primaryClip != null && primaryClip.getItemCount() > 0) {
            f fVar = new f(primaryClip, 1);
            int i11 = i10 == 16908322 ? 0 : 1;
            h hVar = fVar.f1735a;
            hVar.a(i11);
            s1.performReceiveContent(this, hVar.build());
        }
        return true;
    }

    @Override // android.view.View
    public void setBackgroundDrawable(@Nullable Drawable drawable) {
        super.setBackgroundDrawable(drawable);
        y yVar = this.f660a;
        if (yVar != null) {
            yVar.d();
        }
    }

    @Override // android.view.View
    public void setBackgroundResource(@DrawableRes int i10) {
        super.setBackgroundResource(i10);
        y yVar = this.f660a;
        if (yVar != null) {
            yVar.e(i10);
        }
    }

    @Override // android.widget.TextView
    public void setCompoundDrawables(@Nullable Drawable drawable, @Nullable Drawable drawable2, @Nullable Drawable drawable3, @Nullable Drawable drawable4) {
        super.setCompoundDrawables(drawable, drawable2, drawable3, drawable4);
        a1 a1Var = this.f661b;
        if (a1Var != null) {
            a1Var.b();
        }
    }

    @Override // android.widget.TextView
    public void setCompoundDrawablesRelative(@Nullable Drawable drawable, @Nullable Drawable drawable2, @Nullable Drawable drawable3, @Nullable Drawable drawable4) {
        super.setCompoundDrawablesRelative(drawable, drawable2, drawable3, drawable4);
        a1 a1Var = this.f661b;
        if (a1Var != null) {
            a1Var.b();
        }
    }

    @Override // android.widget.TextView
    public void setCustomSelectionActionModeCallback(@Nullable ActionMode.Callback callback) {
        super.setCustomSelectionActionModeCallback(p.wrapCustomSelectionActionModeCallback(this, callback));
    }

    public void setEmojiCompatEnabled(boolean z10) {
        this.f664e.a(z10);
    }

    @Override // android.widget.TextView
    public void setKeyListener(@Nullable KeyListener keyListener) {
        super.setKeyListener(this.f664e.getKeyListener(keyListener));
    }

    @Override // androidx.core.view.x0
    @RestrictTo({RestrictTo.Scope.f557c})
    public void setSupportBackgroundTintList(@Nullable ColorStateList colorStateList) {
        y yVar = this.f660a;
        if (yVar != null) {
            yVar.g(colorStateList);
        }
    }

    @Override // androidx.core.view.x0
    @RestrictTo({RestrictTo.Scope.f557c})
    public void setSupportBackgroundTintMode(@Nullable PorterDuff.Mode mode) {
        y yVar = this.f660a;
        if (yVar != null) {
            yVar.h(mode);
        }
    }

    @Override // u0.t
    @RestrictTo({RestrictTo.Scope.f557c})
    public void setSupportCompoundDrawablesTintList(@Nullable ColorStateList colorStateList) {
        a1 a1Var = this.f661b;
        a1Var.setCompoundDrawableTintList(colorStateList);
        a1Var.b();
    }

    @Override // u0.t
    @RestrictTo({RestrictTo.Scope.f557c})
    public void setSupportCompoundDrawablesTintMode(@Nullable PorterDuff.Mode mode) {
        a1 a1Var = this.f661b;
        a1Var.setCompoundDrawableTintMode(mode);
        a1Var.b();
    }

    @Override // android.widget.TextView
    public void setTextAppearance(Context context, int i10) {
        super.setTextAppearance(context, i10);
        a1 a1Var = this.f661b;
        if (a1Var != null) {
            a1Var.d(context, i10);
        }
    }

    @Override // android.widget.TextView
    @RequiresApi(api = 26)
    public void setTextClassifier(@Nullable TextClassifier textClassifier) {
        u0 u0Var;
        if (Build.VERSION.SDK_INT >= 28 || (u0Var = this.f662c) == null) {
            super.setTextClassifier(textClassifier);
        } else {
            u0Var.setTextClassifier(textClassifier);
        }
    }

    public AppCompatEditText(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, d.a.editTextStyle);
    }

    @Override // android.widget.EditText, android.widget.TextView
    @Nullable
    public Editable getText() {
        return Build.VERSION.SDK_INT >= 28 ? super.getText() : super.getEditableText();
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public AppCompatEditText(@NonNull Context context, @Nullable AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        m3.a(context);
        l3.a(getContext(), this);
        y yVar = new y(this);
        this.f660a = yVar;
        yVar.loadFromAttributes(attributeSet, i10);
        a1 a1Var = new a1(this);
        this.f661b = a1Var;
        a1Var.loadFromAttributes(attributeSet, i10);
        a1Var.b();
        this.f662c = new u0(this);
        this.f663d = new q();
        e0 e0Var = new e0(this);
        this.f664e = e0Var;
        e0Var.loadFromAttributes(attributeSet, i10);
        KeyListener keyListener = getKeyListener();
        if (!(keyListener instanceof NumberKeyListener)) {
            boolean zIsFocusable = super.isFocusable();
            boolean zIsClickable = super.isClickable();
            boolean zIsLongClickable = super.isLongClickable();
            int inputType = super.getInputType();
            KeyListener keyListener2 = e0Var.getKeyListener(keyListener);
            if (keyListener2 == keyListener) {
                return;
            }
            super.setKeyListener(keyListener2);
            super.setRawInputType(inputType);
            super.setFocusable(zIsFocusable);
            super.setClickable(zIsClickable);
            super.setLongClickable(zIsLongClickable);
        }
    }
}
