Introducing Multi Touch

Multi-touch is simply an extension of the regular touch-screen user interface, using two or more fingers instead of one. We've used singlefinger gestures before,1 although we didn't call it that. Remember in Section 4.3, Entering Numbers, on page 89 when we let the user touch a tile in the Sudoku game in order to change it? That's called a tap gesture. Another gesture is called drag. That's where you hold one finger on the screen and move it around, causing the content under your finger to scroll.

Tap, drag, and a few other single-fingered gestures have always been supported in Android. However, because of the popularity of the Apple iPhone, early Android users suffered from a kind of gesture envy. The

1. Some people use them more than others.

C

Figure 11.1: Three common touch gestures: a) tap, b) drag, and c) pinch zoom iPhone supported multi-touch, in particular the "pinch zoom" gesture (see Figure 11.1).

With pinch zoom, you place two fingers on the screen and squeeze them together to make the item you're viewing smaller, or you pull them apart to make it bigger. Before Android 2.0, you had to use a clunky zoom control with icons that you pressed to zoom in and out (see the setBuilt-InZoomControls() method in Section 8.3, Getting Ready, on page 175). But thanks to its new multi-touch support, you can now pinch zoom on Android too—as long as the application supports it, of course.

Note: Android 2.2 introduced a new class called ScaleGestureDetector that recognizes the pinch zoom gesture. However, I decided not to use it in order to be compatible with 2.0 and 2.1 devices. If you only need to target 2.2, see the online documentation for more information.2

2. http://d.android.com/reference/android/view/ScaleGestureDetector.html

Warning: Multi-bugs Ahead

Multi-touch, as implemented on current Android phones, is extremely buggy. In fact, it's so buggy that it borders on the unusable. The API routinely reports invalid or impossible data points, especially during the transition from one finger to two fingers on the screen, and vice versa.

On the developer forums, you can find complaints of fingers getting swapped, x- and y-axes flipping, and multiple fingers sometimes being treated as one. Some of these problems can be traced back to hardware limitations in the touch-screen sensors used in certain phones, but many could be fixed or improved with software updates.

With a lot of trial and error, I was able to get the example in this chapter working because the gesture it implements is so simple. Until Google acknowledges and fixes the issues with multi-touch, that may be about all you can do. Luckily, pinch zoom seems to be the only multi-touch gesture most people want.

If you try to run the example in this chapter on Android 1.5 or 1.6, it will crash because those versions do not support multi-touch. We'll learn how to work around that in Section 13.3, Evolving with Android APIs, on page 259.

0 0

Post a comment