package C0;

import android.os.Build;
import android.util.SparseBooleanArray;
import android.util.SparseLongArray;
import android.view.MotionEvent;
import java.util.ArrayList;
import n.C2592t;
import o0.C2631b;

/* JADX INFO: renamed from: C0.m, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0112m {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public long f610a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final SparseLongArray f611b = new SparseLongArray();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final SparseBooleanArray f612c = new SparseBooleanArray();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final ArrayList f613d = new ArrayList();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final C2592t f614e = new C2592t((Object) null);

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f615f = -1;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int f616g = -1;

    public final void a(MotionEvent motionEvent) {
        int actionMasked = motionEvent.getActionMasked();
        SparseLongArray sparseLongArray = this.f611b;
        if (actionMasked != 0 && actionMasked != 5) {
            if (actionMasked != 9) {
                return;
            }
            int pointerId = motionEvent.getPointerId(0);
            if (sparseLongArray.indexOfKey(pointerId) < 0) {
                long j4 = this.f610a;
                this.f610a = 1 + j4;
                sparseLongArray.put(pointerId, j4);
                return;
            }
            return;
        }
        int actionIndex = motionEvent.getActionIndex();
        int pointerId2 = motionEvent.getPointerId(actionIndex);
        if (sparseLongArray.indexOfKey(pointerId2) < 0) {
            long j6 = this.f610a;
            this.f610a = 1 + j6;
            sparseLongArray.put(pointerId2, j6);
            if (motionEvent.getToolType(actionIndex) == 3) {
                this.f612c.put(pointerId2, true);
            }
        }
    }

    public final void b(MotionEvent motionEvent) {
        if (motionEvent.getPointerCount() != 1) {
            return;
        }
        int toolType = motionEvent.getToolType(0);
        int source = motionEvent.getSource();
        if (toolType == this.f615f && source == this.f616g) {
            return;
        }
        this.f615f = toolType;
        this.f616g = source;
        this.f612c.clear();
        this.f611b.clear();
    }

    /* JADX WARN: Removed duplicated region for block: B:49:0x00ff  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0120  */
    /* JADX WARN: Removed duplicated region for block: B:64:0x0135  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x018b  */
    /* JADX WARN: Removed duplicated region for block: B:74:0x01aa  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final T.p c(J0.A a6, MotionEvent motionEvent) {
        boolean z6;
        long jValueAt;
        float f6;
        long j4;
        long jS;
        long jG;
        int toolType;
        char c6;
        int i6;
        int historySize;
        int i7;
        char c7;
        long jFloatToRawIntBits;
        long j6;
        J0.A a7 = a6;
        int actionMasked = motionEvent.getActionMasked();
        SparseBooleanArray sparseBooleanArray = this.f612c;
        SparseLongArray sparseLongArray = this.f611b;
        int i8 = 3;
        if (actionMasked == 3 || actionMasked == 4) {
            sparseLongArray.clear();
            sparseBooleanArray.clear();
            return null;
        }
        b(motionEvent);
        a(motionEvent);
        boolean z7 = true;
        boolean z8 = actionMasked == 9 || actionMasked == 7 || actionMasked == 10;
        boolean z9 = actionMasked == 8;
        if (z8) {
            sparseBooleanArray.put(motionEvent.getPointerId(motionEvent.getActionIndex()), true);
        }
        int actionIndex = actionMasked != 1 ? actionMasked != 6 ? -1 : motionEvent.getActionIndex() : 0;
        ArrayList arrayList = this.f613d;
        arrayList.clear();
        int pointerCount = motionEvent.getPointerCount();
        int i9 = 0;
        while (i9 < pointerCount) {
            boolean z10 = (z8 || i9 == actionIndex || (z9 && motionEvent.getButtonState() == 0)) ? false : z7;
            int pointerId = motionEvent.getPointerId(i9);
            int iIndexOfKey = sparseLongArray.indexOfKey(pointerId);
            if (iIndexOfKey >= 0) {
                jValueAt = sparseLongArray.valueAt(iIndexOfKey);
                z6 = z9;
            } else {
                long j7 = this.f610a;
                z6 = z9;
                this.f610a = j7 + 1;
                sparseLongArray.put(pointerId, j7);
                jValueAt = j7;
            }
            float pressure = motionEvent.getPressure(i9);
            long jFloatToRawIntBits2 = (((long) Float.floatToRawIntBits(motionEvent.getY(i9))) & 4294967295L) | (((long) Float.floatToRawIntBits(motionEvent.getX(i9))) << 32);
            long jA = C2631b.a(jFloatToRawIntBits2, 0.0f, i8);
            if (i9 == 0) {
                f6 = 0.0f;
                jS = (((long) Float.floatToRawIntBits(motionEvent.getRawY())) & 4294967295L) | (((long) Float.floatToRawIntBits(motionEvent.getRawX())) << 32);
                jG = a7.G(jS);
            } else {
                f6 = 0.0f;
                if (Build.VERSION.SDK_INT >= 29) {
                    jS = (((long) Float.floatToRawIntBits(motionEvent.getRawY(i9))) & 4294967295L) | (((long) Float.floatToRawIntBits(motionEvent.getRawX(i9))) << 32);
                    jG = a7.G(jS);
                } else {
                    j4 = jFloatToRawIntBits2;
                    jS = a7.s(jFloatToRawIntBits2);
                    toolType = motionEvent.getToolType(i9);
                    if (toolType == 0) {
                        if (toolType != 1) {
                            c6 = ' ';
                            if (toolType == 2) {
                                i6 = 3;
                            } else if (toolType == i8) {
                                i6 = 2;
                            } else if (toolType == 4) {
                                i6 = 4;
                            }
                        } else {
                            c6 = ' ';
                            i6 = 1;
                        }
                        ArrayList arrayList2 = new ArrayList(motionEvent.getHistorySize());
                        historySize = motionEvent.getHistorySize();
                        i7 = 0;
                        while (i7 < historySize) {
                            float historicalX = motionEvent.getHistoricalX(i9, i7);
                            float historicalY = motionEvent.getHistoricalY(i9, i7);
                            if ((Float.floatToRawIntBits(historicalX) & Integer.MAX_VALUE) >= 2139095040 || (Float.floatToRawIntBits(historicalY) & Integer.MAX_VALUE) >= 2139095040) {
                                j6 = jS;
                            } else {
                                j6 = jS;
                                long jFloatToRawIntBits3 = (((long) Float.floatToRawIntBits(historicalX)) << c6) | (((long) Float.floatToRawIntBits(historicalY)) & 4294967295L);
                                arrayList2.add(new C0103d(motionEvent.getHistoricalEventTime(i7), jFloatToRawIntBits3, jFloatToRawIntBits3));
                            }
                            i7++;
                            jS = j6;
                        }
                        long j8 = jS;
                        if (motionEvent.getActionMasked() == 8) {
                            c7 = '\n';
                            jFloatToRawIntBits = (((long) Float.floatToRawIntBits(motionEvent.getAxisValue(10))) << c6) | (((long) Float.floatToRawIntBits((-motionEvent.getAxisValue(9)) + f6)) & 4294967295L);
                        } else {
                            c7 = '\n';
                            jFloatToRawIntBits = 0;
                        }
                        arrayList.add(new C(jValueAt, motionEvent.getEventTime(), j8, j4, z10, pressure, i6, sparseBooleanArray.get(motionEvent.getPointerId(i9), false), arrayList2, jFloatToRawIntBits, jA));
                        i9++;
                        z9 = z6;
                        i8 = 3;
                        z7 = true;
                        a7 = a6;
                    } else {
                        c6 = ' ';
                    }
                    i6 = 0;
                    ArrayList arrayList22 = new ArrayList(motionEvent.getHistorySize());
                    historySize = motionEvent.getHistorySize();
                    i7 = 0;
                    while (i7 < historySize) {
                    }
                    long j82 = jS;
                    if (motionEvent.getActionMasked() == 8) {
                    }
                    arrayList.add(new C(jValueAt, motionEvent.getEventTime(), j82, j4, z10, pressure, i6, sparseBooleanArray.get(motionEvent.getPointerId(i9), false), arrayList22, jFloatToRawIntBits, jA));
                    i9++;
                    z9 = z6;
                    i8 = 3;
                    z7 = true;
                    a7 = a6;
                }
            }
            j4 = jG;
            toolType = motionEvent.getToolType(i9);
            if (toolType == 0) {
            }
            i6 = 0;
            ArrayList arrayList222 = new ArrayList(motionEvent.getHistorySize());
            historySize = motionEvent.getHistorySize();
            i7 = 0;
            while (i7 < historySize) {
            }
            long j822 = jS;
            if (motionEvent.getActionMasked() == 8) {
            }
            arrayList.add(new C(jValueAt, motionEvent.getEventTime(), j822, j4, z10, pressure, i6, sparseBooleanArray.get(motionEvent.getPointerId(i9), false), arrayList222, jFloatToRawIntBits, jA));
            i9++;
            z9 = z6;
            i8 = 3;
            z7 = true;
            a7 = a6;
        }
        d(motionEvent);
        motionEvent.getEventTime();
        return new T.p(1, arrayList, motionEvent);
    }

    public final void d(MotionEvent motionEvent) {
        int actionMasked = motionEvent.getActionMasked();
        SparseBooleanArray sparseBooleanArray = this.f612c;
        SparseLongArray sparseLongArray = this.f611b;
        if (actionMasked == 1 || actionMasked == 6) {
            int pointerId = motionEvent.getPointerId(motionEvent.getActionIndex());
            if (!sparseBooleanArray.get(pointerId, false)) {
                sparseLongArray.delete(pointerId);
                sparseBooleanArray.delete(pointerId);
            }
        }
        if (sparseLongArray.size() > motionEvent.getPointerCount()) {
            for (int size = sparseLongArray.size() - 1; -1 < size; size--) {
                int iKeyAt = sparseLongArray.keyAt(size);
                int pointerCount = motionEvent.getPointerCount();
                int i6 = 0;
                while (true) {
                    if (i6 >= pointerCount) {
                        sparseLongArray.removeAt(size);
                        sparseBooleanArray.delete(iKeyAt);
                        break;
                    } else if (motionEvent.getPointerId(i6) == iKeyAt) {
                        break;
                    } else {
                        i6++;
                    }
                }
            }
        }
    }
}
