package b4;

import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.Spanned;
import android.text.TextWatcher;
import android.widget.TextView;
import androidx.databinding.g;

/* loaded from: classes.dex */
public abstract class e {

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

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ d f6742p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ g f6743q;

        a(c cVar, d dVar, g gVar, b bVar) {
            this.f6742p = dVar;
            this.f6743q = gVar;
        }

        @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) {
            d dVar = this.f6742p;
            if (dVar != null) {
                dVar.onTextChanged(charSequence, i10, i11, i12);
            }
            g gVar = this.f6743q;
            if (gVar != null) {
                gVar.a();
            }
        }
    }

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

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

    /* loaded from: classes.dex */
    public interface d {
        void onTextChanged(CharSequence charSequence, int i10, int i11, int i12);
    }

    public static String a(TextView textView) {
        return textView.getText().toString();
    }

    private static boolean b(CharSequence charSequence, CharSequence charSequence2) {
        if ((charSequence == null) != (charSequence2 == null)) {
            return true;
        }
        if (charSequence == null) {
            return false;
        }
        int length = charSequence.length();
        if (length != charSequence2.length()) {
            return true;
        }
        for (int i10 = 0; i10 < length; i10++) {
            if (charSequence.charAt(i10) != charSequence2.charAt(i10)) {
                return true;
            }
        }
        return false;
    }

    public static void c(TextView textView, Drawable drawable) {
        d(drawable);
        Drawable[] compoundDrawablesRelative = textView.getCompoundDrawablesRelative();
        textView.setCompoundDrawablesRelative(drawable, compoundDrawablesRelative[1], compoundDrawablesRelative[2], compoundDrawablesRelative[3]);
    }

    private static void d(Drawable drawable) {
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        }
    }

    public static void e(TextView textView, CharSequence charSequence) {
        CharSequence text = textView.getText();
        if (charSequence != text) {
            if (charSequence == null && text.length() == 0) {
                return;
            }
            if (charSequence instanceof Spanned) {
                if (charSequence.equals(text)) {
                    return;
                }
            } else if (!b(charSequence, text)) {
                return;
            }
            textView.setText(charSequence);
        }
    }

    public static void f(TextView textView, c cVar, d dVar, b bVar, g gVar) {
        a aVar = (cVar == null && bVar == null && dVar == null && gVar == null) ? null : new a(cVar, dVar, gVar, bVar);
        TextWatcher textWatcher = (TextWatcher) b4.d.a(textView, aVar, d4.a.f15912a);
        if (textWatcher != null) {
            textView.removeTextChangedListener(textWatcher);
        }
        if (aVar != null) {
            textView.addTextChangedListener(aVar);
        }
    }
}
