/// <summary>
        /// Called when a touch gesture begins.
        /// </summary>
        /// <param name="touches">The touches.</param>
        /// <param name="evt">The event arguments.</param>
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            base.TouchesBegan(touches, evt);

            if (this.activeTouches.Count >= 2)
            {
                // we already have two touches
                return;
            }

            // Grab 1-2 touches to track
            var newTouches = touches.ToArray <UITouch>();
            var firstTouch = !this.activeTouches.Any();

            this.activeTouches.AddRange(newTouches.Take(2 - this.activeTouches.Count));

            if (firstTouch)
            {
                // HandleTouchStarted initializes the entire multitouch gesture,
                // with the first touch used for panning.
                this.TouchEventArgs = this.activeTouches.First().ToTouchEventArgs(this.View);
            }

            this.CalculateStartingDistance();
        }
        /// <summary>
        /// Called when a touch gesture ends.
        /// </summary>
        /// <param name="touches">The touches.</param>
        /// <param name="evt">The event arguments.</param>
        public override void TouchesEnded(NSSet touches, UIEvent evt)
        {
            base.TouchesEnded(touches, evt);

            // We already have the only two touches we care about, so ignore the params
            var secondTouch = this.activeTouches.ElementAtOrDefault(1);

            if (secondTouch != null && secondTouch.Phase == UITouchPhase.Ended)
            {
                this.activeTouches.Remove(secondTouch);
            }

            var firstTouch = this.activeTouches.FirstOrDefault();

            if (firstTouch != null && firstTouch.Phase == UITouchPhase.Ended)
            {
                this.activeTouches.Remove(firstTouch);

                if (!this.activeTouches.Any())
                {
                    this.TouchEventArgs = firstTouch.ToTouchEventArgs(this.View);

                    if (this.State == UIGestureRecognizerState.Possible)
                    {
                        this.State = UIGestureRecognizerState.Failed;
                    }
                    else
                    {
                        this.State = UIGestureRecognizerState.Ended;
                    }
                }
            }
        }
        /// <summary>
        /// Occurs when a touch delta event is handled.
        /// </summary>
        /// <param name="e">The <see cref="OxyPlot.OxyTouchEventArgs" /> instance containing the event data.</param>
        public override void Delta(OxyTouchEventArgs e)
        {
            base.Delta(e);

            // This is touch, we want to hide the tracker because the user is probably panning / zooming now
            this.PlotView.HideTracker();
        }
        /// <summary>
        /// Occurs when an input device begins a manipulation on the plot.
        /// </summary>
        /// <param name="e">The <see cref="OxyPlot.OxyTouchEventArgs" /> instance containing the event data.</param>
        public override void Started(OxyTouchEventArgs e)
        {
            base.Started(e);
            this.currentSeries = this.PlotView.ActualModel != null?this.PlotView.ActualModel.GetSeriesFromPoint(e.Position) : null;

            UpdateTracker(e.Position);
        }
Example #5
0
 private void Model_TouchStarted(object sender, OxyTouchEventArgs e)
 {
     PlotTouch.Panning = false;
     PlotTouch.Initial_Touch.X_Location = e.Position.X;
     PlotTouch.Initial_Touch.Start_Time = DateTime.UtcNow;
     int index = PlotTouch.Index;
 }
Example #6
0
 private void Ps_TouchCompleted(object sender, OxyTouchEventArgs e)
 {
     min       = 0;
     max       = 0;
     level     = 0;
     e.Handled = true;
     //Debug.WriteLine("calibration touch event...");
 }
        public override void Started(OxyTouchEventArgs e)
        {
            base.Started(e);
            this.startPos = e.Position;

            //Always handle event so we get Completed below which handles Tap
            e.Handled = true;
        }
Example #8
0
        /// <summary>
        /// Handles touch move events.
        /// </summary>
        /// <param name="e">The motion event arguments.</param>
        /// <returns><c>true</c> if the event was handled.</returns>
        private bool OnTouchMoveEvent(MotionEvent e)
        {
            var currentTouchPoints = e.GetTouchPoints(Scale);
            var args    = new OxyTouchEventArgs(currentTouchPoints, this.previousTouchPoints);
            var handled = this.ActualController.HandleTouchDelta(this, args);

            this.previousTouchPoints = currentTouchPoints;
            return(handled);
        }
