package X6FRs_4.KQgRr5e_0.LGe8pk_15;

import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityManager;
/* compiled from: TooltipCompatHandler.java */
/* loaded from: classes.dex */
public class WkDTNqU_32 implements View.OnLongClickListener, View.OnHoverListener, View.OnAttachStateChangeListener {
    public static WkDTNqU_32 KQgRr5e_0;
    public static WkDTNqU_32 QxJ9d_1;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final int f765KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public ViqFd_33 f766KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final View f767KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final CharSequence f768KQgRr5e_0;
    public int PGPF6hQ_2;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public int f770QxJ9d_1;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public boolean f772QxJ9d_1;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Runnable f769KQgRr5e_0 = new KQgRr5e_0();

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public final Runnable f771QxJ9d_1 = new QxJ9d_1();

    /* compiled from: TooltipCompatHandler.java */
    /* loaded from: classes.dex */
    public class KQgRr5e_0 implements Runnable {
        public KQgRr5e_0() {
        }

        @Override // java.lang.Runnable
        public void run() {
            WkDTNqU_32.this.KQgRr5e_0(false);
        }
    }

    /* compiled from: TooltipCompatHandler.java */
    /* loaded from: classes.dex */
    public class QxJ9d_1 implements Runnable {
        public QxJ9d_1() {
        }

        @Override // java.lang.Runnable
        public void run() {
            WkDTNqU_32.this.PGPF6hQ_2();
        }
    }

    public WkDTNqU_32(View view, CharSequence charSequence) {
        this.f767KQgRr5e_0 = view;
        this.f768KQgRr5e_0 = charSequence;
        this.f765KQgRr5e_0 = X6FRs_4.IMuAHx_6.EuDEkJe_12.RfjZ_21.KQgRr5e_0(ViewConfiguration.get(view.getContext()));
        QxJ9d_1();
        this.f767KQgRr5e_0.setOnLongClickListener(this);
        this.f767KQgRr5e_0.setOnHoverListener(this);
    }

    public static void KQgRr5e_0(View view, CharSequence charSequence) {
        WkDTNqU_32 wkDTNqU_32 = KQgRr5e_0;
        if (wkDTNqU_32 != null && wkDTNqU_32.f767KQgRr5e_0 == view) {
            KQgRr5e_0((WkDTNqU_32) null);
        }
        if (TextUtils.isEmpty(charSequence)) {
            WkDTNqU_32 wkDTNqU_322 = QxJ9d_1;
            if (wkDTNqU_322 != null && wkDTNqU_322.f767KQgRr5e_0 == view) {
                wkDTNqU_322.PGPF6hQ_2();
            }
            view.setOnLongClickListener(null);
            view.setLongClickable(false);
            view.setOnHoverListener(null);
            return;
        }
        new WkDTNqU_32(view, charSequence);
    }

    public final void Mqv2r_3() {
        this.f767KQgRr5e_0.postDelayed(this.f769KQgRr5e_0, ViewConfiguration.getLongPressTimeout());
    }

    public void PGPF6hQ_2() {
        if (QxJ9d_1 == this) {
            QxJ9d_1 = null;
            ViqFd_33 viqFd_33 = this.f766KQgRr5e_0;
            if (viqFd_33 != null) {
                viqFd_33.KQgRr5e_0();
                this.f766KQgRr5e_0 = null;
                QxJ9d_1();
                this.f767KQgRr5e_0.removeOnAttachStateChangeListener(this);
            } else {
                Log.e("TooltipCompatHandler", "sActiveHandler.mPopup == null");
            }
        }
        if (KQgRr5e_0 == this) {
            KQgRr5e_0((WkDTNqU_32) null);
        }
        this.f767KQgRr5e_0.removeCallbacks(this.f771QxJ9d_1);
    }

    public final void QxJ9d_1() {
        this.f770QxJ9d_1 = Integer.MAX_VALUE;
        this.PGPF6hQ_2 = Integer.MAX_VALUE;
    }

