protected override void OnAttached() { isCanTouch = Touch.GetIsEnabled(Element); commandStartTap = Touch.GetStartTap(Element); commandFinishTap = Touch.GetFinishTap(Element); commandTap = Touch.GetTap(Element); commandLongTap = Touch.GetLongTap(Element); longTapLatency = Touch.GetLongTapLatency(Element); gestureTap = new GestureTouchSam(OnTap); gestureTap.MinimumPressDuration = 0; gestureTap.ShouldReceiveTouch += (UIGestureRecognizer g, UITouch t) => { return(true); }; gestureTap.ShouldRecognizeSimultaneously += (UIGestureRecognizer g, UIGestureRecognizer t) => { return(true); }; if (commandLongTap != null) { TimerInit(); } View.UserInteractionEnabled = true; View.AddGestureRecognizer(gestureTap); UpdateEffectColor(); }
private void UpdateLongTapLatency() { if (timer == null) { return; } timer.Interval = Touch.GetLongTapLatency(Element); }
private void UpdateLongTapCommand() { var command = Touch.GetLongTap(Element); TimerDispose(); if (command != null) { timer = new System.Timers.Timer(); timer.Elapsed += OnTimerEvent; timer.Interval = Touch.GetLongTapLatency(Element); timer.AutoReset = false; } }
protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e) { base.OnElementPropertyChanged(e); if (e.PropertyName == Touch.IsEnabledProperty.PropertyName) { isCanTouch = Touch.GetIsEnabled(Element); } else if (e.PropertyName == Touch.ColorProperty.PropertyName) { UpdateEffectColor(); } else if (e.PropertyName == Touch.TapProperty.PropertyName) { commandTap = Touch.GetTap(Element); } else if (e.PropertyName == Touch.StartTapProperty.PropertyName) { commandStartTap = Touch.GetStartTap(Element); } else if (e.PropertyName == Touch.FinishTapProperty.PropertyName) { commandFinishTap = Touch.GetFinishTap(Element); } else if (e.PropertyName == Touch.LongTapProperty.PropertyName) { commandLongTap = Touch.GetLongTap(Element); if (commandLongTap == null) { TimerDispose(); } else { TimerInit(); } } else if (e.PropertyName == Touch.LongTapLatencyProperty.PropertyName) { longTapLatency = Touch.GetLongTapLatency(Element); } }
private void OnTouch(object sender, View.TouchEventArgs args) { if (!isEnabled) { return; } //var x = args.Event.GetX(); //var y = args.Event.GetY(); //Console.Out.WriteLine($"x: {x}; y: {y} (action: {args.Event.Action.ToString()})"); motion = args.Event; if (args.Event.Action == MotionEventActions.Down) { View.PlaySoundEffect(SoundEffects.Click); // DOWN if (EnableRipple) { ForceStartRipple(args.Event.GetX(), args.Event.GetY()); } else { StartAnimation(); } if (Touch.GetLongTap(Element) != null) { if (timer == null) { timer = new System.Timers.Timer(); timer.Elapsed += OnTimerEvent; } timer.Interval = Touch.GetLongTapLatency(Element); timer.AutoReset = false; timer.Start(); } } else if (args.Event.Action == MotionEventActions.Up || args.Event.Action == MotionEventActions.Cancel || args.Event.Action == MotionEventActions.Outside) { args.Handled = true; // UP if (IsDisposed) { return; } if (EnableRipple) { ForceEndRipple(); } else { TapAnimation(250, alpha, 0); } if (args.Event.Action == MotionEventActions.Up && IsViewInBounds((int)args.Event.RawX, (int)args.Event.RawY)) { if (Touch.GetLongTap(Element) != null) { if (timer == null) { timer = new System.Timers.Timer(); timer.Elapsed += OnTimerEvent; } if (timer.Enabled) { SelectHandler(); ClickHandler(); } } else { SelectHandler(); ClickHandler(); } } timer?.Stop(); } }