如何将 MotionEvent 停机时间与时钟进行比较,它的时间基础是什么?
How to compare MotionEvent downtime to a clock, what is its time basis?
我正在尝试确定 MotionEvent 的时间顺序与 UI 对象中定期发生的事情的时间顺序。
private var rotateFinishTime: Long = -1
....
fun somethingHappensPeriodically() {
Log.d(tag_, "show new round")
...
this.rotateFinishTime = SystemClock.elapsedRealtime()
}
我附上了 GestureDetector.OnGestureListener:
override fun onSingleTapConfirmed(gd: GestureDetector, e: MotionEvent): Boolean {
// for tap: since it comes delayed, have to check event time
if (e.downTime < this.rotateFinishTime || this.rotating) {
Log.d(tag_, "e.downTime: $e.downTime rotateFinishTime: $rotateFinishTime downTime - rotateFinishTime: ${e.downTime - rotateFinishTime} rotating: $rotating")
return true
}
... do stuff
}
e.downTime: 4763800 rotateFinishTime: 18832541 downTime - rotateFinishTime:
-14068741 rotating: false
所以经过的实时时间似乎不是时间基础。显然,unix 纪元时间也不适合。有趣的注意事项:计算在 qemu 模拟器上产生 "expected" 结果,但在我的设备上没有 Android 6.0 flashed.
我想我找到了:我应该调用 SystemClock.uptimeMillis()
来进行有效比较。文档埋在InputEvent里,他们不在MotionEvent上背诵和重复:
/**
* Retrieve the time this event occurred,
* in the {@link android.os.SystemClock#uptimeMillis} time base.
*
* @return Returns the time this event occurred,
* in the {@link android.os.SystemClock#uptimeMillis} time base.
*/
显然,模拟器从未进入深度睡眠!
我正在尝试确定 MotionEvent 的时间顺序与 UI 对象中定期发生的事情的时间顺序。
private var rotateFinishTime: Long = -1
....
fun somethingHappensPeriodically() {
Log.d(tag_, "show new round")
...
this.rotateFinishTime = SystemClock.elapsedRealtime()
}
我附上了 GestureDetector.OnGestureListener:
override fun onSingleTapConfirmed(gd: GestureDetector, e: MotionEvent): Boolean {
// for tap: since it comes delayed, have to check event time
if (e.downTime < this.rotateFinishTime || this.rotating) {
Log.d(tag_, "e.downTime: $e.downTime rotateFinishTime: $rotateFinishTime downTime - rotateFinishTime: ${e.downTime - rotateFinishTime} rotating: $rotating")
return true
}
... do stuff
}
e.downTime: 4763800 rotateFinishTime: 18832541 downTime - rotateFinishTime: -14068741 rotating: false
所以经过的实时时间似乎不是时间基础。显然,unix 纪元时间也不适合。有趣的注意事项:计算在 qemu 模拟器上产生 "expected" 结果,但在我的设备上没有 Android 6.0 flashed.
我想我找到了:我应该调用 SystemClock.uptimeMillis()
来进行有效比较。文档埋在InputEvent里,他们不在MotionEvent上背诵和重复:
/** * Retrieve the time this event occurred, * in the {@link android.os.SystemClock#uptimeMillis} time base. * * @return Returns the time this event occurred, * in the {@link android.os.SystemClock#uptimeMillis} time base. */
显然,模拟器从未进入深度睡眠!