2012-12-23 4 views
0

나는 안드로이드에서 멀티 터치를 공부하고 있었지만, 내가 찾은 라인의 일부를 이해할 수 없었다. 구글은 구글을 ​​찾았지만 그 이해할만한 자원을 찾을 수 없었다. 나는 코드를 게시하고있다.안드로이드에서의 멀티 터치 이해

내가 "onTouch 방법의 처음 두 행"을 제외한 부분의 대부분을 이해 if (event.getAction() != MotionEvent.ACTION_MOVE && i != pointerIndex)case MotionEvent.ACTION_MOVE:

을 설명해주십시오. 당신의 도움이 ~~ 자세한 내용은

package --- ; 

--imports-- 

@TargetApi(5) 
public class MultiTouchTest extends Activity implements OnTouchListener { 
StringBuilder builder = new StringBuilder(); 
TextView textView; 
float[] x = new float[10]; 
float[] y = new float[10]; 
boolean[] touched = new boolean[10]; 
int[] id = new int[10]; 

private void updateTextView() { 
    builder.setLength(0); 
    for (int i = 0; i < 10; i++) { 
     builder.append(touched[i]); 
     builder.append(", "); 
     builder.append(id[i]); 
     builder.append(", "); 
     builder.append(x[i]); 
     builder.append(", "); 
     builder.append(y[i]); 
     builder.append("\n"); 
    } 
    textView.setText(builder.toString()); 
} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    textView = new TextView(this); 
    textView.setText("Touch and drag(multiple fingers supported!"); 
    textView.setOnTouchListener(this); 
    setContentView(textView); 
    for (int i = 0; i < 10; i++) { 
     id[i] = -1; 
    } 
    updateTextView(); 
} 

@Override 
public boolean onTouch(View v, MotionEvent event) { 
    int action = event.getAction() & MotionEvent.ACTION_MASK; 
    int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT; 
    int pointerCount = event.getPointerCount(); 
    for (int i = 0; i < 10; i++) { 
     if (i >= pointerCount) { 
      touched[i] = false; 
      id[i] = -1; 
      continue; 
     } 

     if (event.getAction() != MotionEvent.ACTION_MOVE 
       && i != pointerIndex) { 

      continue; 
     } 
     int pointerId = event.getPointerId(i); 
     switch (action) { 
     case MotionEvent.ACTION_DOWN: 
     case MotionEvent.ACTION_POINTER_DOWN: 
      touched[i] = true; 
      id[i] = pointerId; 
      x[i] = (int) event.getX(i); 
      y[i] = (int) event.getY(i); 
      break; 
     case MotionEvent.ACTION_UP: 
     case MotionEvent.ACTION_POINTER_UP: 
     case MotionEvent.ACTION_OUTSIDE: 
     case MotionEvent.ACTION_CANCEL: 
      touched[i] = false; 
      id[i] = -1; 
      x[i] = (int) event.getX(i); 
      y[i] = (int) event.getY(i); 
      break; 
     case MotionEvent.ACTION_MOVE: 
      touched[i] = true; 
      id[i] = pointerId; 
      x[i] = (int) event.getX(i); 
      y[i] = (int) event.getY(i); 
      break; 
     } 

    } 
    updateTextView(); 

    return true; 
} 
} 

답변

1
/*Extract the index of the pointer that touch the sensor 
    Return the masked action being performed, without pointer index 
    information. 
    May be any of the actions: ACTION_DOWN, ACTION_MOVE, ACTION_UP, 
    ACTION_CANCEL, ACTION_POINTER_DOWN, or ACTION_POINTER_UP. 
    And return the index associated with pointer actions.*/ 

**int action = event.getAction() & MotionEvent.ACTION_MASK;** 

    /* Extract the index of the pointer that left the touch sensor 
    For ACTION_POINTER_DOWN or ACTION_POINTER_UP as returned by getActionMasked(), 
    this returns the associated pointer index. The index may be used with 
getPointerId(int), getX(int), getY(int), getPressure(int), and getSize(int) 
to get information about the pointer that has gone down or up.*/ 

**int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT;** 

에 대한 감사를 참조하십시오 Link 1 Link 2

+0

죄송하지만하여 "onTouch 방법의 처음 두 행을"내가 (INT 액션 = event.getAction'의미) & MotionEvent.ACTION_MASK; int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT;' – RE60K