public void RegisterGesture(IGesture gesture,GestureEventHandler callback)
 {
     if (!_registeredGestures.ContainsKey(gesture))
     {
         _registeredGestures.Add(gesture,callback);
     }
 }
Example #2
0
        internal static void RegisterHandler(Type grType, GRConfiguration grConf, string ev, GestureEventHandler handler)
        {
            System.Diagnostics.Debug.Assert(handler.Target is IGestureListener,
                "Attempting to register a handler for an instance of class " +
                handler.Target.GetType().ToString() +
                " which doesn't implement the interface IGestureListener.");

            int priorityNumber;
            if (!s_priorityNumbersTable.ContainsKeys(grType, grConf))
            {
                priorityNumber = 0;
                s_priorityNumbersTable[grType, grConf] = priorityNumber;
            }
            else
                priorityNumber = s_priorityNumbersTable[grType, grConf];

            RegistrationInfo grInfo = new RegistrationInfo(grType, grConf, priorityNumber, ev, handler);

            if (grType.IsSubclassOf(typeof(GlobalGestureRecognizer)))
            {
                s_ggrRegistry.Add(grInfo);

                // update subscribed GRManagers
                foreach (GroupGRManager grManager in s_subscribedGRManagers)
                    grManager.UpdateGGR(grInfo);
            }
            else
            {
                s_lgrRegistry.Add(grInfo);

                // TODO: if LGRs are associated to the group's FINAL target list then dynamic update should be done
            }
        }
Example #3
0
        public static void Validate(string gestureName, string dataKey, GestureEventHandler gestureDetected = null, TouchToolkit.Framework.Components.TouchInputRecorder.GesturePlaybackCompleted playbackCompleted = null)
        {
            if (!_isInitialized)
                throw new FrameworkException("You must initialize the framework first!");

            _storage.GetGesture(_projectname, dataKey, (projName, gesName, data, error) =>
                {
                    // Callback on data receive from storage

                    if (error != null)
                    {
                        // Failed to retrieve data from storage
                        if (gestureDetected != null)
                        {
                            GestureEventArgs e = new GestureEventArgs();
                            e.Error = error;

                            gestureDetected(_layoutRoot, e);
                        }
                    }
                    else
                    {
                        // Subscribe to the specified gesture event
                        GestureFramework.EventManager.AddEvent(_layoutRoot, gestureName, gestureDetected);

                        // Playback the user interaction via virtual touch provider
                        _recorder.RunGesture(data, () =>
                        {
                            GestureFramework.EventManager.RemoveEvent(_layoutRoot, gestureName);
                            playbackCompleted();
                        });

                    }
                });
        }
Example #4
0
 /// <summary>
 /// Registers a handler for a gesture event. The GR will be configured with the given configuration.
 /// </summary>
 /// <param name="grType">Type of the gesture recognizer.</param>
 /// <param name="grConf">The GR's configuration.</param>
 /// <param name="e">The event as string.</param>
 /// <param name="handler">The listener's function that will be called when the event is raised.</param>
 public static void RegisterHandler(Type grType, GRConfiguration grConf, string ev, GestureEventHandler handler)
 {
     lock (s_lock)
     {
         GestureEventRegistry.RegisterHandler(grType, grConf, ev, handler);
     }
 }
Example #5
0
 public static void RemoveHoldGestureHandler(DependencyObject d, GestureEventHandler handler)
 {
   UIElement element = d as UIElement;
   if (element != null)
   {
     element.RemoveHandler(HoldGestureEvent, handler);
   }
 }
    private void OnGesture(GestureEventArgs e)
    {
        GestureEventHandler handler = GestureEvent;

        if (handler != null)
        {
            handler(this, e);
        }
    }
Example #7
0
        /// <summary>
        /// Adds gesture event to specified UI element
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="gestureName"></param>
        /// <param name="handler"></param>
        public void AddEvent(UIElement uiElement, string gestureName, GestureEventHandler handler)
        {
            Gesture g = GestureLanguageProcessor.GetGesture(gestureName);

            if (g != null)
                AddEvent(uiElement, g, handler, g.ValidationBlocks.Count - 1);
            else
                throw new FrameworkException(string.Format("The gesture \"{0}\" does not exists in current context", gestureName));
        }
Example #8
0
        /// <summary>
        /// Adds a handler for the DoubleTapGesture attached event
        /// </summary>
        /// <param name="element">UIElement or ContentElement that listens to the event</param>
        /// <param name="handler">Event handler to be added</param>
        public static void AddDoubleTapGestureHandler(DependencyObject d, GestureEventHandler handler)
        {
            UIElement element = d as UIElement;

            if (element != null)
            {
                element.AddHandler(DoubleTapGestureEvent, handler);
            }
        }
Example #9
0
        public static void RemoveHoldGestureHandler(DependencyObject d, GestureEventHandler handler)
        {
            UIElement element = d as UIElement;

            if (element != null)
            {
                element.RemoveHandler(HoldGestureEvent, handler);
            }
        }
