package o;

import android.os.Handler;
import android.text.InputFilter;
import android.text.Selection;
import android.text.Spannable;
import android.widget.TextView;
import java.lang.ref.WeakReference;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.vv, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class RunnableC2763vv extends AbstractC1814lv implements Runnable {
    public final WeakReference l;
    public final WeakReference m;

    public RunnableC2763vv(TextView textView, C2858wv c2858wv) {
        this.l = new WeakReference(textView);
        this.m = new WeakReference(c2858wv);
    }

    @Override // o.AbstractC1814lv
    public final void b() {
        Handler handler;
        TextView textView = (TextView) this.l.get();
        if (textView == null || (handler = textView.getHandler()) == null) {
            return;
        }
        handler.post(this);
    }

    @Override // java.lang.Runnable
    public final void run() {
        InputFilter[] filters;
        int length;
        TextView textView = (TextView) this.l.get();
        InputFilter inputFilter = (InputFilter) this.m.get();
        if (inputFilter == null || textView == null || (filters = textView.getFilters()) == null) {
            return;
        }
        for (InputFilter inputFilter2 : filters) {
            if (inputFilter2 == inputFilter) {
                if (textView.isAttachedToWindow()) {
                    CharSequence text = textView.getText();
                    C2004nv c2004nvA = C2004nv.a();
                    if (text == null) {
                        length = 0;
                    } else {
                        c2004nvA.getClass();
                        length = text.length();
                    }
                    CharSequence charSequenceG = c2004nvA.g(0, length, 0, text);
                    if (text == charSequenceG) {
                        return;
                    }
                    int selectionStart = Selection.getSelectionStart(charSequenceG);
                    int selectionEnd = Selection.getSelectionEnd(charSequenceG);
                    textView.setText(charSequenceG);
                    if (charSequenceG instanceof Spannable) {
                        Spannable spannable = (Spannable) charSequenceG;
                        if (selectionStart >= 0 && selectionEnd >= 0) {
                            Selection.setSelection(spannable, selectionStart, selectionEnd);
                            return;
                        } else if (selectionStart >= 0) {
                            Selection.setSelection(spannable, selectionStart);
                            return;
                        } else {
                            if (selectionEnd >= 0) {
                                Selection.setSelection(spannable, selectionEnd);
                                return;
                            }
                            return;
                        }
                    }
                    return;
                }
                return;
            }
        }
    }
}
