package m;

import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import androidx.appcompat.view.menu.ActionMenuItemView;
import n.C1206e;
import n.C1208f;
import n.C1210g;
import n.C1212h;
import n.RunnableC1199a0;
import n.Y;
import n4.u0;

/* JADX INFO: renamed from: m.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class ViewOnTouchListenerC1140a implements View.OnTouchListener, View.OnAttachStateChangeListener {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final /* synthetic */ View f14419A;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final float f14420q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final int f14421r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final int f14422s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final View f14423t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public RunnableC1199a0 f14424u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public RunnableC1199a0 f14425v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public boolean f14426w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public int f14427x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final int[] f14428y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final /* synthetic */ int f14429z;

    public ViewOnTouchListenerC1140a(View view) {
        this.f14428y = new int[2];
        this.f14423t = view;
        view.setLongClickable(true);
        view.addOnAttachStateChangeListener(this);
        this.f14420q = ViewConfiguration.get(view.getContext()).getScaledTouchSlop();
        int tapTimeout = ViewConfiguration.getTapTimeout();
        this.f14421r = tapTimeout;
        this.f14422s = (ViewConfiguration.getLongPressTimeout() + tapTimeout) / 2;
    }

    public final void a() {
        RunnableC1199a0 runnableC1199a0 = this.f14425v;
        View view = this.f14423t;
        if (runnableC1199a0 != null) {
            view.removeCallbacks(runnableC1199a0);
        }
        RunnableC1199a0 runnableC1199a02 = this.f14424u;
        if (runnableC1199a02 != null) {
            view.removeCallbacks(runnableC1199a02);
        }
    }

    public final AbstractC1149j b() {
        C1206e c1206e;
        switch (this.f14429z) {
            case u0.f15495q /* 0 */:
                AbstractC1141b abstractC1141b = ((ActionMenuItemView) this.f14419A).f7718C;
                if (abstractC1141b == null || (c1206e = ((C1208f) abstractC1141b).f14840a.f14850I) == null) {
                    return null;
                }
                return c1206e.a();
            default:
                C1206e c1206e2 = ((C1210g) this.f14419A).f14841t.H;
                if (c1206e2 == null) {
                    return null;
                }
                return c1206e2.a();
        }
    }

    public final boolean c() {
        AbstractC1149j abstractC1149jB;
        switch (this.f14429z) {
            case u0.f15495q /* 0 */:
                ActionMenuItemView actionMenuItemView = (ActionMenuItemView) this.f14419A;
                InterfaceC1146g interfaceC1146g = actionMenuItemView.f7716A;
                return interfaceC1146g != null && interfaceC1146g.a(actionMenuItemView.f7722x) && (abstractC1149jB = b()) != null && abstractC1149jB.h();
            default:
                ((C1210g) this.f14419A).f14841t.i();
                return true;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x005e  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x0086  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x00ef  */
    /* JADX WARN: Removed duplicated region for block: B:71:0x0124  */
    @Override // android.view.View.OnTouchListener
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean onTouch(View view, MotionEvent motionEvent) {
        boolean z8;
        boolean z9;
        Y y8;
        boolean z10 = this.f14426w;
        View view2 = this.f14423t;
        if (z10) {
            AbstractC1149j abstractC1149jB = b();
            if (abstractC1149jB == null || !abstractC1149jB.h() || (y8 = (Y) abstractC1149jB.i()) == null || !y8.isShown()) {
                switch (this.f14429z) {
                    case 1:
                        C1212h c1212h = ((C1210g) this.f14419A).f14841t;
                        if (c1212h.f14851J == null) {
                            c1212h.h();
                            z9 = true;
                        } else {
                            z9 = false;
                        }
                        break;
                    default:
                        AbstractC1149j abstractC1149jB2 = b();
                        if (abstractC1149jB2 != null && abstractC1149jB2.h()) {
                            abstractC1149jB2.dismiss();
                        }
                        z9 = true;
                        break;
                }
                z8 = !z9;
            } else {
                MotionEvent motionEventObtainNoHistory = MotionEvent.obtainNoHistory(motionEvent);
                int[] iArr = this.f14428y;
                view2.getLocationOnScreen(iArr);
                motionEventObtainNoHistory.offsetLocation(iArr[0], iArr[1]);
                y8.getLocationOnScreen(iArr);
                motionEventObtainNoHistory.offsetLocation(-iArr[0], -iArr[1]);
                boolean zB = y8.b(motionEventObtainNoHistory, this.f14427x);
                motionEventObtainNoHistory.recycle();
                int actionMasked = motionEvent.getActionMasked();
                boolean z11 = (actionMasked == 1 || actionMasked == 3) ? false : true;
                if (!zB || !z11) {
                }
            }
        } else if (view2.isEnabled()) {
            int actionMasked2 = motionEvent.getActionMasked();
            if (actionMasked2 == 0) {
                this.f14427x = motionEvent.getPointerId(0);
                if (this.f14424u == null) {
                    this.f14424u = new RunnableC1199a0(this, 0);
                }
                view2.postDelayed(this.f14424u, this.f14421r);
                if (this.f14425v == null) {
                    this.f14425v = new RunnableC1199a0(this, 1);
                }
                view2.postDelayed(this.f14425v, this.f14422s);
            } else if (actionMasked2 == 1) {
                a();
            } else if (actionMasked2 == 2) {
                int iFindPointerIndex = motionEvent.findPointerIndex(this.f14427x);
                if (iFindPointerIndex >= 0) {
                    float x8 = motionEvent.getX(iFindPointerIndex);
                    float y9 = motionEvent.getY(iFindPointerIndex);
                    float f3 = this.f14420q;
                    float f7 = -f3;
                    if (x8 < f7 || y9 < f7 || x8 >= (view2.getRight() - view2.getLeft()) + f3 || y9 >= (view2.getBottom() - view2.getTop()) + f3) {
                        a();
                        view2.getParent().requestDisallowInterceptTouchEvent(true);
                        z8 = c();
                        if (z8) {
                            long jUptimeMillis = SystemClock.uptimeMillis();
                            MotionEvent motionEventObtain = MotionEvent.obtain(jUptimeMillis, jUptimeMillis, 3, 0.0f, 0.0f, 0);
                            view2.onTouchEvent(motionEventObtain);
                            motionEventObtain.recycle();
                        }
                    }
                }
            } else if (actionMasked2 == 3) {
            }
            if (z8) {
            }
        } else {
            if (z8) {
            }
        }
        this.f14426w = z8;
        return z8 || z10;
    }

    @Override // android.view.View.OnAttachStateChangeListener
    public final void onViewDetachedFromWindow(View view) {
        this.f14426w = false;
        this.f14427x = -1;
        RunnableC1199a0 runnableC1199a0 = this.f14424u;
        if (runnableC1199a0 != null) {
            this.f14423t.removeCallbacks(runnableC1199a0);
        }
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public ViewOnTouchListenerC1140a(ActionMenuItemView actionMenuItemView) {
        this((View) actionMenuItemView);
        this.f14429z = 0;
        this.f14419A = actionMenuItemView;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public ViewOnTouchListenerC1140a(C1210g c1210g, C1210g c1210g2) {
        this(c1210g2);
        this.f14429z = 1;
        this.f14419A = c1210g;
    }

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