기술/beginning games2011.05.24 18:23
download download
public class MultiTouchTest extends Activity implements OnTouchListener{

StringBuilder b = new StringBuilder();
TextView textView;
float[] x = new float[10];
float[] y = new float[10];
boolean[] touched = new boolean[10];
@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   textView = new TextView(this);
   textView.setText("터치 또는 드레그를 하세요(멀티 터치 가능");
   textView.setOnTouchListener(this);
   setContentView(textView);
}

@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 pointerId = event.getPointerId(pointerIndex);
switch(action){
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
touched[pointerId]=true;
x[pointerId] = (int)event.getX(pointerIndex);
y[pointerId] = (int)event.getY(pointerIndex);
break;
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
touched[pointerId]=false;
x[pointerId] = (int)event.getX(pointerIndex);
y[pointerId] = (int)event.getY(pointerIndex);
break;
case MotionEvent.ACTION_MOVE:
int pointerCount = event.getPointerCount();
for(int i=0; i < pointerCount; i++){
pointerIndex = i;
pointerId = event.getPointerId(pointerIndex);
x[pointerId] = (int)event.getX(pointerIndex);
y[pointerId] = (int)event.getY(pointerIndex);
}
break;
}
updateTextView();
return true;
}
private void updateTextView(){
b.setLength(0);
for(int i=0; i < 10; i++){
b.append(touched[i]);
b.append(", ");
b.append(x[i]);
b.append(", ");
b.append(y[i]);
b.append("\n");
}
textView.setText(b.toString());
}

}

추가 정보
[번역] 안드로이드에서 멀티터치 활용하기 (Making Sense of Multitouch)
 http://www.androidside.com/skin/board/mw.basic/mw.proc/mw.print.php?bo_table=B46&wr_id=11860
저작자 표시
신고
download download download
Posted by [lying dragon] Ed Kim

티스토리 툴바