Cyanogen has ported my multi-touch code to the Android 2.0 / Eclair API, enabling much simpler implementation of multi-touch apps on top of the new Eclair multi-touch api. If you’re implementing MT apps, trust me, you don’t want to do it without this Java class The Eclair build includes both the official Linux kernel API for multi-touch, as well as changes to the MotionEvent class to support multiple touch points. You can use these directly to implement multi-touch apps on Android without any additional code, but dealing with the huge amount of noise in the event stream on touch up / touch down events is a hard problem. And re-implementing the boilerplate code for pinch-zoom over and over again is pointless, because it’s not as straightforward as you might think (you have to transform back and forth between two different coordinate spaces, etc.). Anyway my code helps with those problems, and to easily implement multi-touch apps on Eclair all you need is the patched version of my MultiTouchController.java class (see update below). (This is the class used in cyanogenmod to implement multi-touch scaling in the browser and the gallery.) This class dramatically simplifies the logic necessary to implement dual-touch scaling (pinch zoom) as well as other dual-touch operations involving the distance between the touch points and their orientation. There is also a *lot* of finicky behavior on current capacitive touchscreens on touch up / touch down events (e.g. one axis but not the other axis will suddenly jump to an ordinate of zero while the coordinate still reflects the correct location). This code takes care of cleaning up the event stream pretty dramatically so you get stable and useful dual-touch information, has lots of useful helper methods and classes, and has a high-speed integer sqrt for calculating the distance between the touch points. Anyway, thanks for porting the code, cyanogen [if anyone's paying attention, it means cyanogenmod is basically now Eclair]. I hope this Java class is useful to somebody — please drop me a line if you use it to implement multi-touch in your own projects. UPDATED [2010-06-09]: Updated code to Android-2.2, added support for 3+ touch points, and moved to hosting on Google Code, see the link below.
MT Controller: UPDATE [2010-06-09]: get it from the new Google Code project here.
MT Demos (should work out-of-the-box on an unpatched Droid or Nexus One): MTVisualizer.apk | MTMapsDemo.apk | MTPhotoSortrDemo.apk Note that MTVisualizer is also posted as a free app in the Android Market.
MT Demos, source code: MTDemos.zip
UPDATED [2010-06-09]: List of applications that make use of the MT Controller — see these for more examples of how to incorporate the MT Controller class into your own code:
- Mickael Despesse’s “Face Frenzy” face deformation app (not yet on the Market)
- Yuan Chin’s fork of ADW Launcher to support multitouch — Yuan says, “I just made use of the backported version by mmin of your MultiTouchController in my fork of ADW Launcher (to implement the pinch zoom), and I have to say it really simplified things (on top of the backwards compatibility)! Thank you! By the way, I will let @anderwebs know about it soon so it will be included in the ADW Launcher in the Market too!”
- David Byrne’s fractal viewing app Fractoid, available free in the Android Market and with source available under the GPL. David is the first person who has emailed me to say he’s using my code in an actual app shipping in the Market, thanks David! Fractoid is really nicely done, the code is clean, and the pinch-zooming works really well. It’s probably the best example of pinch-zoom out there right now because it zooms to exactly the pinched size, unlike the browser that can only zoom in-out by certain increments and constantly re-flows when you’re zooming. Try out Fractoid and let David know what you think!
- mmin’s handyCalc calculator, for pinch-zooming in/out of graphs.
- Formerly: The browser in the cyanogenmod replacement firmware (and before that, JesusFreke) — also possibly other firmwares like dwang5. Now replaced with official pinch/zoom in the second Nexus One OTA for Android 2.1.
UPDATE [2010-02-02]: Google releases an OTA update for the Nexus One that includes pinch-zoom in the three apps that make sense (Browser, Maps, Gallery3D). Unfortunately however, I looked at the multitouch code used in these apps with baksmali — and it appears that all three MT controller implementations are different. Also they don’t zoom around the correct point (the center of the pinch). My multitouch controller does the correct transformation between screen coordinates and object coordinates to get the center of the zoom correct, and makes writing apps like this much easier — they could have saved themselves some time and work
– Please donate if you use and like multi-touch on cyanogenmod (or previously on the JesusFreke ROMs) — it will encourage me to keep working on cool stuff!