As a developer, I tend to program first then research later. I was trying to implement a screen that would handle multiple user inputs. Basically map more than just one finger. I tried two things..
I had an Activity class that implemented OnTouchListener. Here I had two separate child views that added the Activity as their ontouch listeners. And then I had a print line that printed out the event.getPointerCount() and printed out the location of each of the pointers..
Downloaded it to the phone and tested it. I noticed that the pointers never grew greater than two. I even noticed if one finger was on one child and another finger on the other child view that the events only made it to the first child component. Next I tried to put separate listeners on each of the child components to see if that would work but it acted the same.
So, it seems that the android only supports a total of two user inputs when dealing with inputs from the user touching the screen.
Is this true? It seems from testing and research that this is the case.
Has anyone ran into this limitation. Any clever work arounds?
Thanks for you time and responses.
dk
The number of touch points supported is dependent on the device. In all currently available versions of Android MotionEvent
s are sent to a single target view and describe the state of all currently active touch points. The target view is determined by where the first MotionEvent.ACTION_DOWN
event occurs.
See the post Making Sense of Multitouch on the Android Developers blog for a quick overview of working with multitouch events on Android.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With