示例#1
0
 /// <summary>
 /// Excutes the asyncronous action assoicated with the gesture
 /// </summary>
 /// <param name="result">The final <see cref="GestureResult"/></param>
 /// <param name="param">The Gesture Paramater</param>
 public async void ExecuteGesture(GestureResult result, object param)
 {
     if (_asyncExecute != null)
     {
         await Execute(result, param);
     }
 }
示例#2
0
 /// <summary>
 /// Excutes the action assoicated with the gesture
 /// </summary>
 /// <param name="result">The final <see cref="GestureResult"/></param>
 /// <param name="param">The Gesture Paramater cast to T before calling the action</param>
 public void ExecuteGesture(GestureResult result, object param)
 {
     if (_execute != null)
     {
         _execute(result, param as T);
     }
 }
 private void OnGesture(GestureResult gr, object obj)
 {
     GestureCount++;
     switch (gr.GestureType)
     {
         case GestureType.SingleTap:
             Gestures.Insert(0, string.Format("Gesture:{0} param is {1}", gr.GestureType, obj));
             break;
         case GestureType.DoubleTap:
             Gestures.Insert(0, string.Format("Gesture:{0} param is {1}", gr.GestureType, obj));
             break;
         case GestureType.LongPress:
             Gestures.Insert(0, string.Format("Gesture:{0} param is {1}", gr.GestureType, obj));
             break;
         case GestureType.Swipe:
             Gestures.Insert(0,string.Format("Gesture:{0} Direction: {1} param is {2}",gr.GestureType,gr.Direction,obj));
             break;
     }            
 }
示例#4
0
 /// <summary>
 /// Tests to see if a gesture's action can execute
 /// </summary>
 /// <param name="result">The final <see cref="GestureResult"/></param>
 /// <param name="param">The Gesture Paramater cast to T before calling the function</param>
 /// <returns>true if the action can execute,false othewise</returns>
 public bool CanExecuteGesture(GestureResult result, object param)
 {
     return(_canexecute == null || _canexecute(result, param as T));
 }
示例#5
0
 /// <summary>
 /// Virtual aync funciton that the user can override to provide
 /// any custom functionality required.
 /// </summary>
 /// <param name="gesture"><see cref="GestureResult"/></param>
 /// <param name="annoyingbaseobjectthing"></param>
 /// <returns></returns>
 protected virtual async Task Execute(GestureResult gesture, object annoyingbaseobjectthing)
 {
     await _asyncExecute(gesture, annoyingbaseobjectthing as T);
 }
示例#6
0
 /// <summary>
 /// Tests to see if a gesture's action can execute
 /// </summary>
 /// <param name="result">The final <see cref="GestureResult"/></param>
 /// <param name="annoyingbaseobjectthing">The Gesture Paramater</param>
 /// <returns>true if the action can execute,false othewise</returns>
 public bool CanExecuteGesture(GestureResult result, object annoyingbaseobjectthing)
 {
     return(_canexecute == null || _canexecute(result, annoyingbaseobjectthing as T));
 }
        private void SatisfyInterest(GestureInterest gi,GestureResult args)
        {
            var commandparam = gi.GestureParameter??args.StartView.BindingContext??BindingContext;
            if (gi.GestureCommand != null && gi.GestureCommand.CanExecuteGesture(args, gi.GestureParameter))
                gi.GestureCommand.ExecuteGesture(args,commandparam);
            var handler = GestureRecognized;
            if (handler != null)
            {
                handler(args.StartView, args);
            }

        }
        /// <summary>
        /// Used by <see cref="GesturesContentView"/>.
        /// </summary>
        /// <param name="gesture">The resulting gesture<see cref="GestureResult"/></param>
        /// <returns>True if the gesture was handled,false otherwise</returns>
        internal bool ProcessGesture(GestureResult gesture)
        {
            //Check the view stack first
            if (ExcludeChildren && gesture.ViewStack != null && gesture.ViewStack.Count != 0 && _viewInterests.All(x => x.View != gesture.ViewStack[0])) return false;//The innermost (source) is not an actual interested view
            var interestedview = InterestedView(gesture.Origin);
            if (interestedview == null) return false;
            gesture.StartView = interestedview.View;

            //Check for perfect matches first
            var interest = interestedview.Interests.Where(x => x.GestureType == gesture.GestureType &&
                                                           (
                                                               (x.Direction & Directionality.HorizontalMask) == (gesture.Direction & Directionality.HorizontalMask) &&
                                                               (x.Direction & Directionality.VerticalMask) == (gesture.Direction & Directionality.VerticalMask))
                                                            ).ToList();

            if (!interest.Any())
            {
                //Check for match on the dominant axis
                var horizontaldirection = gesture.HorizontalDistance < gesture.VerticalDistance
                    ? Directionality.None :gesture.Direction & Directionality.HorizontalMask;

                var verticaldirection = gesture.HorizontalDistance < gesture.VerticalDistance
                                              ? gesture.Direction & Directionality.VerticalMask
                                              : Directionality.None;

                //Swap in the new direction so the user knows what the final match was
                gesture.Direction = horizontaldirection | verticaldirection;

                interest =interestedview.Interests.Where(x =>x.GestureType == gesture.GestureType &&
                                                                              (x.Direction & Directionality.HorizontalMask)== horizontaldirection &&
                                                                              (x.Direction & Directionality.VerticalMask) == verticaldirection).ToList();
            }
            //Winnow out the swipe gestures to match on either a perfect direction match (ie Up,Left) or based on the dominant axis


            //Is there one or more interest int this gesture?
            if (!interest.Any()) return false;
            var final = interest.First();
            //Finish setting up our gestureresult
            gesture.Origin=new Point(Math.Max(gesture.Origin.X-interestedview.View.X,0),Math.Max(gesture.Origin.Y-interestedview.View.Y,0));
            SatisfyInterest(final,gesture);
            return true;
        }