/// <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 sortingbox deleting gesture (Drag and drop the box to the delete box on the menubar). /// 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>(); DeletingBoxGesture gesture = null; foreach (Touch touch in touchList) { if (touch.Type == typeof(SortingBox) && !usedTouches.Contains(touch)) { SortingBox box = touch.Sender as SortingBox; MenuBar[] bars = controllers.MenuLayerController.GetAllMenuBars(); foreach (MenuBar bar in bars) { bool isIntersect = await bar.IsIntersectWithDelete(box.Position); if (isIntersect) { foreach (Touch otherTouches in touchList) { if (touch.Sender == otherTouches.Sender && !usedTouches.Contains(otherTouches)) { usedTouches.Add(otherTouches); } } gesture = new DeletingBoxGesture(controllers.GestureController); gesture.AssociatedTouches = usedTouches; gesture.AssociatedObjects = new List <object>() { box, bar }; gesture.AssociatedObjectTypes = new List <Type>() { typeof(SortingBox), typeof(MenuBar) }; DeletingBoxListener listener = controllers.ListenerController.GetListener(typeof(DeletingBoxListener)) as DeletingBoxListener; RegisterListener(gesture, listener);// Register the gesture and add the gesture to the gesture list. } } } } foreach (Touch touch in usedTouches) { touchList.Remove(touch); } }