package com.google.android.material.textfield;

import android.text.TextWatcher;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.EditText;
import com.google.android.material.internal.l;
import com.google.android.material.textfield.TextInputLayout;

/* JADX INFO: compiled from: PasswordToggleEndIconDelegate.java */
/* JADX INFO: loaded from: classes.dex */
class j extends e {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final TextWatcher f4333e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final TextInputLayout.f f4334f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final TextInputLayout.g f4335g;

    /* JADX INFO: compiled from: PasswordToggleEndIconDelegate.java */
    class a extends l {
        a() {
        }

        @Override // com.google.android.material.internal.l, android.text.TextWatcher
        public void beforeTextChanged(CharSequence charSequence, int i3, int i4, int i5) {
            j.this.f4299c.setChecked(!r0.g());
        }
    }

    /* JADX INFO: compiled from: PasswordToggleEndIconDelegate.java */
    class b implements TextInputLayout.f {
        b() {
        }

        @Override // com.google.android.material.textfield.TextInputLayout.f
        public void a(TextInputLayout textInputLayout) {
            EditText editText = textInputLayout.getEditText();
            j.this.f4299c.setChecked(!r0.g());
            editText.removeTextChangedListener(j.this.f4333e);
            editText.addTextChangedListener(j.this.f4333e);
        }
    }

    /* JADX INFO: compiled from: PasswordToggleEndIconDelegate.java */
    class c implements TextInputLayout.g {

        /* JADX INFO: compiled from: PasswordToggleEndIconDelegate.java */
        class a implements Runnable {

            /* JADX INFO: renamed from: e, reason: collision with root package name */
            final /* synthetic */ EditText f4339e;

            a(EditText editText) {
                this.f4339e = editText;
            }

            @Override // java.lang.Runnable
            public void run() {
                this.f4339e.removeTextChangedListener(j.this.f4333e);
            }
        }

        c() {
        }

        @Override // com.google.android.material.textfield.TextInputLayout.g
        public void a(TextInputLayout textInputLayout, int i3) {
            EditText editText = textInputLayout.getEditText();
            if (editText == null || i3 != 1) {
                return;
            }
            editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
            editText.post(new a(editText));
        }
    }

    /* JADX INFO: compiled from: PasswordToggleEndIconDelegate.java */
    class d implements View.OnClickListener {
        d() {
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            EditText editText = j.this.f4297a.getEditText();
            if (editText == null) {
                return;
            }
            int selectionEnd = editText.getSelectionEnd();
            if (j.this.g()) {
                editText.setTransformationMethod(null);
            } else {
                editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
            }
            if (selectionEnd >= 0) {
                editText.setSelection(selectionEnd);
            }
            j.this.f4297a.U();
        }
    }

    j(TextInputLayout textInputLayout, int i3) {
        super(textInputLayout, i3);
        this.f4333e = new a();
        this.f4334f = new b();
        this.f4335g = new c();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean g() {
        EditText editText = this.f4297a.getEditText();
        return editText != null && (editText.getTransformationMethod() instanceof PasswordTransformationMethod);
    }

    private static boolean h(EditText editText) {
        return editText != null && (editText.getInputType() == 16 || editText.getInputType() == 128 || editText.getInputType() == 144 || editText.getInputType() == 224);
    }

    @Override // com.google.android.material.textfield.e
    void a() {
        TextInputLayout textInputLayout = this.f4297a;
        int i3 = this.f4300d;
        if (i3 == 0) {
            i3 = l0.e.f5376a;
        }
        textInputLayout.setEndIconDrawable(i3);
        TextInputLayout textInputLayout2 = this.f4297a;
        textInputLayout2.setEndIconContentDescription(textInputLayout2.getResources().getText(l0.i.f5445p));
        this.f4297a.setEndIconVisible(true);
        this.f4297a.setEndIconCheckable(true);
        this.f4297a.setEndIconOnClickListener(new d());
        this.f4297a.g(this.f4334f);
        this.f4297a.h(this.f4335g);
        EditText editText = this.f4297a.getEditText();
        if (h(editText)) {
            editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        }
    }
}
