Example #1
0
        /// <summary>
        /// This is a good enough approximation of updating the Rating based on where the user clicked. In reality this could be just a bit more accurate, but for now it's sufficient for my needs.
        /// </summary>
        private void UpdateRating(VisualElement view, BaseGestureEventArgs eventArgs)
        {
            double paddingLeft = 0, paddingRight = 0;
            var    layout = view as Layout;

            if (layout != null)
            {
                paddingLeft  = layout.Padding.Left;
                paddingRight = layout.Padding.Right;
            }
            // First 2 IF statements: handle the cases where the user panned way out to the right or left (outside of this view, causing the percentX to really be <0 or >1
            if (eventArgs.Center.X < paddingLeft)
            {
                Monitor.Debug($"Setting rating to 0 in respond to CenterX={eventArgs.Center.X} and Spacing={Spacing}");
                Rating = 0;
            }
            else if (eventArgs.Center.X > view.Width - paddingRight)
            {
                Monitor.Debug($"Setting rating to 10 in respond to CenterX={eventArgs.Center.X} and pacing={Spacing} and Width={view.Width}");
                Rating = 10;
            }
            else
            {
                var remainingWidth = view.Width - paddingLeft - paddingRight;
                var adjustedX      = eventArgs.Center.X - paddingLeft;
                var percentX       = adjustedX / remainingWidth;
                // normal case
                //var percentX = (eventArgs.Center.X - Padding.Left) / (view.Width - Padding.Left - Padding.Right);
                Rating = (byte)Math.Round(percentX * 10);
                Monitor.Debug($"Panned, Set Rating = {Rating} in response to {percentX}% CenterX={eventArgs.Center.X} Width={view.Width}");
            }
        }
Example #2
0
        public iOSPanEventArgs(UIPanGestureRecognizer gr, BaseGestureEventArgs previous)
        {
            Cancelled       = (gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed);
            ElementPosition = gr.View.BoundsInFormsCoord();
            ElementTouches  = iOSEventArgsHelper.GetTouches(gr, gr.View);
            WindowTouches   = iOSEventArgsHelper.GetTouches(gr, null);

            CalculateDistances(previous);
            Velocity = GetVelocity(gr);
        }
        public static Point[] GetTouches(MotionEvent.PointerCoords[] coords, BaseGestureEventArgs previous, Android.Views.View view, int[] startLocation)
        {
            int pointerCount = coords.Length;

            if (pointerCount < 2 && previous != null)
            {
                System.Diagnostics.Debug.WriteLine("\tPointerCount < requiredTouches");
                return(previous.Touches);
            }
            return(AndroidEventArgsHelper.GetTouches(coords, view, startLocation));
        }
Example #4
0
 public AndroidPanEventArgs(MotionEvent previous, MotionEvent current, BaseGestureEventArgs prevArgs, Android.Views.View view, Listener listener)
 {
     Listener        = listener;
     Cancelled       = (current.Action == MotionEventActions.Cancel);
     ElementPosition = VisualElementExtensions.BoundsInWindowCoord(listener.Element);
     ElementTouches  = AndroidEventArgsHelper.GetTouches(current, view, listener);
     //WindowTouches = AndroidEventArgsHelper.GetTouches(current, view, null);
     WindowTouches = AndroidEventArgsHelper.GetRawTouches(current);
     CalculateDistances(prevArgs);
     Velocity = GetVelocity(previous, current);
 }
        public static Point[] GetTouches(MotionEvent.PointerCoords[] coords, BaseGestureEventArgs previous, Android.Views.View view, Listener listener)
        {
            int pointerCount = coords.Length;

            if (pointerCount < 2 && previous != null)
            {
                System.Diagnostics.Debug.WriteLine("\tPointerCount < requiredTouches");
                return(previous.ElementTouches);
            }
            return(GetTouches(coords, view, listener));
        }
 private void AddTouches(StringBuilder sb, BaseGestureEventArgs e)
 {
     sb.Append(", Touches: ");
     if (e.Touches != null && e.Touches.Length > 0)
     {
         sb.Append(string.Join(", ", e.Touches.Select(t => $"{t.X:F}/{t.Y:F}")));
     }
     else
     {
         sb.Append("empty");
     }
 }
Example #7
0
        private void PrintBaseGestureEventArgs(BaseGestureEventArgs e)
        {
#if DEBUG
            for (int i = 0; i < e.TouchBlobs.Count; i++)
            {
                BlobInfo bi = e.TouchBlobs[i];

                //AutoDebugger.WriteLine(bi.ToString());
            }
            //AutoDebugger.WriteLine("DebugGestureHandler: " + e.ToString());
#endif
        }
Example #8
0
        public void ShowTouches(BaseGestureEventArgs e, Color color)
        {
            foreach (var box in _touchIndicators)
            {
                relativeLayout.Children.Remove(box);
            }

            for (var i = 0; i < e.WindowTouches.Length; i++)
            {
                ShowBox(e.WindowTouches[i], color);
            }
        }
Example #9
0
        public static Xamarin.Forms.Point[] GetTouches(this UIGestureRecognizer gestureRecognizer, UIView view, int requiredTouches, BaseGestureEventArgs previous)
        {
            nint numberOfTouches = gestureRecognizer.NumberOfTouches;

            if (numberOfTouches < requiredTouches && previous != null)
            {
                return(view == null
                    ? previous.WindowTouches
                    : previous.ElementTouches);
            }
            return(iOSEventArgsHelper.GetTouches(gestureRecognizer, view));
        }
 protected string GetElementName(BaseGestureEventArgs e)
 {
     return(e.Sender.GetType().Name + " " + ((Element)e.Sender).Id);
 }
		protected string GetElementName(BaseGestureEventArgs e)
		{
			return e.Sender.GetType().Name + " " + ((Element)e.Sender).Id;
		}
        public static Xamarin.Forms.Point[] GetTouches(UIGestureRecognizer gestureRecognizer, int requiredTouches, BaseGestureEventArgs previous, CGPoint locationAtStart)
        {
            nint numberOfTouches = gestureRecognizer.NumberOfTouches;

            if (numberOfTouches < requiredTouches && previous != null)
            {
                return(previous.Touches);
            }
            return(iOSEventArgsHelper.GetTouches(gestureRecognizer, locationAtStart));
        }