C. Touch Screen Event
There are three buttons on the right side of the figure 3. The
client will respond as soon as anyone of them is clicked.
Actually, each click action generates a touch screen motion
event, which will be dealt by calling the
onTouchEvent(MotionEvent event) method. The parameter,
event, encapsulates the whole information about the motion,
containing the location, type, time and so on. Next, we should
call the getX() and getY() method to obtain the coordinates,
with the getAction() method called to obtain the type of the
motion, containing ACTION_DOWN, ACTION_MOVE and
ACTION_UP.
It is not difficult to complete these, however, the key to the
onTouchEvent() method is returning mechanism, which returns
true when the motion has been completely handled without
hoping to be processed by other callback method again,
otherwise returns false. There is evidence that the
ACTION_DOWN will be called firstly when we touch the
screen, with the ACTION_UP called next if the return value is
true. But if the return value is false, only the ACTION_DOWN
will be called. Hence, we select to return true and send the
message on the motion to the main thread by calling the
sendMessage() method of the Handler object for the sake of
further processing. Through this way, a touch screen motion
event can be immediately executed and completely processed
whenever it is generated.