Stuart Lacy
Stuart Lacy

Reputation: 2003

Android frequency of onTouchListener?

I'm developing an app that essentially is Paint style. The user touchs the screen and can draw images. However I would like to measure the speed of the user's movements. At the moment I take the distance between the X and Y coordinates of the event.getX/Y and the previous values and calculate the difference. This is directly proportional to the speed of the movement provided that the timing intervals of the onTouchListener are constant. Is this the case for Android? I know for iPhone the Listener actually changes it's frequency depending on the input.

Furthermore if it is a constant value, does anyone know what it is? So I can portray the speed in useful units (mm/sec) rather than an arbitrary value.

Upvotes: 1

Views: 1240

Answers (2)

Sam Hammond
Sam Hammond

Reputation: 21

Sure this is a decade old question, but I have a specific answer. Following the TutorialPoint's Touch Event Tutorial, and modifying the textView size to fill the screen, I tested the callback frequency by logging the times it was called before release. I first held my finger in one position for exactly 10 seconds which resulted in 19 and 9 onTouchListener()->onTouch() event calls in two trials. Moving my finger as fast as I could back and forth resulted in counts within a few counts off of 600 for a 10 second time period in two attempts.

This equates to an exact maximum of 60 Hz for my S8+.

I logged my coordinates, exported them into Excel and did a scatter plot. Faster movement correlated with points becoming more sparse. In my application I want to have a user draw a wave to play as a tone for experimenting with different wave forms and how they sound. For good sound quality, I need at least 20 KHz, with a target of 40.1 KHz.

Upvotes: 1

gianpi
gianpi

Reputation: 3220

I don't think it's the same for Android (but I have to say I'm not 100% sure). But since this could potentially differ even between manufacturers, could you not look at System.currentTimeMillis() on the two events, to calculate the speed yourself?

Upvotes: 1

Related Questions