package android.support.v7.widget;

import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewParent;

/* JADX INFO: compiled from: ForwardingListener.java */
/* JADX INFO: loaded from: classes.dex */
public abstract class f0 implements View.OnTouchListener, View.OnAttachStateChangeListener {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final float f1025b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final int f1026c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final int f1027d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    final View f1028e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private Runnable f1029f;
    private Runnable g;
    private boolean h;
    private int i;
    private final int[] j = new int[2];

    /* JADX INFO: compiled from: ForwardingListener.java */
    private class a implements Runnable {
        a() {
        }

        @Override // java.lang.Runnable
        public void run() {
            ViewParent parent = f0.this.f1028e.getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
        }
    }

    /* JADX INFO: compiled from: ForwardingListener.java */
    private class b implements Runnable {
        b() {
        }

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

    public f0(View view) {
        this.f1028e = view;
        view.setLongClickable(true);
        view.addOnAttachStateChangeListener(this);
        this.f1025b = ViewConfiguration.get(view.getContext()).getScaledTouchSlop();
        int tapTimeout = ViewConfiguration.getTapTimeout();
        this.f1026c = tapTimeout;
        this.f1027d = (tapTimeout + ViewConfiguration.getLongPressTimeout()) / 2;
    }

    private void a() {
        Runnable runnable = this.g;
        if (runnable != null) {
            this.f1028e.removeCallbacks(runnable);
        }
        Runnable runnable2 = this.f1029f;
        if (runnable2 != null) {
            this.f1028e.removeCallbacks(runnable2);
        }
    }

    private boolean f(MotionEvent motionEvent) {
        d0 d0Var;
        View view = this.f1028e;
        android.support.v7.view.menu.s sVarB = b();
        if (sVarB == null || !sVarB.h() || (d0Var = (d0) sVarB.i()) == null || !d0Var.isShown()) {
            return false;
        }
        MotionEvent motionEventObtainNoHistory = MotionEvent.obtainNoHistory(motionEvent);
        i(view, motionEventObtainNoHistory);
        j(d0Var, motionEventObtainNoHistory);
        boolean zE = d0Var.e(motionEventObtainNoHistory, this.i);
        motionEventObtainNoHistory.recycle();
        int actionMasked = motionEvent.getActionMasked();
        return zE && (actionMasked != 1 && actionMasked != 3);
    }

    /* JADX WARN: Removed duplicated region for block: B:20:0x003d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private boolean g(android.view.MotionEvent r6) {
        /*
            r5 = this;
            android.view.View r0 = r5.f1028e
            boolean r1 = r0.isEnabled()
            r2 = 0
            if (r1 != 0) goto La
            return r2
        La:
            int r1 = r6.getActionMasked()
            if (r1 == 0) goto L41
            r3 = 1
            if (r1 == r3) goto L3d
            r4 = 2
            if (r1 == r4) goto L1a
            r6 = 3
            if (r1 == r6) goto L3d
            goto L6d
        L1a:
            int r1 = r5.i
            int r1 = r6.findPointerIndex(r1)
            if (r1 < 0) goto L6d
            float r4 = r6.getX(r1)
            float r6 = r6.getY(r1)
            float r1 = r5.f1025b
            boolean r6 = h(r0, r4, r6, r1)
            if (r6 != 0) goto L6d
            r5.a()
            android.view.ViewParent r6 = r0.getParent()
            r6.requestDisallowInterceptTouchEvent(r3)
            return r3
        L3d:
            r5.a()
            goto L6d
        L41:
            int r6 = r6.getPointerId(r2)
            r5.i = r6
            java.lang.Runnable r6 = r5.f1029f
            if (r6 != 0) goto L52
            android.support.v7.widget.f0$a r6 = new android.support.v7.widget.f0$a
            r6.<init>()
            r5.f1029f = r6
        L52:
            java.lang.Runnable r6 = r5.f1029f
            int r1 = r5.f1026c
            long r3 = (long) r1
            r0.postDelayed(r6, r3)
            java.lang.Runnable r6 = r5.g
            if (r6 != 0) goto L65
            android.support.v7.widget.f0$b r6 = new android.support.v7.widget.f0$b
            r6.<init>()
            r5.g = r6
        L65:
            java.lang.Runnable r6 = r5.g
            int r1 = r5.f1027d
            long r3 = (long) r1
            r0.postDelayed(r6, r3)
        L6d:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: android.support.v7.widget.f0.g(android.view.MotionEvent):boolean");
    }

    private static boolean h(View view, float f2, float f3, float f4) {
        float f5 = -f4;
        return f2 >= f5 && f3 >= f5 && f2 < ((float) (view.getRight() - view.getLeft())) + f4 && f3 < ((float) (view.getBottom() - view.getTop())) + f4;
    }

    private boolean i(View view, MotionEvent motionEvent) {
        view.getLocationOnScreen(this.j);
        motionEvent.offsetLocation(r0[0], r0[1]);
        return true;
    }

    private boolean j(View view, MotionEvent motionEvent) {
        view.getLocationOnScreen(this.j);
        motionEvent.offsetLocation(-r0[0], -r0[1]);
        return true;
    }

    public abstract android.support.v7.view.menu.s b();

    protected abstract boolean c();

    protected boolean d() {
        android.support.v7.view.menu.s sVarB = b();
        if (sVarB == null || !sVarB.h()) {
            return true;
        }
        sVarB.dismiss();
        return true;
    }

    void e() {
        a();
        View view = this.f1028e;
        if (view.isEnabled() && !view.isLongClickable() && c()) {
            view.getParent().requestDisallowInterceptTouchEvent(true);
            long jUptimeMillis = SystemClock.uptimeMillis();
            MotionEvent motionEventObtain = MotionEvent.obtain(jUptimeMillis, jUptimeMillis, 3, 0.0f, 0.0f, 0);
            view.onTouchEvent(motionEventObtain);
            motionEventObtain.recycle();
            this.h = true;
        }
    }

    @Override // android.view.View.OnTouchListener
    public boolean onTouch(View view, MotionEvent motionEvent) {
        boolean z;
        boolean z2 = this.h;
        if (z2) {
            z = f(motionEvent) || !d();
        } else {
            z = g(motionEvent) && c();
            if (z) {
                long jUptimeMillis = SystemClock.uptimeMillis();
                MotionEvent motionEventObtain = MotionEvent.obtain(jUptimeMillis, jUptimeMillis, 3, 0.0f, 0.0f, 0);
                this.f1028e.onTouchEvent(motionEventObtain);
                motionEventObtain.recycle();
            }
        }
        this.h = z;
        return z || z2;
    }

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

    @Override // android.view.View.OnAttachStateChangeListener
    public void onViewDetachedFromWindow(View view) {
        this.h = false;
        this.i = -1;
        Runnable runnable = this.f1029f;
        if (runnable != null) {
            this.f1028e.removeCallbacks(runnable);
        }
    }
}
