package com.google.android.material.textfield;

import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import com.google.android.material.internal.CheckableImageButton;
import com.google.android.material.internal.w0;
import l.p3;

/* JADX INFO: loaded from: classes2.dex */
public final class v extends LinearLayout {

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

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

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public PorterDuff.Mode f23476e;

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public ImageView.ScaleType f23478g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public View.OnLongClickListener f23479h;

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

    @Nullable
    private CharSequence prefixText;

    public v(TextInputLayout textInputLayout, p3 p3Var) {
        super(textInputLayout.getContext());
        this.f23472a = textInputLayout;
        setVisibility(8);
        setOrientation(0);
        setLayoutParams(new FrameLayout.LayoutParams(-2, -1, 8388611));
        CheckableImageButton checkableImageButton = (CheckableImageButton) LayoutInflater.from(getContext()).inflate(x8.i.design_text_input_start_icon, (ViewGroup) this, false);
        this.f23474c = checkableImageButton;
        AppCompatTextView appCompatTextView = new AppCompatTextView(getContext());
        this.f23473b = appCompatTextView;
        if (q9.d.c(getContext())) {
            ((ViewGroup.MarginLayoutParams) checkableImageButton.getLayoutParams()).setMarginEnd(0);
        }
        setStartIconOnClickListener(null);
        setStartIconOnLongClickListener(null);
        int i10 = x8.m.TextInputLayout_startIconTint;
        TypedArray typedArray = p3Var.f29809b;
        if (typedArray.hasValue(i10)) {
            this.f23475d = q9.d.getColorStateList(getContext(), p3Var, i10);
        }
        int i11 = x8.m.TextInputLayout_startIconTintMode;
        if (typedArray.hasValue(i11)) {
            this.f23476e = w0.f(typedArray.getInt(i11, -1), null);
        }
        int i12 = x8.m.TextInputLayout_startIconDrawable;
        if (typedArray.hasValue(i12)) {
            setStartIconDrawable(p3Var.b(i12));
            int i13 = x8.m.TextInputLayout_startIconContentDescription;
            if (typedArray.hasValue(i13)) {
                setStartIconContentDescription(typedArray.getText(i13));
            }
            checkableImageButton.setCheckable(typedArray.getBoolean(x8.m.TextInputLayout_startIconCheckable, true));
        }
        int dimensionPixelSize = typedArray.getDimensionPixelSize(x8.m.TextInputLayout_startIconMinSize, getResources().getDimensionPixelSize(x8.e.mtrl_min_touch_target_size));
        if (dimensionPixelSize < 0) {
            throw new IllegalArgumentException("startIconSize cannot be less than 0");
        }
        if (dimensionPixelSize != this.f23477f) {
            this.f23477f = dimensionPixelSize;
            checkableImageButton.setMinimumWidth(dimensionPixelSize);
            checkableImageButton.setMinimumHeight(dimensionPixelSize);
        }
        int i14 = x8.m.TextInputLayout_startIconScaleType;
        if (typedArray.hasValue(i14)) {
            ImageView.ScaleType scaleTypeB = q.b(typedArray.getInt(i14, -1));
            this.f23478g = scaleTypeB;
            checkableImageButton.setScaleType(scaleTypeB);
        }
        appCompatTextView.setVisibility(8);
        appCompatTextView.setId(x8.g.textinput_prefix_text);
        appCompatTextView.setLayoutParams(new LinearLayout.LayoutParams(-2, -2));
        appCompatTextView.setAccessibilityLiveRegion(1);
        appCompatTextView.setTextAppearance(typedArray.getResourceId(x8.m.TextInputLayout_prefixTextAppearance, 0));
        int i15 = x8.m.TextInputLayout_prefixTextColor;
        if (typedArray.hasValue(i15)) {
            appCompatTextView.setTextColor(p3Var.a(i15));
        }
        setPrefixText(typedArray.getText(x8.m.TextInputLayout_prefixText));
        addView(checkableImageButton);
        addView(appCompatTextView);
    }

