I wanted to calculate the screen touch time.
I used the "onKeyUp" function when my finger was not on the screen and "isKeyPressed" returned false.I used the "onKeyDown" function when my finger was on the screen. I wanted to calculate these times but onKeyDown function is not fired (checked on debub) and because of that startTime's value come "0".
Can you help me?
class MainActivity : AppCompatActivity(),SensorEventListener {
private lateinit var sensorManager: SensorManager
private var sensorGyroscope: Sensor? = null
private var sensorAccelerometer: Sensor? = null
private var sensorPressure: Sensor? = null
private var startTime: Long = 0
private var endTime: Long = 0
var isKeyPressed : Boolean = false
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
isKeyPressed = false
endTime = System.currentTimeMillis()
val result : Long = endTime - startTime
return true
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
isKeyPressed = true
startTime = System.currentTimeMillis()
return true
}
}