package com.unity3d.player;

import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.View;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;

/* loaded from: /storage/emulated/0/Documents/jadec/sources/com.UBI.A90.WW/dex-files/2.dex */
public final class i {
    private LinkedHashMap a = new LinkedHashMap();

    /* loaded from: /storage/emulated/0/Documents/jadec/sources/com.UBI.A90.WW/dex-files/2.dex */
    public static class a {
        final int a;
        final float[] b;

        public a(int i, float[] fArr) {
            this.a = i;
            this.b = fArr;
        }
    }

    public static float a(MotionEvent motionEvent, int i) {
        return a(motionEvent, 9, i);
    }

    private static float a(MotionEvent motionEvent, int i, int i2) {
        return motionEvent.getAxisValue(i, i2);
    }

    private static Object a(Object obj, int i) {
        if (i < Array.getLength(obj)) {
            Object newInstance = Array.newInstance(obj.getClass().getComponentType(), i);
            System.arraycopy(obj, 0, newInstance, 0, i);
            return newInstance;
        }
        return obj;
    }

    private void a(int[] iArr) {
        int i = 0;
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        int length = iArr.length;
        int i2 = 0;
        while (i < length) {
            int i3 = iArr[i];
            int i4 = i2 + 1;
            d dVar = new d(i2, a(i3));
            if (dVar.b != null) {
                linkedHashMap.put(Integer.valueOf(i3), dVar);
            }
            i++;
            i2 = i4;
        }
        this.a = linkedHashMap;
    }

    public static boolean a(View view, MotionEvent motionEvent) {
        return view.dispatchGenericMotionEvent(motionEvent);
    }

    public static int[] a(int i) {
        InputDevice device = InputDevice.getDevice(i);
        if (device == null) {
            return null;
        }
        List<InputDevice.MotionRange> motionRanges = device.getMotionRanges();
        int[] iArr = new int[motionRanges.size()];
        int i2 = 0;
        Iterator<InputDevice.MotionRange> it = motionRanges.iterator();
        while (true) {
            int i3 = i2;
            if (!it.hasNext()) {
                return b((int[]) a(iArr, i3));
            }
            InputDevice.MotionRange next = it.next();
            if ((next.getSource() & 16777232) == 16777232) {
                iArr[i3] = next.getAxis();
                i2 = i3 + 1;
            } else {
                i2 = i3;
            }
        }
    }

    public static String b(int i) {
        InputDevice device = InputDevice.getDevice(i);
        if (device != null) {
            return device.getName();
        }
        return null;
    }

    private static int[] b(int[] iArr) {
        Arrays.sort(iArr);
        return iArr;
    }

    private d c(int i) {
        d dVar = (d) this.a.get(Integer.valueOf(i));
        if (dVar == null) {
            a();
            return (d) this.a.get(Integer.valueOf(i));
        }
        return dVar;
    }

    public final int[] a() {
        int i;
        int[] deviceIds = InputDevice.getDeviceIds();
        int[] iArr = new int[deviceIds.length];
        int length = deviceIds.length;
        int i2 = 0;
        int i3 = 0;
        while (i2 < length) {
            int i4 = deviceIds[i2];
            InputDevice device = InputDevice.getDevice(i4);
            if (device == null || (device.getSources() & 16777232) != 16777232) {
                i = i3;
            } else {
                i = i3 + 1;
                iArr[i3] = i4;
            }
            i2++;
            i3 = i;
        }
        int[] b = b((int[]) a(iArr, i3));
        a(b);
        return b;
    }

    public final a[] a(MotionEvent motionEvent) {
        a[] aVarArr = new a[motionEvent.getPointerCount()];
        int i = 0;
        for (int i2 = 0; i2 < aVarArr.length; i2++) {
            d c = c(motionEvent.getDeviceId());
            if (c != null) {
                a aVar = new a(c.a, new float[c.b.length]);
                for (int i3 = 0; i3 < c.b.length; i3++) {
                    aVar.b[i3] = a(motionEvent, c.b[i3], i2);
                }
                aVarArr[i] = aVar;
                i++;
            }
        }
        return (a[]) a(aVarArr, i);
    }
}