    public final int a() {
        int marginEnd;
        CheckableImageButton checkableImageButton = this.f23474c;
        if (checkableImageButton.getVisibility() == 0) {
            marginEnd = ((ViewGroup.MarginLayoutParams) checkableImageButton.getLayoutParams()).getMarginEnd() + checkableImageButton.getMeasuredWidth();
        } else {
            marginEnd = 0;
        }
        return this.f23473b.getPaddingStart() + getPaddingStart() + marginEnd;
    }

    public final void b(boolean z10) {
        CheckableImageButton checkableImageButton = this.f23474c;
        if ((checkableImageButton.getVisibility() == 0) != z10) {
            checkableImageButton.setVisibility(z10 ? 0 : 8);
            c();
            d();
        }
    }

    public final void c() {
        EditText editText = this.f23472a.f23360e;
        if (editText == null) {
            return;
        }
        this.f23473b.setPaddingRelative(this.f23474c.getVisibility() == 0 ? 0 : editText.getPaddingStart(), editText.getCompoundPaddingTop(), getContext().getResources().getDimensionPixelSize(x8.e.material_input_text_to_prefix_suffix_padding), editText.getCompoundPaddingBottom());
    }

    public final void d() {
        int i10 = (this.prefixText == null || this.f23480i) ? 8 : 0;
        setVisibility((this.f23474c.getVisibility() == 0 || i10 == 0) ? 0 : 8);
        this.f23473b.setVisibility(i10);
        this.f23472a.r();
    }

    @Nullable
    public CharSequence getPrefixText() {
        return this.prefixText;
    }

    @Nullable
    public ColorStateList getPrefixTextColor() {
        return this.f23473b.getTextColors();
    }

    @Nullable
    public CharSequence getStartIconContentDescription() {
        return this.f23474c.getContentDescription();
    }

    @Nullable
    public Drawable getStartIconDrawable() {
        return this.f23474c.getDrawable();
    }

    @Override // android.widget.LinearLayout, android.view.View
    public final void onMeasure(int i10, int i11) {
        super.onMeasure(i10, i11);
        c();
    }

    public void setPrefixText(@Nullable CharSequence charSequence) {
        this.prefixText = TextUtils.isEmpty(charSequence) ? null : charSequence;
        this.f23473b.setText(charSequence);
        d();
    }

    public void setStartIconContentDescription(@Nullable CharSequence charSequence) {
        if (getStartIconContentDescription() != charSequence) {
            this.f23474c.setContentDescription(charSequence);
        }
    }

    public void setStartIconDrawable(@Nullable Drawable drawable) {
        CheckableImageButton checkableImageButton = this.f23474c;
        checkableImageButton.setImageDrawable(drawable);
        if (drawable == null) {
            b(false);
            setStartIconOnClickListener(null);
            setStartIconOnLongClickListener(null);
            setStartIconContentDescription(null);
            return;
        }
        ColorStateList colorStateList = this.f23475d;
        PorterDuff.Mode mode = this.f23476e;
        TextInputLayout textInputLayout = this.f23472a;
        q.a(textInputLayout, checkableImageButton, colorStateList, mode);
        b(true);
        q.c(textInputLayout, checkableImageButton, this.f23475d);
    }

    public void setStartIconOnClickListener(@Nullable View.OnClickListener onClickListener) {
        q.setIconOnClickListener(this.f23474c, onClickListener, this.f23479h);
    }

    public void setStartIconOnLongClickListener(@Nullable View.OnLongClickListener onLongClickListener) {
        this.f23479h = onLongClickListener;
        q.setIconOnLongClickListener(this.f23474c, onLongClickListener);
    }

    public void setStartIconTintList(@Nullable ColorStateList colorStateList) {
        if (this.f23475d != colorStateList) {
            this.f23475d = colorStateList;
            q.a(this.f23472a, this.f23474c, colorStateList, this.f23476e);
        }
    }

    public void setStartIconTintMode(@Nullable PorterDuff.Mode mode) {
        if (this.f23476e != mode) {
            this.f23476e = mode;
            q.a(this.f23472a, this.f23474c, this.f23475d, mode);
        }
    }
}