Example #9
0
        private void Ls_TouchStarted(object sender, OxyTouchEventArgs e)
        {
            var ls           = (LineSeries)sender;
            var nierestPoint = ls.GetNearestPoint(e.Position, true);

            //var date = DateTimeAxis.ToDateTime(nierestPoint.DataPoint.X);

            DataPoint closest  = new DataPoint();
            double    distance = Double.MaxValue;

            foreach (var point in ls.Points)
            {
                var curDiff = (point.X - nierestPoint.DataPoint.X);
                if (curDiff < 0)
                {
                    curDiff = curDiff * -1;
                }
                if (curDiff < distance)
                {
                    distance = curDiff;
                    closest  = point;
                }
            }

            var hl = mController.GetHairLengthByPoint(closest);

            var labelAnnotation = new TextAnnotation
            {
                Text            = $"{hl.Day.ToString("dd MMMM yyyy")} - {String.Format("{0:0}", closest.Y)}cm",
                TextPosition    = new DataPoint(closest.X, closest.Y + 2),
                FontWeight      = 4,
                Background      = OxyColor.FromRgb(211, 211, 211),
                StrokeThickness = 0
            };


            mModel.Annotations.Clear();
            //mModel.Annotations.Add(labelAnnotation);
            mModel.Annotations.Add(SetSelectPoint(closest));
            mModel.InvalidatePlot(false);

            foreach (var image in mPictContainer.Children)
            {
                var hairImage = (HairLengthImage)image;
                if (hairImage.HairLength == hl)
                {
                    SelectImage(hairImage);
                }
                else
                {
                    hairImage.Deselect();
                }
            }

            FillData(hl);
        }
        /// <summary>
        /// Occurs when a manipulation is complete.
        /// </summary>
        /// <param name="e">The <see cref="OxyPlot.OxyTouchEventArgs" /> instance containing the event data.</param>
        public override void Completed(OxyTouchEventArgs e)
        {
            base.Completed(e);

            this.currentSeries = null;
            this.PlotView.HideTracker();
            if (this.PlotView.ActualModel != null)
            {
                this.PlotView.ActualModel.RaiseTrackerChanged(null);
            }
        }
Example #11
0
        /// <summary>
        /// Occurs when a manipulation is complete.
        /// </summary>
        /// <param name="e">The <see cref="OxyPlot.OxyTouchEventArgs" /> instance containing the event data.</param>
        public override void Completed(OxyTouchEventArgs e)
        {
            base.Completed(e);

            this.currentSeries = null;
            // this.PlotView.HideTracker();
            if (this.PlotView.ActualModel != null)
            {
                this.PlotView.ActualModel.RaiseTrackerChanged(null);
            }
        }
