5:35 여기서 network 작업을 다른 thread에서 하고 있는 것을 가정한다. network작업 결과가 성공적이면 public void sendSuccess()를 호출하고 실패하면 public void sendFail()를 호출한다. 각각의 함수는 mHandler.obtainMessage()를 통해 각각에 필요한 재사용가능한 message를 main thread에 있는 message pool에서 가져오고 mHandler.sendMessage()를 통해 message queue에 올려 놓는다. 그리고 looper에 의해 순서가 되면 mHandler.handleMessage()가 호출된다.
9:30 에서 나오는 NetworkRequest class는 실제 android에서 제공하는 class가 아니고 이 강의에서 설명을 위해서 만들어진 class이다.
참고로 factory pattern은 하나의 factory class를 통해 여러 다른 타입의 하위 클래스를 상황에 따라 맞게 생성할수 있다. 예를 들어 X를 extends한 x1 , x2클래스가 있는 경우 factory X를 통해 상황에 따라 x1, x2를 생성할수 있다.
Multi-Touch in android was available since Android 2.0. When more than one finger touches the screen multi-touch gesture happens and android provide various apis to handle these gestures. Lets start with the basic event handling for single finger on the screen
public boolean onTouchEvent(MotionEvent ev){ final int action = ev.getAction(); switch(action) { case MotionEvent.ACTION_DOWN: { Log.i("Event handled ", "Action finger down"); break; } case MotionEvent.ACTION_UP: { Log.i("Event handled ", "Action finger up"); break; } return true; }
The above is the one of many methods of handling touches which logs touch down and up of single finger. This work fine as long as we don’t need to handle multiple fingers. But in many cases handling single finger events in not sufficient. For handling multi-touch we need to handle the below two additional events.
ACTION_POINTER_DOWN – MotionEvent.ACTION_POINTER_DOWN is the event triggered whenever the secondary pointer touches the screen. If there is already a pointer(finger) on the screen and one more pointer goes in contact with the screen, ACTION_POINTER_DOWN event is triggered. For all the next coming pointers the ACTION_POINTER_DOWN is triggered. MotionEvent.ACTION_DOWN will be triggered only for the first pointer coming in contact with the screen.
ACTION_POINTER_UP – MotionEvent.ACTION_POINTER_UP is the event triggered when a pointer goes up and there in yet another pointer still in contact with the screen. The same event is triggered for all pointer going up till the last pointer and MotionEvent.ACTION_UP will be triggered for the last pointer leaving the screen.
The next two things we should know to keep track of each pointer is are Pointer Index and Pointer ID. Lets see what they are and how they help us in handling multi-touch.
Index – In a MotionEvent object, the pointer details are stored in array. So, the Index of a pointer is its position in that array. From this we can infer that pointer index in not persistent across the event. To put that with an example, when a first pointer touches the screen, it will be the first object in array, with pointer index 0. When second pointer comes, it will be stored in index 1. Now when the pointer with index 0 goes up, the position of pointer in array is rearranged, which puts the second pointer which is currently stays on screen in index 0.
ID – While the pointer index is non persistent, to identify the pointers across events of an entire gesture, Pointer IDcomes in handy. Pointer ID is unique ID mapping to the pointer which stays persistent always. So in the example discussed for Index, even when the position of pointer in array changes, its pointer id remains same. That makes the difference between Index and ID.