package defpackage;

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 j$.util.Objects;
import java.lang.reflect.Method;
import java.util.Map;

/* JADX INFO: renamed from: ˋᵺ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1553 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final InterfaceC1813 f6236;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public VelocityTracker f6238;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final Context f6240;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public float f6242;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public int f6239 = -1;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public int f6243 = -1;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public int f6241 = -1;

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final int[] f6237 = {Integer.MAX_VALUE, 0};

    public C1553(Context context, InterfaceC1813 interfaceC1813) {
        this.f6240 = context;
        this.f6236 = interfaceC1813;
    }

    /* JADX WARN: Removed duplicated region for block: B:112:0x022d  */
    /* JADX WARN: Removed duplicated region for block: B:113:0x0235  */
    /* JADX WARN: Removed duplicated region for block: B:30:0x007d  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x00c4  */
    /* JADX WARN: Removed duplicated region for block: B:81:0x0168  */
    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m4381(MotionEvent motionEvent, int i) {
        int i2;
        int i3;
        int scaledMinimumFlingVelocity;
        int scaledMaximumFlingVelocity;
        boolean z;
        float f;
        float yVelocity;
        long j;
        int i4;
        float f2;
        float fSqrt;
        float f3;
        float[] fArr;
        float f4;
        int source = motionEvent.getSource();
        int deviceId = motionEvent.getDeviceId();
        int i5 = this.f6243;
        int[] iArr = this.f6237;
        if (i5 == source && this.f6241 == deviceId && this.f6239 == i) {
            z = false;
            i2 = 1;
            i3 = 0;
        } else {
            Context context = this.f6240;
            ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
            int deviceId2 = motionEvent.getDeviceId();
            int source2 = motionEvent.getSource();
            i2 = 1;
            int i6 = Build.VERSION.SDK_INT;
            i3 = 0;
            if (i6 >= 34) {
                Method method = AbstractC3263.f12482;
                scaledMinimumFlingVelocity = AbstractC1025.m3405(viewConfiguration, deviceId2, i, source2);
            } else {
                Method method2 = AbstractC3263.f12482;
                InputDevice device = InputDevice.getDevice(deviceId2);
                if (device == null || device.getMotionRange(i, source2) == null) {
                    scaledMinimumFlingVelocity = Integer.MAX_VALUE;
                } else {
                    Resources resources = context.getResources();
                    int identifier = (source2 == 4194304 && i == 26) ? resources.getIdentifier("config_viewMinRotaryEncoderFlingVelocity", "dimen", "android") : -1;
                    Objects.requireNonNull(viewConfiguration);
                    if (identifier == -1) {
                        scaledMinimumFlingVelocity = viewConfiguration.getScaledMinimumFlingVelocity();
                    } else if (identifier == 0 || (scaledMinimumFlingVelocity = resources.getDimensionPixelSize(identifier)) < 0) {
                    }
                }
            }
            iArr[0] = scaledMinimumFlingVelocity;
            int deviceId3 = motionEvent.getDeviceId();
            int source3 = motionEvent.getSource();
            if (i6 >= 34) {
                scaledMaximumFlingVelocity = AbstractC1025.m3395(viewConfiguration, deviceId3, i, source3);
            } else {
                InputDevice device2 = InputDevice.getDevice(deviceId3);
                if (device2 == null || device2.getMotionRange(i, source3) == null) {
                    scaledMaximumFlingVelocity = Integer.MIN_VALUE;
                } else {
                    Resources resources2 = context.getResources();
                    int identifier2 = (source3 == 4194304 && i == 26) ? resources2.getIdentifier("config_viewMaxRotaryEncoderFlingVelocity", "dimen", "android") : -1;
                    Objects.requireNonNull(viewConfiguration);
                    if (identifier2 == -1) {
                        scaledMaximumFlingVelocity = viewConfiguration.getScaledMaximumFlingVelocity();
                    } else if (identifier2 == 0 || (scaledMaximumFlingVelocity = resources2.getDimensionPixelSize(identifier2)) < 0) {
                    }
                }
            }
            iArr[1] = scaledMaximumFlingVelocity;
            this.f6243 = source;
            this.f6241 = deviceId;
            this.f6239 = i;
            z = true;
        }
        int i7 = iArr[i3];
        VelocityTracker velocityTracker = this.f6238;
        if (i7 == Integer.MAX_VALUE) {
            if (velocityTracker != null) {
                velocityTracker.recycle();
                this.f6238 = null;
                return;
            }
            return;
        }
        if (velocityTracker == null) {
            this.f6238 = VelocityTracker.obtain();
        }
        VelocityTracker velocityTracker2 = this.f6238;
        Map map = AbstractC3484.f13412;
        velocityTracker2.addMovement(motionEvent);
        float f5 = 0.0f;
        int i8 = 20;
        if (Build.VERSION.SDK_INT < 34 && motionEvent.getSource() == 4194304) {
            Map map2 = AbstractC3484.f13412;
            if (!map2.containsKey(velocityTracker2)) {
                map2.put(velocityTracker2, new C5020());
            }
            C5020 c5020 = (C5020) map2.get(velocityTracker2);
            long[] jArr = c5020.f19021;
            long eventTime = motionEvent.getEventTime();
            if (c5020.f19025 != 0 && eventTime - jArr[c5020.f19023] > 40) {
                c5020.f19025 = i3;
                c5020.f19022 = 0.0f;
            }
            int i9 = (c5020.f19023 + 1) % 20;
            c5020.f19023 = i9;
            int i10 = c5020.f19025;
            if (i10 != 20) {
                c5020.f19025 = i10 + 1;
            }
            c5020.f19024[i9] = motionEvent.getAxisValue(26);
            jArr[c5020.f19023] = eventTime;
        }
        velocityTracker2.computeCurrentVelocity(1000, Float.MAX_VALUE);
        C5020 c50202 = (C5020) AbstractC3484.f13412.get(velocityTracker2);
        if (c50202 != null) {
            float[] fArr2 = c50202.f19024;
            long[] jArr2 = c50202.f19021;
            int i11 = c50202.f19025;
            if (i11 < 2) {
                f2 = Float.MAX_VALUE;
                fSqrt = 0.0f;
                f = 0.0f;
                f4 = fSqrt * 1000.0f;
                c50202.f19022 = f4;
                if (f4 >= (-Math.abs(f2))) {
                    c50202.f19022 = -Math.abs(f2);
                } else if (c50202.f19022 > Math.abs(f2)) {
                    c50202.f19022 = Math.abs(f2);
                }
            } else {
                int i12 = c50202.f19023;
                int i13 = ((i12 + 20) - (i11 - 1)) % 20;
                long j2 = jArr2[i12];
                while (true) {
                    j = jArr2[i13];
                    long j3 = j2 - j;
                    i4 = c50202.f19025;
                    if (j3 <= 100) {
                        break;
                    }
                    c50202.f19025 = i4 - 1;
                    i13 = (i13 + 1) % 20;
                }
                if (i4 >= 2) {
                    if (i4 == 2) {
                        int i14 = (i13 + 1) % 20;
                        if (j != jArr2[i14]) {
                            fSqrt = fArr2[i14] / (r13 - j);
                            f2 = Float.MAX_VALUE;
                            f = 0.0f;
                        }
                    } else {
                        f2 = Float.MAX_VALUE;
                        float fAbs = 0.0f;
                        int i15 = 0;
                        int i16 = 0;
                        while (true) {
                            if (i15 >= c50202.f19025 - 1) {
                                break;
                            }
                            int i17 = i15 + i13;
                            long j4 = jArr2[i17 % 20];
                            int i18 = (i17 + 1) % i8;
                            if (jArr2[i18] == j4) {
                                f3 = f5;
                                fArr = fArr2;
                            } else {
                                i16++;
                                f3 = f5;
                                fArr = fArr2;
                                float fSqrt2 = (fAbs < f5 ? -1.0f : 1.0f) * ((float) Math.sqrt(Math.abs(fAbs) * 2.0f));
                                float f6 = fArr[i18] / (jArr2[i18] - j4);
                                fAbs += Math.abs(f6) * (f6 - fSqrt2);
                                if (i16 == i2) {
                                    fAbs *= 0.5f;
                                }
                            }
                            i15++;
                            f5 = f3;
                            fArr2 = fArr;
                            i8 = 20;
                            i2 = 1;
                        }
                        f = f5;
                        fSqrt = (fAbs < f ? -1.0f : 1.0f) * ((float) Math.sqrt(Math.abs(fAbs) * 2.0f));
                    }
                    f4 = fSqrt * 1000.0f;
                    c50202.f19022 = f4;
                    if (f4 >= (-Math.abs(f2))) {
                    }
                }
            }
        } else {
            f = 0.0f;
        }
        if (Build.VERSION.SDK_INT >= 34) {
            yVelocity = AbstractC1025.m3398(velocityTracker2, i);
        } else if (i == 0) {
            yVelocity = velocityTracker2.getXVelocity();
        } else if (i == 1) {
            yVelocity = velocityTracker2.getYVelocity();
        } else {
            C5020 c50203 = (C5020) AbstractC3484.f13412.get(velocityTracker2);
            yVelocity = (c50203 == null || i != 26) ? f : c50203.f19022;
        }
        InterfaceC1813 interfaceC1813 = this.f6236;
        float fMo4979 = interfaceC1813.mo4979() * yVelocity;
        float fSignum = Math.signum(fMo4979);
        if (z || (fSignum != Math.signum(this.f6242) && fSignum != f)) {
            interfaceC1813.mo4977();
        }
        if (Math.abs(fMo4979) < iArr[0]) {
            return;
        }
        float fMax = Math.max(-r1, Math.min(fMo4979, iArr[1]));
        this.f6242 = interfaceC1813.mo4978(fMax) ? fMax : f;
    }
}
