what-the-bank/sources/io/flutter/embedding/android/AndroidTouchProcessor.java

263 lines
9.9 KiB
Java

package io.flutter.embedding.android;
import android.graphics.Matrix;
import android.view.InputDevice;
import android.view.MotionEvent;
import io.flutter.embedding.engine.renderer.FlutterRenderer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.HashMap;
import java.util.Map;
/* loaded from: classes5.dex */
public class AndroidTouchProcessor {
static final int BYTES_PER_FIELD = 8;
private static final Matrix IDENTITY_TRANSFORM = new Matrix();
private static final int POINTER_DATA_FIELD_COUNT = 35;
private static final int POINTER_DATA_FLAG_BATCHED = 1;
private final FlutterRenderer renderer;
private final boolean trackMotionEvents;
private final Map<Integer, float[]> ongoingPans = new HashMap();
private final MotionEventTracker motionEventTracker = MotionEventTracker.getInstance();
/* loaded from: classes.dex */
public @interface PointerChange {
public static final int ADD = 1;
public static final int CANCEL = 0;
public static final int DOWN = 4;
public static final int HOVER = 3;
public static final int MOVE = 5;
public static final int PAN_ZOOM_END = 9;
public static final int PAN_ZOOM_START = 7;
public static final int PAN_ZOOM_UPDATE = 8;
public static final int REMOVE = 2;
public static final int UP = 6;
}
/* loaded from: classes.dex */
public @interface PointerDeviceKind {
public static final int INVERTED_STYLUS = 3;
public static final int MOUSE = 1;
public static final int STYLUS = 2;
public static final int TOUCH = 0;
public static final int TRACKPAD = 4;
public static final int UNKNOWN = 5;
}
/* loaded from: classes.dex */
public @interface PointerSignalKind {
public static final int NONE = 0;
public static final int SCALE = 3;
public static final int SCROLL = 1;
public static final int SCROLL_INERTIA_CANCEL = 2;
public static final int UNKNOWN = 4;
}
private int getPointerChangeForAction(int i) {
if (i == 0) {
return 4;
}
if (i == 1) {
return 6;
}
if (i == 5) {
return 4;
}
if (i == 6) {
return 6;
}
if (i == 2) {
return 5;
}
if (i == 7) {
return 3;
}
if (i == 3) {
return 0;
}
return i == 8 ? 3 : -1;
}
private int getPointerDeviceTypeForToolType(int i) {
if (i == 1) {
return 0;
}
if (i == 2) {
return 2;
}
if (i != 3) {
return i != 4 ? 5 : 3;
}
return 1;
}
public AndroidTouchProcessor(FlutterRenderer flutterRenderer, boolean z) {
this.renderer = flutterRenderer;
this.trackMotionEvents = z;
}
public boolean onTouchEvent(MotionEvent motionEvent) {
return onTouchEvent(motionEvent, IDENTITY_TRANSFORM);
}
public boolean onTouchEvent(MotionEvent motionEvent, Matrix matrix) {
int pointerCount = motionEvent.getPointerCount();
ByteBuffer allocateDirect = ByteBuffer.allocateDirect(pointerCount * 280);
allocateDirect.order(ByteOrder.LITTLE_ENDIAN);
int actionMasked = motionEvent.getActionMasked();
int pointerChangeForAction = getPointerChangeForAction(motionEvent.getActionMasked());
boolean z = actionMasked == 0 || actionMasked == 5;
boolean z2 = !z && (actionMasked == 1 || actionMasked == 6);
if (z) {
addPointerForIndex(motionEvent, motionEvent.getActionIndex(), pointerChangeForAction, 0, matrix, allocateDirect);
} else if (z2) {
for (int i = 0; i < pointerCount; i++) {
if (i != motionEvent.getActionIndex() && motionEvent.getToolType(i) == 1) {
addPointerForIndex(motionEvent, i, 5, 1, matrix, allocateDirect);
}
}
addPointerForIndex(motionEvent, motionEvent.getActionIndex(), pointerChangeForAction, 0, matrix, allocateDirect);
} else {
for (int i2 = 0; i2 < pointerCount; i2++) {
addPointerForIndex(motionEvent, i2, pointerChangeForAction, 0, matrix, allocateDirect);
}
}
if (allocateDirect.position() % 280 != 0) {
throw new AssertionError("Packet position is not on field boundary");
}
this.renderer.dispatchPointerDataPacket(allocateDirect, allocateDirect.position());
return true;
}
public boolean onGenericMotionEvent(MotionEvent motionEvent) {
boolean isFromSource = motionEvent.isFromSource(2);
boolean z = motionEvent.getActionMasked() == 7 || motionEvent.getActionMasked() == 8;
if (!isFromSource || !z) {
return false;
}
int pointerChangeForAction = getPointerChangeForAction(motionEvent.getActionMasked());
ByteBuffer allocateDirect = ByteBuffer.allocateDirect(motionEvent.getPointerCount() * 280);
allocateDirect.order(ByteOrder.LITTLE_ENDIAN);
addPointerForIndex(motionEvent, motionEvent.getActionIndex(), pointerChangeForAction, 0, IDENTITY_TRANSFORM, allocateDirect);
if (allocateDirect.position() % 280 != 0) {
throw new AssertionError("Packet position is not on field boundary.");
}
this.renderer.dispatchPointerDataPacket(allocateDirect, allocateDirect.position());
return true;
}
private void addPointerForIndex(MotionEvent motionEvent, int i, int i2, int i3, Matrix matrix, ByteBuffer byteBuffer) {
long j;
double d;
double d2;
InputDevice.MotionRange motionRange;
if (i2 == -1) {
return;
}
long id = this.trackMotionEvents ? this.motionEventTracker.track(motionEvent).getId() : 0L;
int pointerDeviceTypeForToolType = getPointerDeviceTypeForToolType(motionEvent.getToolType(i));
float[] fArr = {motionEvent.getX(i), motionEvent.getY(i)};
matrix.mapPoints(fArr);
if (pointerDeviceTypeForToolType == 1) {
j = motionEvent.getButtonState() & 31;
if (j == 0 && motionEvent.getSource() == 8194 && i2 == 4) {
this.ongoingPans.put(Integer.valueOf(motionEvent.getPointerId(i)), fArr);
}
} else {
j = pointerDeviceTypeForToolType == 2 ? (motionEvent.getButtonState() >> 4) & 15 : 0L;
}
boolean containsKey = this.ongoingPans.containsKey(Integer.valueOf(motionEvent.getPointerId(i)));
int i4 = motionEvent.getActionMasked() == 8 ? 1 : 0;
long eventTime = motionEvent.getEventTime();
byteBuffer.putLong(id);
byteBuffer.putLong(1000 * eventTime);
if (containsKey) {
byteBuffer.putLong(getPointerChangeForPanZoom(i2));
byteBuffer.putLong(4L);
} else {
byteBuffer.putLong(i2);
byteBuffer.putLong(pointerDeviceTypeForToolType);
}
byteBuffer.putLong(i4);
byteBuffer.putLong(motionEvent.getPointerId(i));
byteBuffer.putLong(0L);
if (containsKey) {
float[] fArr2 = this.ongoingPans.get(Integer.valueOf(motionEvent.getPointerId(i)));
byteBuffer.putDouble(fArr2[0]);
byteBuffer.putDouble(fArr2[1]);
} else {
byteBuffer.putDouble(fArr[0]);
byteBuffer.putDouble(fArr[1]);
}
byteBuffer.putDouble(0.0d);
byteBuffer.putDouble(0.0d);
byteBuffer.putLong(j);
byteBuffer.putLong(0L);
byteBuffer.putLong(0L);
byteBuffer.putDouble(motionEvent.getPressure(i));
if (motionEvent.getDevice() == null || (motionRange = motionEvent.getDevice().getMotionRange(2)) == null) {
d = 0.0d;
d2 = 1.0d;
} else {
d = motionRange.getMin();
d2 = motionRange.getMax();
}
byteBuffer.putDouble(d);
byteBuffer.putDouble(d2);
if (pointerDeviceTypeForToolType == 2) {
byteBuffer.putDouble(motionEvent.getAxisValue(24, i));
byteBuffer.putDouble(0.0d);
} else {
byteBuffer.putDouble(0.0d);
byteBuffer.putDouble(0.0d);
}
byteBuffer.putDouble(motionEvent.getSize(i));
byteBuffer.putDouble(motionEvent.getToolMajor(i));
byteBuffer.putDouble(motionEvent.getToolMinor(i));
byteBuffer.putDouble(0.0d);
byteBuffer.putDouble(0.0d);
byteBuffer.putDouble(motionEvent.getAxisValue(8, i));
if (pointerDeviceTypeForToolType == 2) {
byteBuffer.putDouble(motionEvent.getAxisValue(25, i));
} else {
byteBuffer.putDouble(0.0d);
}
byteBuffer.putLong(i3);
if (i4 == 1) {
byteBuffer.putDouble(-motionEvent.getAxisValue(10));
byteBuffer.putDouble(-motionEvent.getAxisValue(9));
} else {
byteBuffer.putDouble(0.0d);
byteBuffer.putDouble(0.0d);
}
if (containsKey) {
float[] fArr3 = this.ongoingPans.get(Integer.valueOf(motionEvent.getPointerId(i)));
byteBuffer.putDouble(fArr[0] - fArr3[0]);
byteBuffer.putDouble(fArr[1] - fArr3[1]);
} else {
byteBuffer.putDouble(0.0d);
byteBuffer.putDouble(0.0d);
}
byteBuffer.putDouble(0.0d);
byteBuffer.putDouble(0.0d);
byteBuffer.putDouble(1.0d);
byteBuffer.putDouble(0.0d);
if (containsKey && getPointerChangeForPanZoom(i2) == 9) {
this.ongoingPans.remove(Integer.valueOf(motionEvent.getPointerId(i)));
}
}
private int getPointerChangeForPanZoom(int i) {
if (i == 4) {
return 7;
}
if (i == 5) {
return 8;
}
if (i == 6 || i == 0) {
return 9;
}
throw new AssertionError("Unexpected pointer change");
}
}