    @Override // android.view.View.OnHoverListener
    public boolean onHover(View view, MotionEvent motionEvent) {
        if (this.f766KQgRr5e_0 == null || !this.f772QxJ9d_1) {
            AccessibilityManager accessibilityManager = (AccessibilityManager) this.f767KQgRr5e_0.getContext().getSystemService("accessibility");
            if (accessibilityManager.isEnabled() && accessibilityManager.isTouchExplorationEnabled()) {
                return false;
            }
            int action = motionEvent.getAction();
            if (action != 7) {
                if (action == 10) {
                    QxJ9d_1();
                    PGPF6hQ_2();
                }
            } else if (this.f767KQgRr5e_0.isEnabled() && this.f766KQgRr5e_0 == null && KQgRr5e_0(motionEvent)) {
                KQgRr5e_0(this);
            }
            return false;
        }
        return false;
    }

    @Override // android.view.View.OnLongClickListener
    public boolean onLongClick(View view) {
        this.f770QxJ9d_1 = view.getWidth() / 2;
        this.PGPF6hQ_2 = view.getHeight() / 2;
        KQgRr5e_0(true);
        return true;
    }

    @Override // android.view.View.OnAttachStateChangeListener
    public void onViewAttachedToWindow(View view) {
    }

    @Override // android.view.View.OnAttachStateChangeListener
    public void onViewDetachedFromWindow(View view) {
        PGPF6hQ_2();
    }

    public void KQgRr5e_0(boolean z) {
        long j;
        int longPressTimeout;
        long j2;
        if (X6FRs_4.IMuAHx_6.EuDEkJe_12.ZzDuCHW_20.m250IMuAHx_6(this.f767KQgRr5e_0)) {
            KQgRr5e_0((WkDTNqU_32) null);
            WkDTNqU_32 wkDTNqU_32 = QxJ9d_1;
            if (wkDTNqU_32 != null) {
                wkDTNqU_32.PGPF6hQ_2();
            }
            QxJ9d_1 = this;
            this.f772QxJ9d_1 = z;
            ViqFd_33 viqFd_33 = new ViqFd_33(this.f767KQgRr5e_0.getContext());
            this.f766KQgRr5e_0 = viqFd_33;
            viqFd_33.KQgRr5e_0(this.f767KQgRr5e_0, this.f770QxJ9d_1, this.PGPF6hQ_2, this.f772QxJ9d_1, this.f768KQgRr5e_0);
            this.f767KQgRr5e_0.addOnAttachStateChangeListener(this);
            if (this.f772QxJ9d_1) {
                j2 = 2500;
            } else {
                if ((X6FRs_4.IMuAHx_6.EuDEkJe_12.ZzDuCHW_20.Xgtqvk_8(this.f767KQgRr5e_0) & 1) == 1) {
                    j = 3000;
                    longPressTimeout = ViewConfiguration.getLongPressTimeout();
                } else {
                    j = 15000;
                    longPressTimeout = ViewConfiguration.getLongPressTimeout();
                }
                j2 = j - longPressTimeout;
            }
            this.f767KQgRr5e_0.removeCallbacks(this.f771QxJ9d_1);
            this.f767KQgRr5e_0.postDelayed(this.f771QxJ9d_1, j2);
        }
    }

    public static void KQgRr5e_0(WkDTNqU_32 wkDTNqU_32) {
        WkDTNqU_32 wkDTNqU_322 = KQgRr5e_0;
        if (wkDTNqU_322 != null) {
            wkDTNqU_322.KQgRr5e_0();
        }
        KQgRr5e_0 = wkDTNqU_32;
        if (wkDTNqU_32 != null) {
            wkDTNqU_32.Mqv2r_3();
        }
    }

    public final void KQgRr5e_0() {
        this.f767KQgRr5e_0.removeCallbacks(this.f769KQgRr5e_0);
    }

    public final boolean KQgRr5e_0(MotionEvent motionEvent) {
        int x = (int) motionEvent.getX();
        int y = (int) motionEvent.getY();
        if (Math.abs(x - this.f770QxJ9d_1) > this.f765KQgRr5e_0 || Math.abs(y - this.PGPF6hQ_2) > this.f765KQgRr5e_0) {
            this.f770QxJ9d_1 = x;
            this.PGPF6hQ_2 = y;
            return true;
        }
        return false;
    }
}
