package androidx.core.view;

import android.content.Context;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;

/* loaded from: classes.dex */
public class o {

    /* renamed from: a, reason: collision with root package name */
    private final Context f3887a;

    /* renamed from: b, reason: collision with root package name */
    private final p f3888b;

    /* renamed from: c, reason: collision with root package name */
    private final b f3889c;

    /* renamed from: d, reason: collision with root package name */
    private final a f3890d;

    /* renamed from: e, reason: collision with root package name */
    private VelocityTracker f3891e;

    /* renamed from: f, reason: collision with root package name */
    private float f3892f;

    /* renamed from: g, reason: collision with root package name */
    private int f3893g;

    /* renamed from: h, reason: collision with root package name */
    private int f3894h;

    /* renamed from: i, reason: collision with root package name */
    private int f3895i;

    /* renamed from: j, reason: collision with root package name */
    private final int[] f3896j;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public interface a {
        float a(VelocityTracker velocityTracker, MotionEvent motionEvent, int i10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public interface b {
        void a(Context context, int[] iArr, MotionEvent motionEvent, int i10);
    }

    public o(Context context, p pVar) {
        this(context, pVar, new b() { // from class: androidx.core.view.m
            @Override // androidx.core.view.o.b
            public final void a(Context context2, int[] iArr, MotionEvent motionEvent, int i10) {
                o.c(context2, iArr, motionEvent, i10);
            }
        }, new a() { // from class: androidx.core.view.n
            @Override // androidx.core.view.o.a
            public final float a(VelocityTracker velocityTracker, MotionEvent motionEvent, int i10) {
                float f10;
                f10 = o.f(velocityTracker, motionEvent, i10);
                return f10;
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static void c(Context context, int[] iArr, MotionEvent motionEvent, int i10) {
        ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
        iArr[0] = w0.g(context, viewConfiguration, motionEvent.getDeviceId(), i10, motionEvent.getSource());
        iArr[1] = w0.f(context, viewConfiguration, motionEvent.getDeviceId(), i10, motionEvent.getSource());
    }

    private boolean d(MotionEvent motionEvent, int i10) {
        int source = motionEvent.getSource();
        int deviceId = motionEvent.getDeviceId();
        if (this.f3894h == source && this.f3895i == deviceId && this.f3893g == i10) {
            return false;
        }
        this.f3889c.a(this.f3887a, this.f3896j, motionEvent, i10);
        this.f3894h = source;
        this.f3895i = deviceId;
        this.f3893g = i10;
        return true;
    }

    private float e(MotionEvent motionEvent, int i10) {
        if (this.f3891e == null) {
            this.f3891e = VelocityTracker.obtain();
        }
        return this.f3890d.a(this.f3891e, motionEvent, i10);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static float f(VelocityTracker velocityTracker, MotionEvent motionEvent, int i10) {
        p0.a(velocityTracker, motionEvent);
        p0.b(velocityTracker, 1000);
        return p0.d(velocityTracker, i10);
    }

    public void g(MotionEvent motionEvent, int i10) {
        boolean d10 = d(motionEvent, i10);
        if (this.f3896j[0] == Integer.MAX_VALUE) {
            VelocityTracker velocityTracker = this.f3891e;
            if (velocityTracker != null) {
                velocityTracker.recycle();
                this.f3891e = null;
                return;
            }
            return;
        }
        float e10 = e(motionEvent, i10) * this.f3888b.b();
        float signum = Math.signum(e10);
        float f10 = BitmapDescriptorFactory.HUE_RED;
        if (d10 || (signum != Math.signum(this.f3892f) && signum != BitmapDescriptorFactory.HUE_RED)) {
            this.f3888b.c();
        }
        float abs = Math.abs(e10);
        int[] iArr = this.f3896j;
        if (abs < iArr[0]) {
            return;
        }
        float max = Math.max(-r6, Math.min(e10, iArr[1]));
        if (this.f3888b.a(max)) {
            f10 = max;
        }
        this.f3892f = f10;
    }

    o(Context context, p pVar, b bVar, a aVar) {
        this.f3893g = -1;
        this.f3894h = -1;
        this.f3895i = -1;
        this.f3896j = new int[]{Api.BaseClientBuilder.API_PRIORITY_OTHER, 0};
        this.f3887a = context;
        this.f3888b = pVar;
        this.f3889c = bVar;
        this.f3890d = aVar;
    }
}
