package k4;

import android.text.InputFilter;
import android.text.method.PasswordTransformationMethod;
import android.text.method.TransformationMethod;
import android.util.SparseArray;
import android.widget.TextView;
import s3.i;

/* loaded from: classes.dex */
public final class f {

    /* renamed from: a, reason: collision with root package name */
    private final b f25371a;

    /* loaded from: classes.dex */
    private static class a extends b {

        /* renamed from: a, reason: collision with root package name */
        private final TextView f25372a;

        /* renamed from: b, reason: collision with root package name */
        private final d f25373b;

        /* renamed from: c, reason: collision with root package name */
        private boolean f25374c = true;

        a(TextView textView) {
            this.f25372a = textView;
            this.f25373b = new d(textView);
        }

        private InputFilter[] f(InputFilter[] inputFilterArr) {
            int length = inputFilterArr.length;
            for (InputFilter inputFilter : inputFilterArr) {
                if (inputFilter == this.f25373b) {
                    return inputFilterArr;
                }
            }
            InputFilter[] inputFilterArr2 = new InputFilter[inputFilterArr.length + 1];
            System.arraycopy(inputFilterArr, 0, inputFilterArr2, 0, length);
            inputFilterArr2[length] = this.f25373b;
            return inputFilterArr2;
        }

        private SparseArray g(InputFilter[] inputFilterArr) {
            SparseArray sparseArray = new SparseArray(1);
            for (int i10 = 0; i10 < inputFilterArr.length; i10++) {
                InputFilter inputFilter = inputFilterArr[i10];
                if (inputFilter instanceof d) {
                    sparseArray.put(i10, inputFilter);
                }
            }
            return sparseArray;
        }

        private InputFilter[] h(InputFilter[] inputFilterArr) {
            SparseArray g10 = g(inputFilterArr);
            if (g10.size() == 0) {
                return inputFilterArr;
            }
            int length = inputFilterArr.length;
            InputFilter[] inputFilterArr2 = new InputFilter[inputFilterArr.length - g10.size()];
            int i10 = 0;
            for (int i11 = 0; i11 < length; i11++) {
                if (g10.indexOfKey(i11) < 0) {
                    inputFilterArr2[i10] = inputFilterArr[i11];
                    i10++;
                }
            }
            return inputFilterArr2;
        }

        private TransformationMethod j(TransformationMethod transformationMethod) {
            return transformationMethod instanceof h ? ((h) transformationMethod).a() : transformationMethod;
        }

        private void k() {
            this.f25372a.setFilters(a(this.f25372a.getFilters()));
        }

        private TransformationMethod m(TransformationMethod transformationMethod) {
            return ((transformationMethod instanceof h) || (transformationMethod instanceof PasswordTransformationMethod)) ? transformationMethod : new h(transformationMethod);
        }

        @Override // k4.f.b
        InputFilter[] a(InputFilter[] inputFilterArr) {
            return !this.f25374c ? h(inputFilterArr) : f(inputFilterArr);
        }

        @Override // k4.f.b
        public boolean b() {
            return this.f25374c;
        }

        @Override // k4.f.b
        void c(boolean z10) {
            if (z10) {
                l();
            }
        }

        @Override // k4.f.b
        void d(boolean z10) {
            this.f25374c = z10;
            l();
            k();
        }

        @Override // k4.f.b
        TransformationMethod e(TransformationMethod transformationMethod) {
            return this.f25374c ? m(transformationMethod) : j(transformationMethod);
        }

        void i(boolean z10) {
            this.f25374c = z10;
        }

        void l() {
            this.f25372a.setTransformationMethod(e(this.f25372a.getTransformationMethod()));
        }
    }

    /* loaded from: classes.dex */
    static class b {
        b() {
        }

        abstract InputFilter[] a(InputFilter[] inputFilterArr);

        public abstract boolean b();

        abstract void c(boolean z10);

        abstract void d(boolean z10);

        abstract TransformationMethod e(TransformationMethod transformationMethod);
    }

    /* loaded from: classes.dex */
    private static class c extends b {

        /* renamed from: a, reason: collision with root package name */
        private final a f25375a;

        c(TextView textView) {
            this.f25375a = new a(textView);
        }

        private boolean f() {
            return !androidx.emoji2.text.e.k();
        }

        @Override // k4.f.b
        InputFilter[] a(InputFilter[] inputFilterArr) {
            return f() ? inputFilterArr : this.f25375a.a(inputFilterArr);
        }

        @Override // k4.f.b
        public boolean b() {
            return this.f25375a.b();
        }

        @Override // k4.f.b
        void c(boolean z10) {
            if (f()) {
                return;
            }
            this.f25375a.c(z10);
        }

        @Override // k4.f.b
        void d(boolean z10) {
            if (f()) {
                this.f25375a.i(z10);
            } else {
                this.f25375a.d(z10);
            }
        }

        @Override // k4.f.b
        TransformationMethod e(TransformationMethod transformationMethod) {
            return f() ? transformationMethod : this.f25375a.e(transformationMethod);
        }
    }

    public f(TextView textView, boolean z10) {
        i.h(textView, "textView cannot be null");
        if (z10) {
            this.f25371a = new a(textView);
        } else {
            this.f25371a = new c(textView);
        }
    }

    public InputFilter[] a(InputFilter[] inputFilterArr) {
        return this.f25371a.a(inputFilterArr);
    }

    public boolean b() {
        return this.f25371a.b();
    }

    public void c(boolean z10) {
        this.f25371a.c(z10);
    }

    public void d(boolean z10) {
        this.f25371a.d(z10);
    }

    public TransformationMethod e(TransformationMethod transformationMethod) {
        return this.f25371a.e(transformationMethod);
    }
}
