/// <summary> /// Get the listener instance. If the listener object does not exist, create one and add it to the list. /// All same gestures share one gesture listener. /// </summary> /// <param name="listenerType"></param> /// <returns></returns> internal GestureListener GetListener(Type listenerType) { if (!list.Keys.Contains(listenerType)) { GestureListener listener = null; if (listenerType == typeof(SortingListener)) { listener = new SortingListener(gestureListenerController); } else if (listenerType == typeof(DeletingBoxListener)) { listener = new DeletingBoxListener(gestureListenerController); } list.Add(listenerType, listener); } return(list[listenerType]); }
/// <summary> /// Detect the sorting gesture (Drag and drop the card to the sorting box). /// The touches in the sorting gesture will be removed from the touchList /// </summary> /// <param name="touchList"></param> /// <returns></returns> internal static async Task Detect(List <Touch> touchList, CentralControllers controllers) { List <Touch> usedTouches = new List <Touch>(); SortingGesture gesture = null; foreach (Touch touch in touchList) { if (touch.Type == typeof(Card) && !usedTouches.Contains(touch)) { Card card = touch.Sender as Card; SortingBox[] boxes = controllers.SortingBoxController.GetAllSortingBoxes(); foreach (SortingBox box in boxes) { bool isIntersect = await box.IsIntersected(card.Position); if (isIntersect) { foreach (Touch otherTouches in touchList) { if (touch.Sender == otherTouches.Sender && !usedTouches.Contains(otherTouches)) { usedTouches.Add(otherTouches); } } gesture = new SortingGesture(controllers.GestureController); gesture.AssociatedTouches = usedTouches; gesture.AssociatedObjects = new List <object>() { card, box }; gesture.AssociatedObjectTypes = new List <Type>() { typeof(Card), typeof(SortingBox) }; SortingListener listener = controllers.ListenerController.GetListener(typeof(SortingListener)) as SortingListener; RegisterListener(gesture, listener);// Register the gesture and add the gesture to the gesture list. } } } } foreach (Touch touch in usedTouches) { touchList.Remove(touch); } }