Search code examples
androidkotlinontouch

Detect Android touch event without moving


Is there any way to detect Android event like holding finger on screen but without moving? When I override function onTouch I can detect 3 types of events: ACTION_DOWN, ACTION_MOVE, ACTION_UP but when the user holds finger on screen without moving there isn't emitted any action. Is there any function which I can override to detect such an event?


Solution

  • First off- you're almost never not moving. Even if you aren't moving, small variations in the capacity of your finger and the shape of the contact with the screen will make it look like you're moving. So you'll be getting a constant stream of move events.

    Secondly- until you get an ACTION_UP or ACTION_CANCEL, you're still touching the device. So you basically just set a timer for however long you want to wait when you see a down, and cancel it when you see UP, CANCEL, or a MOVE that seems too big (you define what that threshold is). If the timer goes off, then you were holding your finger in one spot.