package androidx.core.view;

import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;
import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Objects;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f1789a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final e.y f1790b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final n f1791c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final n f1792d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public float f1793e;

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

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

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

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

    @Nullable
    private VelocityTracker mVelocityTracker;

    public o(Context context, e.y yVar) {
        n nVar = new n(0);
        n nVar2 = new n(1);
        this.f1794f = -1;
        this.f1795g = -1;
        this.f1796h = -1;
        this.f1797i = new int[]{Integer.MAX_VALUE, 0};
        this.f1789a = context;
        this.f1790b = yVar;
        this.f1791c = nVar;
        this.f1792d = nVar2;
    }

    /* JADX WARN: Removed duplicated region for block: B:31:0x0084  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void a(MotionEvent motionEvent, int i10) {
        int iIntValue;
        int iIntValue2;
        int dimensionPixelSize;
        char c6;
        boolean z10;
        int source = motionEvent.getSource();
        int deviceId = motionEvent.getDeviceId();
        int i11 = this.f1795g;
        int[] iArr = this.f1797i;
        if (i11 == source && this.f1796h == deviceId && this.f1794f == i10) {
            c6 = 0;
            z10 = false;
        } else {
            this.f1791c.getClass();
            Context context = this.f1789a;
            ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
            int deviceId2 = motionEvent.getDeviceId();
            int source2 = motionEvent.getSource();
            int i12 = Build.VERSION.SDK_INT;
            if (i12 >= 34) {
                Method method = t1.f1828a;
                iIntValue = z0.f(viewConfiguration, deviceId2, i10, source2);
            } else {
                Method method2 = t1.f1828a;
                InputDevice device = InputDevice.getDevice(deviceId2);
                if (device == null || device.getMotionRange(i10, source2) == null) {
                    iIntValue = Integer.MAX_VALUE;
                } else {
                    Resources resources = context.getResources();
                    int identifier = (source2 == 4194304 && i10 == 26) ? resources.getIdentifier("config_viewMinRotaryEncoderFlingVelocity", "dimen", "android") : -1;
                    Objects.requireNonNull(viewConfiguration);
                    if (identifier == -1) {
                        iIntValue = Integer.valueOf(viewConfiguration.getScaledMinimumFlingVelocity()).intValue();
                    } else if (identifier == 0 || (iIntValue = resources.getDimensionPixelSize(identifier)) < 0) {
                    }
                }
            }
            iArr[0] = iIntValue;
            int deviceId3 = motionEvent.getDeviceId();
            int source3 = motionEvent.getSource();
            if (i12 >= 34) {
                iIntValue2 = z0.e(viewConfiguration, deviceId3, i10, source3);
            } else {
                InputDevice device2 = InputDevice.getDevice(deviceId3);
                int i13 = Integer.MIN_VALUE;
                if ((device2 == null || device2.getMotionRange(i10, source3) == null) ? false : true) {
                    Resources resources2 = context.getResources();
                    int identifier2 = (source3 == 4194304 && i10 == 26) ? resources2.getIdentifier("config_viewMaxRotaryEncoderFlingVelocity", "dimen", "android") : -1;
                    Objects.requireNonNull(viewConfiguration);
                    if (identifier2 != -1) {
                        if (identifier2 != 0 && (dimensionPixelSize = resources2.getDimensionPixelSize(identifier2)) >= 0) {
                            i13 = dimensionPixelSize;
                        }
                        iIntValue2 = i13;
                    } else {
                        iIntValue2 = Integer.valueOf(viewConfiguration.getScaledMaximumFlingVelocity()).intValue();
                    }
                } else {
                    iIntValue2 = i13;
                }
            }
            iArr[1] = iIntValue2;
            this.f1795g = source;
            this.f1796h = deviceId;
            this.f1794f = i10;
            c6 = 0;
            z10 = true;
        }
        if (iArr[c6] == Integer.MAX_VALUE) {
            VelocityTracker velocityTracker = this.mVelocityTracker;
            if (velocityTracker != null) {
                velocityTracker.recycle();
                this.mVelocityTracker = null;
                return;
            }
            return;
        }
        if (this.mVelocityTracker == null) {
            this.mVelocityTracker = VelocityTracker.obtain();
        }
        VelocityTracker velocityTracker2 = this.mVelocityTracker;
        this.f1792d.getClass();
        Map map = a1.f1712a;
        velocityTracker2.addMovement(motionEvent);
        float f10 = 0.0f;
        if (Build.VERSION.SDK_INT < 34 && motionEvent.getSource() == 4194304) {
            Map map2 = a1.f1712a;
            if (!map2.containsKey(velocityTracker2)) {
                map2.put(velocityTracker2, new b1());
            }
            b1 b1Var = (b1) map2.get(velocityTracker2);
            b1Var.getClass();
            long eventTime = motionEvent.getEventTime();
            int i14 = b1Var.f1720d;
            long[] jArr = b1Var.f1718b;
            if (i14 != 0 && eventTime - jArr[b1Var.f1721e] > 40) {
                b1Var.f1720d = 0;
                b1Var.f1719c = 0.0f;
            }
            int i15 = (b1Var.f1721e + 1) % 20;
            b1Var.f1721e = i15;
            int i16 = b1Var.f1720d;
            if (i16 != 20) {
                b1Var.f1720d = i16 + 1;
            }
            b1Var.f1717a[i15] = motionEvent.getAxisValue(26);
            jArr[b1Var.f1721e] = eventTime;
        }
        a1.a(velocityTracker2);
        float fB = a1.b(velocityTracker2, i10);
        e.y yVar = this.f1790b;
        float f11 = fB * (-((NestedScrollView) yVar.f25365a).getVerticalScrollFactorCompat());
        float fSignum = Math.signum(f11);
        if (z10 || (fSignum != Math.signum(this.f1793e) && fSignum != 0.0f)) {
            ((NestedScrollView) yVar.f25365a).f1888d.abortAnimation();
        }
        if (Math.abs(f11) < iArr[0]) {
            return;
        }
        float fMax = Math.max(-r3, Math.min(f11, iArr[1]));
        if (fMax != 0.0f) {
            ((NestedScrollView) yVar.f25365a).f1888d.abortAnimation();
            ((NestedScrollView) yVar.f25365a).d((int) fMax);
            f10 = fMax;
        }
        this.f1793e = f10;
    }
}
