Android Gestures

Since version 1.6 Android offers a library for recognition and handling of new gestures using a touch display. With the gesture builder it is possible to capture new gestures in the emulator. Gestures can be integrated into an activity like that. GestureLibrary gLib = GestureLibraries.fromRawResource(this, R.raw.spells); if (!gLib.load()) { finish(); } Furthermore we need a gesture overlay in the UI: <android.gesture.GestureOverlayView android:id="@+id/gestures" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1.0" /> In the next step we implement an event handler for the gesture (Source: http://developer.android.com/resources/articles/gestures.html): GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures); gestures.addOnGesturePerformedListener(this); public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { ArrayList<prediction> predictions = mLibrary.recognize(gesture); if (predictions.size() > 0) { Prediction prediction = predictions.get(0); if (prediction.score > 1.0) { Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT).show(); } } } ...

May 21, 2010 · 1 min · 197 words · Micha Kops