package o;

import android.text.Editable;
import android.text.Selection;
import android.text.Spannable;
import android.text.TextWatcher;
import android.widget.EditText;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Fv, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0151Fv implements TextWatcher {
    public final EditText l;
    public RunnableC0125Ev m;
    public boolean n = true;

    public C0151Fv(EditText editText) {
        this.l = editText;
    }

    public static void a(EditText editText, int i) {
        int length;
        if (i == 1 && editText != null && editText.isAttachedToWindow()) {
            Editable editableText = editText.getEditableText();
            int selectionStart = Selection.getSelectionStart(editableText);
            int selectionEnd = Selection.getSelectionEnd(editableText);
            C2004nv c2004nvA = C2004nv.a();
            if (editableText == null) {
                length = 0;
            } else {
                c2004nvA.getClass();
                length = editableText.length();
            }
            c2004nvA.g(0, length, 0, editableText);
            if (selectionStart >= 0 && selectionEnd >= 0) {
                Selection.setSelection(editableText, selectionStart, selectionEnd);
            } else if (selectionStart >= 0) {
                Selection.setSelection(editableText, selectionStart);
            } else if (selectionEnd >= 0) {
                Selection.setSelection(editableText, selectionEnd);
            }
        }
    }

    @Override // android.text.TextWatcher
    public final void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        EditText editText = this.l;
        if (!editText.isInEditMode() && this.n && C2004nv.d() && i2 <= i3 && (charSequence instanceof Spannable)) {
            int iC = C2004nv.a().c();
            if (iC != 0) {
                if (iC == 1) {
                    C2004nv.a().g(i, i3 + i, 0, (Spannable) charSequence);
                    return;
                } else if (iC != 3) {
                    return;
                }
            }
            C2004nv c2004nvA = C2004nv.a();
            if (this.m == null) {
                this.m = new RunnableC0125Ev(editText);
            }
            c2004nvA.h(this.m);
        }
    }

    @Override // android.text.TextWatcher
    public final void afterTextChanged(Editable editable) {
    }

    @Override // android.text.TextWatcher
    public final void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
    }
}
