Skip to content Skip to sidebar Skip to footer

Taking A Picture With Ontouch On X Seconds

First of all I want to Thank SO for being here for the don`t Know hows. Second, I am relative new to android programing and doing this for about 2 weeks now. ok My Question: I`m Wr

Solution 1:

The way some android components(such as GestureDetector) do it, is they use a Handler to send delayed messages. So for example, on a ACTION_DOWN event you could call sendEmptyMessageDelayed(int what, long delayMillis), and on ACTION_UP event call removeMessages(int what). If the event is delivered, that means a ACTION_UP never happened, which means the users finger is still down. This ignores the user moving there finger around, though. So you would have set up 'slop' area, and check if they left it with every ACTION_MOVE. Upon the users finger leaving the slop area, you would then cancel the message.

You can read the GestureDetector source code here to see how they did it.

Solution 2:

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP && event.getEventTime() - event.getDownTime() >= 5000)
        Toast.makeText(getApplicationContext(), "CAMERA ACTION", Toast.LENGTH_LONG).show();
    returntrue;
}

Post a Comment for "Taking A Picture With Ontouch On X Seconds"