Android, peculiar TouchEvent scenario to handle?

I could imagine a Timing thread that is started on a TouchEvent. ACTION_DOWN, which would be started and run inside a loop that sleeps for 500ms. After the sleep it would then be able to perform its check, which would do your custom processing as well as checking whether or not TouchEvent.

ACTION_UP happened or not (which you would have to record in the EventHandler) Of course there is a bit of synchronization that would be required Does this make sense? Something along the lines of this: boolean upHappened; switch (myTouchHandler.getAction()) { case (TouchEvent. ACTION_DOWN): upHappened = false; new Thread(new TimerRunnable()).start(); case (TouchEvent.

ACTION_UP): case (TouchEvent. ACTION_CANCEL): upHappened = true; } class TimerRunnable implements Runnable { public void run() { while(true) { Thread. Sleep(500); if(upHappened) break; //custom processing } } }.

I could imagine a Timing thread that is started on a TouchEvent. ACTION_DOWN, which would be started and run inside a loop that sleeps for 500ms. After the sleep it would then be able to perform its check, which would do your custom processing as well as checking whether or not TouchEvent.

ACTION_UP happened or not (which you would have to record in the EventHandler). Of course there is a bit of synchronization that would be required. Does this make sense?

Something along the lines of this: boolean upHappened; switch (myTouchHandler.getAction()) { case (TouchEvent. ACTION_DOWN): upHappened = false; new Thread(new TimerRunnable()).start(); case (TouchEvent. ACTION_UP): case (TouchEvent.

ACTION_CANCEL): upHappened = true; } class TimerRunnable implements Runnable { public void run() { while(true) { Thread. Sleep(500); if(upHappened) break; //custom processing } } }.

Nicholas yes, it does :) – Aleadam May 10 at 1:21 1 +1 for the simple code. But I would add a case (TouchEvent. ACTION_CANCEL): to the switch (right below the other case, executing the same code).

– Aleadam May 10 at 1:31 Good call. I didn't remember that case. It is now reflected in the code.

Thanks! – nicholas. Hauschild May 10 at 1:32 1 A thread is way more heavy-weight than you need.

Just use Handler. SendMessageDelayed() to enqueue a message to be executed in 500ms. – hackbod May 10 at 2:29 This was an excellent solution, very elegant, thank you Nicholas.

@hackbod, sendMessageDelayed() wouldn't work for me as readily, as I don't ALWAYS want the 500ms events to fire, just only if its still held at that point in time. – Eric May 10 at 4:29.

The screen will be pressed until you have an event with either an ACTION_UP or ACTION_CANCEL actions, so I would check inversely.

I could imagine a Timing thread that is started on a TouchEvent. ACTION_DOWN, which would be started and run inside a loop that sleeps for 500ms. After the sleep it would then be able to perform its check, which would do your custom processing as well as checking whether or not TouchEvent.

ACTION_UP happened or not (which you would have to record in the EventHandler). Of course there is a bit of synchronization that would be required. Does this make sense?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions