I wrote a very simple application to test multiple touch on my HTC Incredible phone. I behave pretty much like I thought and pretty much like the URL given by adamp. My results is that the phone could only handle two finger inputs. I have for box that each has its own OnTouchListener. When I click each box I print out a text for each. Clicking on each get touch events but with my index finger I clicked anywhere on the screen I got two pointers. From the MotionEvent event.getPointerCount method. Did not matter where the second finger landed. Could have been outside of the original view that received the first finger down event. Anyways here is the code if you like to try it yourself.
I have a 7z of the entire project but I do not think I can attach it.
So, here is the main activity and the xml for the layout.
package com.multitouch;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MultiTouch extends Activity {
protected LinearLayout sq1;
protected LinearLayout sq2;
protected LinearLayout sq3;
protected LinearLayout sq4;
protected String sqText = new String();
protected String sq1Text = new String();
protected String sq2Text = new String();
protected String sq3Text = new String();
private Handler handler = new Handler();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setViews();
handler.postDelayed(mUpdateUITimerTask, 5000);
}
private final Runnable mUpdateUITimerTask = new Runnable() {
public void run() {
// do whatever you want to change here, like:
updateTextField();
}
};
private void updateTextField() {
TextView view1 = (TextView) this.findViewById(R.id.logView);
TextView view2 = (TextView) this.findViewById(R.id.logView1);
TextView view3 = (TextView) this.findViewById(R.id.logView2);
TextView view4 = (TextView) this.findViewById(R.id.logView3);
//view1.append(sqText + "\n");
view1.setText(sqText);
view2.setText(sq1Text);
view3.setText(sq2Text);
view4.setText(sq3Text);
handler.post(mUpdateUITimerTask);
}
private void setViews() {
sq1 = (LinearLayout) this.findViewById(R.id.square1);
sq2 = (LinearLayout) this.findViewById(R.id.square2);
sq3 = (LinearLayout) this.findViewById(R.id.square3);
sq4 = (LinearLayout) this.findViewById(R.id.square4);
sq1.setOnTouchListener(new TouchListener());
sq2.setOnTouchListener(new TouchListener());
sq3.setOnTouchListener(new TouchListener());
sq4.setOnTouchListener(new TouchListener());
}
private class TouchListener implements OnTouchListener {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getPointerCount()>2) {
sq1Text = "GOT THREE POINTERS!!";
sq2Text = "GOT THREE POINTERS!!";
sq3Text = "GOT THREE POINTERS!!";
sqText = "GOT THREE POINTERS!!";
}
if(event.getAction() == MotionEvent.ACTION_DOWN){
switch(v.getId()) {
case R.id.square1:
sqText = "Square 1 Pressed::Pointer count = " + String.valueOf(event.getPointerCount());
break;
case R.id.square2:
sq1Text = "Square 2 Pressed::Pointer count = " + String.valueOf(event.getPointerCount());
break;
case R.id.square3:
sq2Text = "Square 3 Pressed::Pointer count = " + String.valueOf(event.getPointerCount());
break;
case R.id.square4:
sq3Text = "Square 4 Pressed::Pointer count = " + String.valueOf(event.getPointerCount());
break;
}
} else if(event.getAction() == MotionEvent.ACTION_POINTER_DOWN ||
event.getAction() == MotionEvent.ACTION_POINTER_UP) {
switch(v.getId()) {
case R.id.square1:
sqText = "Square 1 Pointer Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square2:
sq1Text = "Square 2 Pointer Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square3:
sq2Text = "Square 3 Pointer Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square4:
sq3Text = "Square 4 Pointer Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
}
} else if(event.getAction() == MotionEvent.ACTION_POINTER_1_DOWN) {
switch(v.getId()) {
case R.id.square1:
sqText = "Square 1 Pointer1Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square2:
sq1Text = "Square 2 Pointer1Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square3:
sq2Text = "Square 3 Pointer1Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square4:
sq3Text = "Square 4 Pointer1Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
}
} else if(event.getAction() == MotionEvent.ACTION_POINTER_2_DOWN) {
switch(v.getId()) {
case R.id.square1:
sqText = "Square 1 Pointer2Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square2:
sq1Text = "Square 2 Pointer2Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square3:
sq2Text = "Square 3 Pointer2Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square4:
sq3Text = "Square 4 Pointer2Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
}
} else if(event.getAction() == MotionEvent.ACTION_POINTER_3_DOWN) {
switch(v.getId()) {
case R.id.square1:
sqText = "Square 1 Pointer3Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square2:
sq1Text = "Square 2 Pointer3Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square3:
sq2Text = "Square 3 Pointer3Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square4:
sq3Text = "Square 4 Pointer3Down::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
}
} else if(event.getAction() == MotionEvent.ACTION_UP) {
switch(v.getId()) {
case R.id.square1:
sqText = "Square 1 UP::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square2:
sq1Text = "Square 2 UP::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square3:
sq2Text = "Square 3 UP::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square4:
sq3Text = "Square 4 UP::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
}
} else if(event.getAction() == MotionEvent.ACTION_MOVE) {
switch(v.getId()) {
case R.id.square1:
sqText = "Square 1 MOVE::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square2:
sq1Text = "Square 2 MOVE::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square3:
sq2Text = "Square 3 MOVE::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.square4:
sq3Text = "Square 4 MOVE::Pointer count = " + String.valueOf(event.getPointerCount()) + "\n";
break;
}
}
// TODO Auto-generated method stub
return true;
}
}
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/MainLay" >
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal" android:padding="10dip">
<TableRow android:gravity="center_horizontal" android:padding="10dip">
<LinearLayout android:background="#FFFF00" android:id="@+id/square1" android:padding="10px" android:layout_width="125px" android:layout_height="125px"/>
<LinearLayout android:background="#FF00FF" android:id="@+id/square2" android:padding="10px" android:layout_width="125px" android:layout_height="125px"/>
</TableRow>
<TableRow android:gravity="center_horizontal" android:padding="10dip">
<LinearLayout android:background="#00FFFF" android:id="@+id/square3" android:padding="10px" android:layout_width="125px" android:layout_height="125px"/>
<LinearLayout android:background="#eeeeee" android:id="@+id/square4" android:padding="10px" android:layout_width="125px" android:layout_height="125px"/>
</TableRow>
<TextView android:id="@+id/logView" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/logView1" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/logView2" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/logView3" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</TableLayout>
</LinearLayout>
Good luck, and if you try it let me know if you get the GOT THREE POINTERS!! print statements. I wonder what phones supports it.
thanks,
dk