xbmc/android — pull request #8 by Montellese (2012-07-22 11:40:23+00:00)
Title: [droid] touch input refactor

These commits refactor the whole touch input handling currently done in CAndroidTouch based on events from the NDK and the native activity.

The general idea is to have a generic (i.e. not Android/platform specific) touch input handler/manager (CTouchInput) which contains all the logic to handle touch events (touch down/up/move) for multiple simultaneous touches (currently a maximum of 2 touches are supported). Whenever there is a touch event it is passed to CTouchInput through its Handle() method which triggers the logic to handle the new touch and deduce some action from it. Depending on the current and previous touch events CTouchInput calls callback methods. These callback methods are sent to a platform specific implementation derived from ITouchHandler which has been previously registered with CTouchInput. In these callback methods the platform specific implementation (in case of android this is CAndroidTouch) can send actions to XBMC (or ignore the event).

There are "low level" and "high level" callbacks in ITouchHandler. Currently available high level callbacks are OnSingleTap, OnSingleLongPress, OnDoubleTap, OnDoubleLongPress and OnZoomPinch. Low level callbacks are basically single/multi touch down, up, hold, move and events for pan start, move and end (although the pan related callbacks could be considered "high level" as well).

The behaviour of touch input has not changed apart from some fixes I have added to improve multi touch and especially double tap recoginition. In addition to the existing behaviour there is now also touch hold detection (for both single and multi touch) using a (very simple) timer class. The timeout for hold detection is configurable and defaults to 1 second (Android's default). I used the single touch hold (OnSingleLongPress) to trigger the right-click action (to bring up the context menu) which is currently done using double tap. IMO that's much easier to use and much more intuitive because that's how most Android browsers and editors work.

Obviously there's only one implementation of ITouchHandler so far (because iOS has its own touch handling logic provided by the iOS SDK). CAndroidTouch is now very simple and clean and easy to extend/adjust without having to work through the whole touch detection logic.