Example #12
0
        /// <summary>
        /// Converts <see cref="PointerRoutedEventArgs" /> to <see cref="OxyMouseEventArgs" /> for a touch event.
        /// </summary>
        /// <param name="e">The <see cref="ManipulationCompletedRoutedEventArgs" /> instance containing the event data.</param>
        /// <param name="relativeTo">The <see cref="UIElement" /> that the event is relative to.</param>
        /// <returns>A <see cref="OxyMouseEventArgs" /> containing the converted event arguments.</returns>
        public static OxyTouchEventArgs ToTouchEventArgs(this PointerRoutedEventArgs e, UIElement relativeTo)
        {
            var point = e.GetCurrentPoint(relativeTo);

            var eventArgs = new OxyTouchEventArgs
            {
                Position     = point.Position.ToScreenPoint(),
                ModifierKeys = e.GetModifierKeys(),
            };

            return(eventArgs);
        }
        /// <summary>
        /// Called when a touch gesture is moving.
        /// </summary>
        /// <param name="touches">The touches.</param>
        /// <param name="evt">The event arguments.</param>
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            base.TouchesMoved(touches, evt);

            if (this.activeTouches.Any(touch => touch.Phase == UITouchPhase.Moved))
            {
                // get current and previous location of the first touch point
                var t1  = this.activeTouches.First();
                var l1  = t1.LocationInView(this.View).ToScreenPoint();
                var pl1 = t1.Phase == UITouchPhase.Moved ? t1.PreviousLocationInView(this.View).ToScreenPoint() : l1;

                var l = l1;
                var t = l1 - pl1;
                var s = new ScreenVector(1, 1);

                if (this.activeTouches.Count > 1)
                {
                    // get current and previous location of the second touch point
                    var t2  = this.activeTouches.ElementAt(1);
                    var l2  = t2.LocationInView(this.View).ToScreenPoint();
                    var pl2 = t2.Phase == UITouchPhase.Moved ? t2.PreviousLocationInView(this.View).ToScreenPoint() : l2;

                    var d  = l1 - l2;
                    var pd = pl1 - pl2;

                    if (!this.KeepAspectRatioWhenPinching)
                    {
                        if (!this.AllowPinchPastZero)
                        {
                            // Don't allow fingers crossing in a zoom-out gesture to turn it back into a zoom-in gesture
                            d = this.PreventCross(d);
                        }

                        var scalex = this.CalculateScaleFactor(d.X, pd.X);
                        var scaley = this.CalculateScaleFactor(d.Y, pd.Y);
                        s = new ScreenVector(scalex, scaley);
                    }
                    else
                    {
                        var scale = pd.Length > 0 ? d.Length / pd.Length : 1;
                        s = new ScreenVector(scale, scale);
                    }
                }

                var e = new OxyTouchEventArgs {
                    Position = l, DeltaTranslation = t, DeltaScale = s
                };
                this.TouchEventArgs = e;
                this.State          = UIGestureRecognizerState.Changed;
            }
        }
        /// <summary>
        /// Invoked when an unhandled MouseUp routed event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs" /> that contains the event data. The event data reports that the mouse button was released.</param>
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            base.OnPointerReleased(e);
            if (e.Handled)
            {
                return;
            }

            e.Pointer.Capture(null);

            if (e.Pointer.Type == PointerType.Touch)
            {
                var position = e.GetPosition(this).ToScreenPoint();

                var touchEventArgs = new OxyTouchEventArgs()
                {
                    ModifierKeys     = e.KeyModifiers.ToModifierKeys(),
                    Position         = position,
                    DeltaTranslation = new ScreenVector(0, 0),
                    DeltaScale       = new ScreenVector(1, 1),
                };

                TouchPositions.Remove(e.Pointer.Id);

                if (TouchPositions.Count == 0)
                {
                    e.Handled = ActualController.HandleTouchCompleted(this, touchEventArgs);
                }
            }
            else
            {
                e.Handled = ActualController.HandleMouseUp(this, e.ToMouseReleasedEventArgs(this));

                // Open the context menu
                var p = e.GetPosition(this).ToScreenPoint();
                var d = p.DistanceTo(mouseDownPoint);

                if (ContextMenu != null)
                {
                    if (Math.Abs(d) < 1e-8 && e.InitialPressMouseButton == MouseButton.Right)
                    {
                        ContextMenu.DataContext = DataContext;
                        ContextMenu.IsVisible   = true;
                    }
                    else
                    {
                        ContextMenu.IsVisible = false;
                    }
                }
            }
        }
        public override void Completed(OxyTouchEventArgs e)
        {
            base.Completed(e);
            if (e.Position.DistanceTo(this.startPos) >= TAP_TOLERANCE)
            {
                return;
            }

            var results = PlotView.ActualModel.HitTest(new HitTestArguments(e.Position, HIT_TOLERANCE));

            if (this.tapCommand != null)
            {
                this.tapCommand.Execute(results);
            }
        }
