From 9c817b7472cbf441bf75b2ef0ffc3c0ee9c9be8e Mon Sep 17 00:00:00 2001 From: Pavel fljot Date: Wed, 1 Aug 2012 19:41:58 +0300 Subject: [PATCH] Implement touch cancelation handling --- src/org/gestouch/core/GesturesManager.as | 15 +++++++++++- src/org/gestouch/gestures/Gesture.as | 29 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/org/gestouch/core/GesturesManager.as b/src/org/gestouch/core/GesturesManager.as index 77b4d96..1820be0 100644 --- a/src/org/gestouch/core/GesturesManager.as +++ b/src/org/gestouch/core/GesturesManager.as @@ -313,7 +313,20 @@ package org.gestouch.core gestouch_internal function onTouchCancel(touch:Touch):void { - //TODO + var gesturesForTouch:Vector. = _gesturesForTouchMap[touch] as Vector.; + var gesture:Gesture; + var i:uint = gesturesForTouch.length; + while (i-- > 0) + { + gesture = gesturesForTouch[i]; + + if (!_dirtyGesturesMap[gesture] && gesture.isTrackingTouch(touch.id)) + { + gesture.touchCancelHandler(touch); + } + } + + gesturesForTouch.length = 0;// release for GC } diff --git a/src/org/gestouch/gestures/Gesture.as b/src/org/gestouch/gestures/Gesture.as index 2772cb8..261f440 100644 --- a/src/org/gestouch/gestures/Gesture.as +++ b/src/org/gestouch/gestures/Gesture.as @@ -407,6 +407,14 @@ package org.gestouch.gestures } + /** + * + */ + protected function onTouchCancel(touch:Touch):void + { + } + + protected function setState(newState:GestureState):Boolean { if (_state == newState && _state == GestureState.CHANGED) @@ -576,6 +584,27 @@ package org.gestouch.gestures } + gestouch_internal function touchCancelHandler(touch:Touch):void + { + delete _touchesMap[touch.id]; + _touchesCount--; + + onTouchCancel(touch); + + if (!state.isEndState) + { + if (state == GestureState.BEGAN || state == GestureState.CHANGED) + { + setState(GestureState.CANCELLED); + } + else + { + setState(GestureState.FAILED); + } + } + } + + protected function gestureToFail_stateChangeHandler(event:GestureStateEvent):void { if (!_pendingRecognizedState || state != GestureState.POSSIBLE)