Example #10
0
        /// <summary>
        /// Adds the gesture event request to the end of the existing requests collection
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="gestureName"></param>
        /// <param name="handler"></param>
        public static void Add(UIElement uiElement, Gesture gesture, GestureEventHandler handler, int stepNo)
        {
            if (uiElement == null)
                throw new FrameworkException("UIElement can not be null!");

            // Add new record in the list
            eventRequests.Add(new EventRequest()
            {
                UIElement = uiElement,
                Gesture = gesture,
                EventHandler = handler,
                StepNo = stepNo
            });
        }
Example #11
0
 /// <summary>
 /// Registers a handler for a gesture event. The GR will be will be configured by default.
 /// </summary>
 /// <param name="grType">Type of the gesture recognizer.</param>
 /// <param name="e">The event as string.</param>
 /// <param name="handler">The listener's function that will be called when the event is raised.</param>
 public static void RegisterHandler(Type grType, string ev, GestureEventHandler handler)
 {
     RegisterHandler(grType, GestureRecognizer.DefaultConfiguration, ev, handler);
 }
Example #12
0
        internal static void UnregisterHandler(Type grType, GRConfiguration grConf, string ev, GestureEventHandler handler)
        {
            List<RegistrationInfo> registry;
            if (grType.IsSubclassOf(typeof(GlobalGestureRecognizer)))
                registry = s_ggrRegistry;
            else
                registry = s_lgrRegistry;

            bool removed = registry.Remove(registry.Find(delegate(RegistrationInfo ggrInfo)
            {
                return
                    ggrInfo.GRType == grType &&
                    ggrInfo.GRConfiguration == grConf &&
                    ggrInfo.Event == ev &&
                    ggrInfo.Handler == handler;
            }));

            System.Diagnostics.Debug.WriteLineIf(!removed, "Warning: GRRegistry.UnregisterHandler did not find the handler to remove.");
        }
Example #13
0
 /// <summary>
 /// Adds a handler for the TapGesture attached event
 /// </summary>
 /// <param name="element">UIElement or ContentElement that listens to the event</param>
 /// <param name="handler">Event handler to be added</param>
 public static void AddTapGestureHandler(DependencyObject d, GestureEventHandler handler)
 {
   UIElement element = d as UIElement;
   if (element != null)
   {
     element.AddHandler(TapGestureEvent, handler);
   }
 }
 internal override sealed void AddHandler(string ev, GestureEventHandler handler)
 {
     GetEventInfo(ev).AddEventHandler(this, handler);
 }
Example #15
0
 private void AddEvent(UIElement uiElement, Gesture gesture, GestureEventHandler handler, int stepNo)
 {
     if (GestureFramework.IsInitialized)
     {
         EventRequestDirectory.Add(uiElement, gesture, handler, stepNo);
     }
     else
     {
         throw new FrameworkException("You need to initialize the framework first!. Call GestureEventManager.Initialize(...) at application startup.");
     }
 }
Example #16
0
 /// <summary>
 /// Register callback event for a specific step of a multi-step gesture on the specified UI element
 /// </summary>
 /// <param name="uiElement"></param>
 /// <param name="gestureName"></param>
 /// <param name="handler"></param>
 /// <param name="stepNo">The step no of a multi-step gesture definition</param>
 public void AddEvent(UIElement uiElement, string gestureName, GestureEventHandler handler, int stepNo)
 {
     Gesture g = GestureLanguageProcessor.GetGesture(gestureName);
     AddEvent(uiElement, g, handler, stepNo);
 }
Example #17
0
 internal abstract void AddHandler(string ev, GestureEventHandler handler);
Example #18
0
 /// <summary>
 /// Use this method to send events. If the GR is not armed (e.g. it's in competition
 /// with other GRs), events will be scheduled in a queue and raised as soon as the GR 
 /// will be armed. If the GR is already armed, events are raised immediately.
 /// </summary>
 /// <param name="ev">The event</param>
 /// <param name="args">The event's arguments</param>
 protected void AppendEvent(GestureEventHandler ev, GestureEventArgs args)
 {
     if (ev != null)
     {
         if (m_armed)
             ev(this, args);
         else
         {
             m_bufferedHandlers.Add((GestureEventHandler)ev.Clone());
             m_bufferedArgs.Add(args);
         }
     }
 }
Example #19
0
 void OnEnable()
 {
     Instance = this;
 }
Example #20
0
            private readonly int m_priorityNumber; // priority number of the GR

            #endregion Fields

            #region Constructors

            internal RegistrationInfo(Type grType, GRConfiguration grConf, int pn, string ev, GestureEventHandler handler)
            {
                m_grType = grType;
                m_grConf = grConf;
                m_priorityNumber = pn;
                m_event = ev;
                m_handler = handler;
            }
        internal override sealed void AddHandler(string ev, GestureEventHandler handler)
        {
            // Check if it's a default event
            bool isDefaultEvent = false;
            for (int i = 0; i < DefaultEvents.Length; i++)
            {
                if (DefaultEvents[i] == ev)
                {
                    isDefaultEvent = true;
                    break;
                }
            }

            EventInfo eventInfo = GetEventInfo(ev);
            object listener = handler.Target;

            if (isDefaultEvent)
                eventInfo.AddEventHandler(this, handler);
            else
            {
                if (!m_handlerTable.ContainsKeys(eventInfo, listener))
                    m_handlerTable[eventInfo, listener] = new List<GestureEventHandler>();
                m_handlerTable[eventInfo, listener].Add(handler);
            }
        }