Example #16
0
        /// <summary>
        /// Occurs when a touch delta event is handled.
        /// </summary>
        /// <param name="e">The <see cref="OxyPlot.OxyTouchEventArgs" /> instance containing the event data.</param>
        public override void Delta(OxyTouchEventArgs e)
        {
            base.Delta(e);

            var v = (startPoint - e.Position);

            if (v.Value.Length > 10)
            {
                if (updateTrackerTimer != null && updateTrackerTimer.Enabled)
                {
                    updateTrackerTimer.Stop();
                    updateTrackerTimer = null;
                }

                // This is touch, we want to hide the tracker because the user is probably panning / zooming now
                this.PlotView.HideTracker();
            }
        }
Example #17
0
        /// <summary>
        /// Called when a touch gesture is moving.
        /// </summary>
        /// <param name="touches">The touches.</param>
        /// <param name="evt">The event arguments.</param>
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            // it seems to be easier to handle touch events here than using UIPanGesturRecognizer and UIPinchGestureRecognizer
            base.TouchesMoved(touches, evt);

            // convert the touch points to an array
            var ta = touches.ToArray <UITouch>();

            if (ta.Length > 0)
            {
                // get current and previous location of the first touch point
                var t1  = ta[0];
                var l1  = t1.LocationInView(this).ToScreenPoint();
                var pl1 = t1.PreviousLocationInView(this).ToScreenPoint();
                var l   = l1;
                var t   = l1 - pl1;
                var s   = new ScreenVector(1, 1);
                if (ta.Length > 1)
                {
                    // get current and previous location of the second touch point
                    var t2  = ta[1];
                    var l2  = t2.LocationInView(this).ToScreenPoint();
                    var pl2 = t2.PreviousLocationInView(this).ToScreenPoint();
                    var d   = l1 - l2;
                    var pd  = pl1 - pl2;
                    if (!this.KeepAspectRatioWhenPinching)
                    {
                        var scalex = System.Math.Abs(pd.X) > 0 ? System.Math.Abs(d.X / pd.X) : 1;
                        var scaley = System.Math.Abs(pd.Y) > 0 ? System.Math.Abs(d.Y / pd.Y) : 1;
                        s = new ScreenVector(scalex, scaley);
                    }
                    else
                    {
                        var scale = pd.Length > 0 ? d.Length / pd.Length : 1;
                        s = new ScreenVector(scale, scale);
                    }
                }

                var e = new OxyTouchEventArgs {
                    Position = l, DeltaTranslation = t, DeltaScale = s
                };
                this.ActualController.HandleTouchDelta(this, e);
            }
        }
        /// <summary>
        /// Invoked when an unhandled MouseDown attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs" /> that contains the event data. This event data reports details about the mouse button that was pressed and the handled state.</param>
        protected override void OnPointerPressed(PointerPressedEventArgs e)
        {
            base.OnPointerPressed(e);
            if (e.Handled)
            {
                return;
            }

            Focus();
            e.Pointer.Capture(this);

            if (e.Pointer.Type == PointerType.Touch)
            {
                var position = e.GetPosition(this).ToScreenPoint();

                var touchEventArgs = new OxyTouchEventArgs()
                {
                    ModifierKeys     = e.KeyModifiers.ToModifierKeys(),
                    Position         = position,
                    DeltaTranslation = new ScreenVector(0, 0),
                    DeltaScale       = new ScreenVector(1, 1),
                };

                TouchPositions[e.Pointer.Id] = position;

                if (TouchPositions.Count == 1)
                {
                    e.Handled = ActualController.HandleTouchStarted(this, touchEventArgs);
                }
            }
            else
            {
                // store the mouse down point, check it when mouse button is released to determine if the context menu should be shown
                mouseDownPoint = e.GetPosition(this).ToScreenPoint();

                e.Handled = ActualController.HandleMouseDown(this, e.ToMouseDownEventArgs(this));
            }
        }
        /// <summary>
        /// Called when a touch gesture is cancelled.
        /// </summary>
        /// <param name="touches">The touches.</param>
        /// <param name="evt">The event arguments.</param>
        public override void TouchesCancelled(NSSet touches, UIEvent evt)
        {
            base.TouchesCancelled(touches, evt);

            // I'm not sure if it's actually possible for one touch to be canceled without
            // both being canceled, but just to be safe let's stay consistent with TouchesEnded
            // and handle that scenario.

            // We already have the only two touches we care about, so ignore the params
            var secondTouch = this.activeTouches.ElementAtOrDefault(1);

            if (secondTouch != null && secondTouch.Phase == UITouchPhase.Cancelled)
            {
                this.activeTouches.Remove(secondTouch);
            }

            var firstTouch = this.activeTouches.FirstOrDefault();

            if (firstTouch != null && firstTouch.Phase == UITouchPhase.Cancelled)
            {
                this.activeTouches.Remove(firstTouch);

                if (!this.activeTouches.Any())
                {
                    this.TouchEventArgs = firstTouch.ToTouchEventArgs(this.View);

                    if (this.State == UIGestureRecognizerState.Possible)
                    {
                        this.State = UIGestureRecognizerState.Failed;
                    }
                    else
                    {
                        this.State = UIGestureRecognizerState.Cancelled;
                    }
                }
            }
        }
        /// <summary>
        /// Invoked when an unhandled MouseMove attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Input.MouseEventArgs" /> that contains the event data.</param>
        protected override void OnPointerMoved(PointerEventArgs e)
        {
            base.OnPointerMoved(e);
            if (e.Handled)
            {
                return;
            }

            if (e.Pointer.Type == PointerType.Touch)
            {
                var point          = e.GetPosition(this).ToScreenPoint();
                var oldTouchPoints = TouchPositions.Values.ToArray();
                TouchPositions[e.Pointer.Id] = point;
                var newTouchPoints = TouchPositions.Values.ToArray();

                var touchEventArgs = new OxyTouchEventArgs(newTouchPoints, oldTouchPoints);

                e.Handled = ActualController.HandleTouchDelta(this, touchEventArgs);
            }
            else
            {
                e.Handled = ActualController.HandleMouseMove(this, e.ToMouseEventArgs(this));
            }
        }
        /// <summary>
        /// Occurs when an input device begins a manipulation on the plot.
        /// </summary>
        /// <param name="e">The <see cref="OxyPlot.OxyTouchEventArgs" /> instance containing the event data.</param>
        public override void Started(OxyTouchEventArgs e)
        {
            base.Started(e);
            this.currentSeries = this.PlotView.ActualModel != null ? this.PlotView.ActualModel.GetSeriesFromPoint(e.Position) : null;

            UpdateTracker(e.Position);
        }
        /// <summary>
        /// Occurs when a touch delta event is handled.
        /// </summary>
        /// <param name="e">The <see cref="OxyPlot.OxyTouchEventArgs" /> instance containing the event data.</param>
        public override void Delta(OxyTouchEventArgs e)
        {
            base.Delta(e);

            // This is touch, we want to hide the tracker because the user is probably panning / zooming now
            this.PlotView.HideTracker();
        }
        /// <summary>
        /// Converts <see cref="PointerRoutedEventArgs" /> to <see cref="OxyMouseEventArgs" /> for a touch event.
        /// </summary>
        /// <param name="e">The <see cref="ManipulationCompletedRoutedEventArgs" /> instance containing the event data.</param>
        /// <param name="relativeTo">The <see cref="UIElement" /> that the event is relative to.</param>
        /// <returns>A <see cref="OxyMouseEventArgs" /> containing the converted event arguments.</returns>
        public static OxyTouchEventArgs ToTouchEventArgs(this PointerRoutedEventArgs e, UIElement relativeTo)
        {
            var point = e.GetCurrentPoint(relativeTo);

            var eventArgs = new OxyTouchEventArgs
            {
                Position = point.Position.ToScreenPoint(),
                ModifierKeys = e.GetModifierKeys(),
            };

            return eventArgs;
        }
 private void PieSeries_TouchStarted(object sender, OxyTouchEventArgs e)
 {
     Toast.MakeText(ApplicationContext, "Clicked", ToastLength.Long).Show();
 }