package p028j;

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;
import p023h0.C0829h1;
import p023h0.C0977w3;

/* renamed from: j.n3 */
/* loaded from: classes.dex */
public class View$OnLongClickListenerC1162n3 implements View.OnLongClickListener, View.OnHoverListener, View.OnAttachStateChangeListener {

    /* renamed from: n */
    public static View$OnLongClickListenerC1162n3 f2823n;

    /* renamed from: o */
    public static View$OnLongClickListenerC1162n3 f2824o;

    /* renamed from: d */
    public final View f2825d;

    /* renamed from: e */
    public final CharSequence f2826e;

    /* renamed from: f */
    public final int f2827f;

    /* renamed from: g */
    public final Runnable f2828g = new Runnable() { // from class: j.l3
        @Override // java.lang.Runnable
        public final void run() {
            View$OnLongClickListenerC1162n3.this.m1997e();
        }
    };

    /* renamed from: h */
    public final Runnable f2829h = new Runnable() { // from class: j.m3
        @Override // java.lang.Runnable
        public final void run() {
            View$OnLongClickListenerC1162n3.this.m1998d();
        }
    };

    /* renamed from: i */
    public int f2830i;

    /* renamed from: j */
    public int f2831j;

    /* renamed from: k */
    public C1170o3 f2832k;

    /* renamed from: l */
    public boolean f2833l;

    /* renamed from: m */
    public boolean f2834m;

    public View$OnLongClickListenerC1162n3(View view, CharSequence charSequence) {
        this.f2825d = view;
        this.f2826e = charSequence;
        this.f2827f = C0977w3.m2450a(ViewConfiguration.get(view.getContext()));
        m1999c();
        view.setOnLongClickListener(this);
        view.setOnHoverListener(this);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* renamed from: e */
    public /* synthetic */ void m1997e() {
        m1993i(false);
    }

    /* renamed from: g */
    public static void m1995g(View$OnLongClickListenerC1162n3 view$OnLongClickListenerC1162n3) {
        View$OnLongClickListenerC1162n3 view$OnLongClickListenerC1162n32 = f2823n;
        if (view$OnLongClickListenerC1162n32 != null) {
            view$OnLongClickListenerC1162n32.m2000b();
        }
        f2823n = view$OnLongClickListenerC1162n3;
        if (view$OnLongClickListenerC1162n3 != null) {
            view$OnLongClickListenerC1162n3.m1996f();
        }
    }

    /* renamed from: h */
    public static void m1994h(View view, CharSequence charSequence) {
        View$OnLongClickListenerC1162n3 view$OnLongClickListenerC1162n3 = f2823n;
        if (view$OnLongClickListenerC1162n3 != null && view$OnLongClickListenerC1162n3.f2825d == view) {
            m1995g(null);
        }
        if (!TextUtils.isEmpty(charSequence)) {
            new View$OnLongClickListenerC1162n3(view, charSequence);
            return;
        }
        View$OnLongClickListenerC1162n3 view$OnLongClickListenerC1162n32 = f2824o;
        if (view$OnLongClickListenerC1162n32 != null && view$OnLongClickListenerC1162n32.f2825d == view) {
            view$OnLongClickListenerC1162n32.m1998d();
        }
        view.setOnLongClickListener(null);
        view.setLongClickable(false);
        view.setOnHoverListener(null);
    }

    /* renamed from: b */
    public final void m2000b() {
        this.f2825d.removeCallbacks(this.f2828g);
    }

    /* renamed from: c */
    public final void m1999c() {
        this.f2834m = true;
    }

    /* renamed from: d */
    public void m1998d() {
        if (f2824o == this) {
            f2824o = null;
            C1170o3 c1170o3 = this.f2832k;
            if (c1170o3 != null) {
                c1170o3.m1962c();
                this.f2832k = null;
                m1999c();
                this.f2825d.removeOnAttachStateChangeListener(this);
            } else {
                Log.e("TooltipCompatHandler", "sActiveHandler.mPopup == null");
            }
        }
        if (f2823n == this) {
            m1995g(null);
        }
        this.f2825d.removeCallbacks(this.f2829h);
    }

    /* renamed from: f */
    public final void m1996f() {
        this.f2825d.postDelayed(this.f2828g, ViewConfiguration.getLongPressTimeout());
    }

    /* renamed from: i */
    public void m1993i(boolean z) {
        long longPressTimeout;
        long j;
        long j2;
        if (C0829h1.m2862A(this.f2825d)) {
            m1995g(null);
            View$OnLongClickListenerC1162n3 view$OnLongClickListenerC1162n3 = f2824o;
            if (view$OnLongClickListenerC1162n3 != null) {
                view$OnLongClickListenerC1162n3.m1998d();
            }
            f2824o = this;
            this.f2833l = z;
            C1170o3 c1170o3 = new C1170o3(this.f2825d.getContext());
            this.f2832k = c1170o3;
            c1170o3.m1960e(this.f2825d, this.f2830i, this.f2831j, this.f2833l, this.f2826e);
            this.f2825d.addOnAttachStateChangeListener(this);
            if (this.f2833l) {
                j2 = 2500;
            } else {
                if ((C0829h1.m2810x(this.f2825d) & 1) == 1) {
                    longPressTimeout = ViewConfiguration.getLongPressTimeout();
                    j = 3000;
                } else {
                    longPressTimeout = ViewConfiguration.getLongPressTimeout();
                    j = 15000;
                }
                j2 = j - longPressTimeout;
            }
            this.f2825d.removeCallbacks(this.f2829h);
            this.f2825d.postDelayed(this.f2829h, j2);
        }
    }

    /* renamed from: j */
    public final boolean m1992j(MotionEvent motionEvent) {
        int x = (int) motionEvent.getX();
        int y = (int) motionEvent.getY();
        if (this.f2834m || Math.abs(x - this.f2830i) > this.f2827f || Math.abs(y - this.f2831j) > this.f2827f) {
            this.f2830i = x;
            this.f2831j = y;
            this.f2834m = false;
            return true;
        }
        return false;
    }

    @Override // android.view.View.OnHoverListener
    public boolean onHover(View view, MotionEvent motionEvent) {
        if (this.f2832k == null || !this.f2833l) {
            AccessibilityManager accessibilityManager = (AccessibilityManager) this.f2825d.getContext().getSystemService("accessibility");
            if (accessibilityManager.isEnabled() && accessibilityManager.isTouchExplorationEnabled()) {
                return false;
            }
            int action = motionEvent.getAction();
            if (action != 7) {
                if (action == 10) {
                    m1999c();
                    m1998d();
                }
            } else if (this.f2825d.isEnabled() && this.f2832k == null && m1992j(motionEvent)) {
                m1995g(this);
            }
            return false;
        }
        return false;
    }

    @Override // android.view.View.OnLongClickListener
    public boolean onLongClick(View view) {
        this.f2830i = view.getWidth() / 2;
        this.f2831j = view.getHeight() / 2;
        m1993i(true);
        return true;
    }

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

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