I have an app that is used outdoors, in all conditions. These are on rooted B&N Nook tablets running Android 2.1. They have optical touch detection, not pressure, so a large raindrop on the screen can "disable" the device, because it's being detected as a press, and then all other presses are not detected.
Part one: in the activity being used, I manually detect long (10 second) screen presses, consistent with a raindrop beginning a blocking press. I use dispatchTouchEvent() for this and it's fine.
Part two: So then I open a new activity and actually circle the rain drop and tell the user "wipe up this rain drop". The new activity opens fine, and I can successfully draw circles anywhere I please.
The trouble is the new activity does not receive any touch events for that very first press... the long press that hasn't stopped yet. Not getting a "new" ACTION_DOWN is understandable... I already grabbed that. If I lift my finger though, there's no ACTION_UP either. After lifting the initial press, every works fine: I can tap the screen, instantly a circle is drawn around the spot, and it will move if I drag my finger, so no problems there.
How do I get the initial press, the one that brought me here, that still exists? It must some sort of polling API, not event, since I really want the current state and I know the event is already sucked up. To be clear, NO events are coming out of dispatchTouchEvent() until I first take my finger off the screen (even the off does not create a detectable event).
(I could grab the coordinates from the prior activity and pass it... but the trouble there is the rain drop could slide around during the 10 second wait period. And I would rather the activity be self contained in doing its job.)
I'm not sure you can (although I've never tried). I'm pretty sure the touch events are canceled out as soon as the new Activity is opened.
The approach that you may decide instead is to either use the Framgents API or simply open a new View on top of the View that's being touched.
The View that's receiving touch events will continue to do so until one of these events happen:
The method onTouchEvent()
returns false
. If it returns false
at any point, it will stop receiving touch events all together. Meaning, if you return false
in an ACTION_MOVE action, you will not receive an ACTION_UP action.
You receive an ACTION_CANCEL which denotes the gesture has ended. Usually it means the touch left the view bounds, but it could be a number of reasons.
You receive an ACTION_UP which means the last touching finger lifted from the View.
Views in the back will always receive touch events as long as Views in the front return false
for the actions which most do by default. So if you just pop up a new View on top of the View that's recording the touches, just keep recording and pass the draw coordinates to the top View.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With