Reputation: 3175
I am trying to determine the chronological ordering of a MotionEvent vs something that happens periodically in my UI object.
private var rotateFinishTime: Long = -1
....
fun somethingHappensPeriodically() {
Log.d(tag_, "show new round")
...
this.rotateFinishTime = SystemClock.elapsedRealtime()
}
I have a GestureDetector.OnGestureListener attached:
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
So the elapsed real-time doesn't seem to be the time basis. Obviously, unix epoch time doesn't fit either. Interesting note: the calculation produces the "expected" results on the qemu emulator, but not on my device with stock Android 6.0 flashed.
Upvotes: 3
Views: 641
Reputation: 3175
I think I found it: I should call SystemClock.uptimeMillis()
to make a valid comparison. The documentation is buried in InputEvent, they don't recite or repeat it on 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. */
Obviously, the emulator never went into deep sleep!
Upvotes: 4