How to detect a touch screen that already exists when creating activity?

I have an application that is used outdoors, under any conditions. They are located on B & N Nook root tablets running Android 2.1. They have optical touch detection, not pressure, so a large drop of rain on the screen can "turn off" the device because it is detected as a press, and then all other presses are not detected.

Part one: in the activity I use, I manually detect long (10 seconds) on-screen presses that are consistent with the droplet that starts blocking pressing. I am using dispatchTouchEvent () for this and this is normal.

Part two. So, I am discovering a new activity and actually drawing rain and telling the user to "erase this drop of rain." The new activity opens perfectly, and I can successfully draw circles anywhere.

The problem is that the new activity does not receive any sensory events for this very first press ... a long press that has not stopped yet. Not getting the "new" ACTION_DOWN is understandable ... I already grabbed this. However, if I raise my finger, there is no ACTION_UP. After raising the initial click, each one works fine: I can touch the screen, the circle is drawn around the spot instantly, and it will move if I drag my finger, so there’s no problem.

How do I get the initial message that brought me here that still exists? This should be some kind of API poll, not an event, since I really want the current state, and I know that the event is already pulled in. To be clear, NO events come out of the dispatchTouchEvent () event until I first pull my finger off the screen (even shutting down doesn't create a detectable event).

(I could grab the coordinates from a previous activity and pass it ... but the problem is that the rain can glide over a 10-second waiting period. And I would prefer the activity to be autonomous when doing its job.)

+5
source share
1 answer

I'm not sure you can (although I never tried). I am sure that touch events will be canceled as soon as a new action is opened.

An approach you can decide is to either use the Framgents API or just open a new View on top of the View that has been affected.

A view that accepts touch events will continue to do this until one of these events occurs:

  • The onTouchEvent() method returns false . If it returns false at any time, it will stop accepting touch events all together. If you return false in the ACTION_MOVE action, you will not receive the ACTION_UP action.

  • You get ACTION_CANCEL, which means the gesture is over. Usually this means that the touch left the boundaries of the view, but this may be several reasons.

  • You get ACTION_UP, which means the last touching finger is raised from the view.

Views in the opposite direction will always receive touch events until views in front of the front return false for the actions that most do by default. Therefore, if you simply open a new top view of a view that records strokes, just continue recording and transfer the coordinates of the draw to the top view.

+2
source

All Articles