-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix new input system touches on android.
- Loading branch information
1 parent
1e21706
commit 0abef50
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/utils/CopyMotionEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// source https://gist.github.com/sebschaef/b803da53217c88e8c691aeed08602193 | ||
|
||
package com.xraph.plugin.flutter_unity_widget | ||
|
||
import android.view.MotionEvent | ||
|
||
/* | ||
Copies a MotionEvent. Use the named parameters to modify immutable properties. | ||
Don't forget to recycle the original event if it is not used anymore. | ||
*/ | ||
fun MotionEvent.copy( | ||
downTime: Long = getDownTime(), | ||
eventTime: Long = getEventTime(), | ||
action: Int = getAction(), | ||
pointerCount: Int = getPointerCount(), | ||
pointerProperties: Array<MotionEvent.PointerProperties>? = | ||
(0 until getPointerCount()) | ||
.map { index -> | ||
MotionEvent.PointerProperties().also { pointerProperties -> | ||
getPointerProperties(index, pointerProperties) | ||
} | ||
} | ||
.toTypedArray(), | ||
pointerCoords: Array<MotionEvent.PointerCoords>? = | ||
(0 until getPointerCount()) | ||
.map { index -> | ||
MotionEvent.PointerCoords().also { pointerCoords -> | ||
getPointerCoords(index, pointerCoords) | ||
} | ||
} | ||
.toTypedArray(), | ||
metaState: Int = getMetaState(), | ||
buttonState: Int = getButtonState(), | ||
xPrecision: Float = getXPrecision(), | ||
yPrecision: Float = getYPrecision(), | ||
deviceId: Int = getDeviceId(), | ||
edgeFlags: Int = getEdgeFlags(), | ||
source: Int = getSource(), | ||
flags: Int = getFlags() | ||
): MotionEvent = | ||
MotionEvent.obtain( | ||
downTime, | ||
eventTime, | ||
action, | ||
pointerCount, | ||
pointerProperties, | ||
pointerCoords, | ||
metaState, | ||
buttonState, | ||
xPrecision, | ||
yPrecision, | ||
deviceId, | ||
edgeFlags, | ||
source, | ||
flags | ||
) |