Limit to number of touches on Android?
I have a small test app on Android that is meant to test tracking multitouch input, but I am only ever getting two touches at the same time on my Evo. Does anyone know if this is a limitation to Android or the hardware?
By the way, here's my test class so you can try it out yourself.
import java.util.HashMap;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.MotionEvent;
import android.view.View;
public class PressureView extends View
{
private HashMap<Integer, Spot> mSpots = new HashMap<Integer, Spot>();
private final int[] mColors;
private final Paint mPaint;
public PressureView(Context context)
{
开发者_StackOverflow super(context);
mPaint = new Paint();
mPaint.setStyle(Style.FILL);
mColors = new int[]{Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.MAGENTA};
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawColor(Color.WHITE);
for(int id : mSpots.keySet())
{
Spot spot = mSpots.get(id);
mPaint.setColor(spot.Color);
canvas.drawCircle(spot.X, spot.Y, spot.Pressure*500, mPaint);
}
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
System.out.println("************************** " + event.getPointerCount() + " Pointers");
for(int i = 0; i < event.getPointerCount(); i++)
{
int id = event.getPointerId(i);
Spot spot = null;
if(mSpots.containsKey(id))
{
spot = mSpots.get(id);
}
else
{
spot = new Spot();
spot.Color = mColors[mSpots.size()];
}
if(event.getAction() == MotionEvent.ACTION_UP) spot.Pressure = 0;
else spot.Pressure = event.getPressure(id);
spot.X = event.getX(id);
spot.Y = event.getY(id);
mSpots.put(id, spot);
}
invalidate();
return true;
}
private class Spot
{
public float X, Y, Pressure;
public int Color;
}
}
It seems that currently all HTC devices only can 2 finger multi-touch, but the Android SDK supports more fingers. E.g. the Galaxy S i9000 has support for more http://www.youtube.com/watch?v=KRCDRXYJBCY .
精彩评论