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(); }
protected override void OnAttached() { if (Touch.GetLongTap(Element) != null) { timer = new System.Timers.Timer(); timer.Elapsed += OnTimerEvent; } isEnabled = Touch.GetIsEnabled(Element); View.Clickable = true; View.LongClickable = true; View.SoundEffectsEnabled = true; viewOverlay = new FrameLayout(Container.Context) { LayoutParameters = new ViewGroup.LayoutParams(-1, -1), Clickable = false, Focusable = false, }; Container.LayoutChange += ViewOnLayoutChange; if (EnableRipple) { viewOverlay.Background = CreateRipple(color); } SetEffectColor(); View.Touch += OnTouch; Container.AddView(viewOverlay); viewOverlay.BringToFront(); }
private void OnRightTapped() { var cmd = Touch.GetLongTap(Element); var param = Touch.GetLongTapParameter(Element); if (cmd?.CanExecute(param) ?? false) { cmd.Execute(param); } }
private void OnRightTapped(object sender, Windows.UI.Xaml.Input.RightTappedRoutedEventArgs e) { Tap(); var cmd = Touch.GetLongTap(Element); if (cmd?.CanExecute(Element.BindingContext) ?? false) { cmd.Execute(Element.BindingContext); } }
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; } }
private void LongTap() { var cmdLong = Touch.GetLongTap(Element); var paramLong = Touch.GetLongTapParameter(Element); if (cmdLong == null) { Tap(); return; } if (cmdLong.CanExecute(paramLong)) { cmdLong.Execute(paramLong); } }
private void LongClickHandler() { SelectHandler(); var cmdLong = Touch.GetLongTap(Element); if (cmdLong == null) { ClickHandler(); return; } if (cmdLong.CanExecute(Element.BindingContext)) { cmdLong.Execute(Element.BindingContext); } }
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); } }
public override bool OnTouchEvent(MotionEvent e) { float x = e.RawX; float y = e.RawY; float internalX = e.GetX(); float internalY = e.GetY(); host.currentX = x; host.currentY = y; // Detect nestered gesture if (nestedGesture != null) { nestedGesture.OnTouchEvent(e); // Detect END for nestered gesture if (e.Action == MotionEventActions.Cancel || e.Action == MotionEventActions.Up) { nestedGesture = null; } return(true); } // START if (e.Action == MotionEventActions.Down) { if (!host.IsEnabled || isGestureProcessed) { return(true); } // Detect nested TouchSam gestures var childs = host.GetNestedTouchs(view); foreach (var item in childs) { if (host.IsViewInBounds(item.View, (int)x, (int)y)) { nestedGesture = item.Gesture; nestedGesture.OnTouchEvent(e); return(true); } } isGestureProcessed = true; host.startX = x; host.startY = y; host.StartTap(); host.AnimationStart(internalX, internalY); // Try start long tap timer if (Touch.GetLongTap(host.Element) != null) { host.timer?.Stop(); host.timer?.Start(); } } // MOVE else if (e.Action == MotionEventActions.Move || e.Action == MotionEventActions.Scroll) { if (!isGestureProcessed) { return(true); } float deltaX = Math.Abs(host.startX - x); float deltaY = Math.Abs(host.startY - y); if (deltaX > touchSlop || deltaY > touchSlop || !host.IsEnabled) { host.FinishTap(); host.AnimationEnd(); host.timer?.Stop(); isGestureProcessed = false; } } // UP else if (e.Action == MotionEventActions.Up || e.Action == MotionEventActions.Cancel) { if (host.IsDisposed || !isGestureProcessed) { return(true); } isGestureProcessed = false; host.AnimationEnd(); host.FinishTap(); if (e.Action == MotionEventActions.Up && host.IsEnabled) { // Tap sound :) view.PlaySoundEffect(SoundEffects.Click); if (host.IsViewInBounds(view, (int)e.RawX, (int)e.RawY)) { if (Touch.GetLongTap(host.Element) == null) { host.Tap(); } else if (host.timer == null || host.timer.Enabled) { host.Tap(); } } } host.timer?.Stop(); } return(true); }
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(); } }