Ok, with the help of
http://blog.javia.org/android-application-backwards-compatibility/ I implemented multitouch which should work on all sdk versions.
Here's the code (onTouch listener on a SurfaceView):
Using java Syntax Highlighting
public boolean onTouch(View v, MotionEvent event) {
input = event;
String sdkVersion = Build.VERSION.SDK;
Log.d(Build.VERSION.SDK, " ");
if(sdkVersion.equals("3") || sdkVersion.equals("4")){
// do single touch event, or notify that there is no multitouch available
} else {
// say its ok to use multitouch, or if this code is to be used in the
// ontouch listener, do:
float pointers[] = MultitouchWrapper.getPointerLocations(event);
Log.d(pointers[0] + " " + pointers[1], pointers[2] + " " + pointers[3]);
}
return true;
}
Parsed in 0.031 seconds, using
GeSHi 1.0.8.4
and now the MultitouchWrapper class:
Using java Syntax Highlighting
public class MultitouchWrapper {
static float[] getPointerLocations(MotionEvent event) {
float pointers[] = new float[4];
//Log.d(event.getPointerCount() + " pointers", " ");
switch (event.getPointerCount()) {
case 1:
pointers[0] = event.getX(0);
pointers[1] = event.getY(0);
pointers[2] = -1;
pointers[3] = -1;
break;
case 2:
pointers[0] = event.getX(0);
pointers[1] = event.getY(0);
pointers[2] = event.getX(1);
pointers[3] = event.getY(1);
break;
}
return pointers;
}
}
Parsed in 0.032 seconds, using
GeSHi 1.0.8.4
I guess you could add a "convenience" layer to the multitouch wrapper class, where the wrapper would return an object, say a PointerLocations class, where an instance called "pl" would have fields like pl.x1, pl.x2, pl.areMoreFingersPressed() etc.
I tested this out on a G1 and N1, and it works like a charm. However, the build target sdk of the project has to be 2.0+, and the manifest has to contain <uses-sdk android:minSdkVersion="3" /> for it to run on a G1.
Hope this helped

Paul