/// <summary> /// Indexs the path at point. /// </summary> /// <returns>The path at point.</returns> /// <param name="listView">List view.</param> /// <param name="p">P.</param> public Tuple <int, int> IndexPathAtPoint(Xamarin.Forms.ListView listView, Xamarin.Forms.Point p) { var renderer = Renderer(listView); var point = new CoreGraphics.CGPoint(p.X * Display.Scale, p.Y * Display.Scale); //System.Diagnostics.Debug.WriteLine("size=["+renderer.Control.Frame.Size+"]"); //System.Diagnostics.Debug.WriteLine("point=["+point+"]"); var visibleCells = renderer.Control.VisibleCells; var visibleCellIndexPaths = renderer.Control.IndexPathsForVisibleRows; var scroll = renderer.Control.ContentOffset; //System.Diagnostics.Debug.WriteLine("Scroll=["+scroll+"]"); foreach (var ip in visibleCellIndexPaths) { var cell = renderer.Control.CellAt(ip); var frame = cell.Frame; var frameX = cell.ConvertRectToView(frame, renderer.Control); var frameZ = new CoreGraphics.CGRect(frameX.X - scroll.X * Display.Scale, frameX.Y - scroll.Y * Display.Scale, frameX.Width * Display.Scale, frameX.Height * Display.Scale); //System.Diagnostics.Debug.WriteLine("ip=["+ip+"] frame=[" + frameZ + "]"); if (frameZ.Contains(point)) { return(new Tuple <int, int>(ip.Section, ip.Row)); } } return(null); //System.Diagnostics.Debug.WriteLine(""); //var indexPath = renderer.Control.IndexPathForRowAtPoint(point); //return new Tuple<int, int>(indexPath.Section, indexPath.Row); }
public override bool DispatchTouchEvent(MotionEvent e) { if (e.Action == MotionEventActions.Down) { _downTime = DateTime.UtcNow; _downPosition = new Point(e.RawX, e.RawY); } if (e.Action != MotionEventActions.Up) { return(base.DispatchTouchEvent(e)); } View currentFocus1 = ((Activity)Context).CurrentFocus; bool flag = base.DispatchTouchEvent(e); if (currentFocus1 is EditText) { View currentFocus2 = ((Activity)Context).CurrentFocus; if (currentFocus1 == currentFocus2 && _downPosition.Distance(new Point(e.RawX, e.RawY)) <= Context.ToPixels(20.0) && !(DateTime.UtcNow - _downTime > TimeSpan.FromMilliseconds(200.0))) { int[] location = new int[2]; currentFocus1.GetLocationOnScreen(location); float num1 = e.RawX + currentFocus1.Left - location[0]; float num2 = e.RawY + currentFocus1.Top - location[1]; if (!new Rectangle(currentFocus1.Left, currentFocus1.Top, currentFocus1.Width, currentFocus1.Height).Contains(num1, num2)) { Context.HideKeyboard(currentFocus1); RequestFocus(); currentFocus1.ClearFocus(); } } } return(flag); }
private void Joystick_Pan(Xamarin.Forms.Point point) { var newStickX = (float)(_stickX + point.X); var newStickY = (float)(_stickY + point.Y); var stickAngle = MathHelper.Angle(new SKPoint(_originX, _originY), new SKPoint(newStickX, newStickY)); var distance = MathHelper.Distance(new SKPoint(_originX, _originY), new SKPoint(newStickX, newStickY)); if (distance > _areaRadius * .5f) { _stickX = (float)Math.Cos(stickAngle) * _areaRadius * .5f + _originX; _stickY = (float)Math.Sin(stickAngle) * _areaRadius * .5f + _originY; distance = _areaRadius * .5f; } else { _stickX = newStickX; _stickY = newStickY; } _tiltX = (float)Math.Cos(stickAngle) * distance / (_areaRadius * .5f); _tiltY = (float)Math.Sin(stickAngle) * distance / (_areaRadius * .5f); Tilt = new Point(_tiltX, _tiltY); TiltChanged?.Invoke(new SKPoint(_tiltX, _tiltY)); }
public override bool DispatchTouchEvent(MotionEvent e) { if (e.Action == MotionEventActions.Down) { downTime = DateTime.UtcNow; downPosition = new Xamarin.Forms.Point((double)e.RawX, (double)e.RawY); } if (e.Action != MotionEventActions.Up) { return(base.DispatchTouchEvent(e)); } Android.Views.View currentFocus1 = ((Activity)Context).CurrentFocus; bool flag = base.DispatchTouchEvent(e); if (currentFocus1 is EditText) { Android.Views.View currentFocus2 = ((Activity)Context).CurrentFocus; if (currentFocus1 == currentFocus2 && this.downPosition.Distance(new Xamarin.Forms.Point((double)e.RawX, (double)e.RawY)) <= ContextExtensions.ToPixels(Context, 20.0) && !(DateTime.UtcNow - downTime > TimeSpan.FromMilliseconds(200.0))) { int[] location = new int[2]; currentFocus1.GetLocationOnScreen(location); float num1 = e.RawX + currentFocus1.Left - location[0]; float num2 = e.RawY + currentFocus1.Top - location[1]; if (!new Rectangle((double)currentFocus1.Left, (double)currentFocus1.Top, (double)currentFocus1.Width, (double)currentFocus1.Height).Contains((double)num1, (double)num2)) { ContextExtensions.HideKeyboard(Context, currentFocus1); RequestFocus(); currentFocus1.ClearFocus(); } } } return(flag); }
void OnUp(GestureMotionEvent e) { NumberOfTouches = e.PointerCount; var tookTooLong = (DateTime.Now - _startTime).Milliseconds > MaxSwipeDuration; var wrongAmountOfTouches = NumberOfTouches < SwipeGestureRecognizer.NumberOfTouchesRequired; if (tookTooLong || wrongAmountOfTouches) { State = GestureRecognizerState.Failed; SendGestureEvent(); PointerId = -1; return; } var endTouchPoint = new Xamarin.Forms.Point(e.GetX(0), e.GetY(0)); double velocityX = endTouchPoint.X - FirstTouchPoint.X; double velocityY = endTouchPoint.Y - FirstTouchPoint.Y; var direction = GetSwipeDirection(velocityX, velocityY); var expectedDirection = (Recognizer as SwipeGestureRecognizer).Direction; if (direction == expectedDirection) { State = GestureRecognizerState.Recognized; SendGestureEvent(); } else { State = GestureRecognizerState.Failed; Console.WriteLine("failed gesture was expecting {0} got {1}", expectedDirection, direction); } PointerId = -1; }
public bool OnScale(ScaleGestureDetector detector) { //Debug.WriteLine("Control_PointerWheelChanged"); if (detector.PreviousSpan != detector.CurrentSpan) { double oldScale = Element.ViewScale; // UWP delta とは逆値 double sclae = detector.PreviousSpan / detector.CurrentSpan; if (sclae < 1) { Element.ViewScale = Element.ViewScale * (sclae * 1.1); } else if (sclae > 1) { Element.ViewScale = Element.ViewScale * (sclae / 1.1); } Xamarin.Forms.Point oldPoint = Element.ViewPoint.Offset(detector.FocusX / oldScale, detector.FocusY / oldScale); Xamarin.Forms.Point newPoint = Element.ViewPoint.Offset(detector.FocusX / Element.ViewScale, detector.FocusY / Element.ViewScale); Element.ViewPoint = Element.ViewPoint.Offset(oldPoint.X - newPoint.X, oldPoint.Y - newPoint.Y); DrawImage = Element.DrawImmageRequest(Element.ViewPoint, Matrix2.Enlargement(ViewSize, 1 / Element.ViewScale, 1 / Element.ViewScale)); Invalidate(); } return(true); }
private void OnStop(object sender, ManipulationCompletedRoutedEventArgs e) { if (Element is CarouselLayout layout && _touchDown && layout.IsPanEnabled) { double swipeVelocityTreshlod = 0.3; Xamarin.Forms.Point delta = GetPositionDelta(_start, e.Position); if (Math.Abs(e.Velocities.Linear.X) > swipeVelocityTreshlod) { layout.OnPanUpdated(layout, new PanUpdatedEventArgs(GestureStatus.Canceled, 1, -delta.X, -delta.Y)); } else { layout.OnPanUpdated(layout, new PanUpdatedEventArgs(GestureStatus.Completed, 1, -delta.X, -delta.Y)); } if (e.Velocities.Linear.X > swipeVelocityTreshlod) { layout.OnSwiped(SwipeDirection.Right, Math.Abs(e.Velocities.Linear.X)); } else if (e.Velocities.Linear.X < -swipeVelocityTreshlod) { layout.OnSwiped(SwipeDirection.Left, Math.Abs(e.Velocities.Linear.X)); } e.Handled = true; } _touchDown = false; _firstLayout = null; }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); int size = Element.pointList.Count; paint.StrokeWidth = 6; paint.AntiAlias = true; for (int i = 0; i < size; i++)//绘制元素点图 { Point item = Element.pointList.ElementAt(i); paint.Color = Android.Graphics.Color.Blue; paint.SetStyle(Paint.Style.Fill); //设置为实心 canvas.DrawCircle((int)item.X, (int)item.Y, Element.Circle_r, paint); paint.SetStyle(Paint.Style.Stroke); //设置为空心 canvas.DrawCircle((int)item.X, (int)item.Y, Element.Circle_R, paint); } size = Element.drawList.Count; for (int i = 0; i < size; i++)//绘制选中点图 { Point item = Element.drawList.ElementAt(i); paint.Color = Android.Graphics.Color.Red; paint.SetStyle(Paint.Style.Fill);//设置为实心 canvas.DrawCircle((int)item.X, (int)item.Y, Element.Circle_r, paint); if (i < size - 1) { Point item2 = Element.drawList.ElementAt(i + 1); paint.Color = Android.Graphics.Color.Red; canvas.DrawLine((int)item.X, (int)item.Y, (int)item2.X, (int)item2.Y, paint); paint.SetStyle(Paint.Style.Stroke);//设置为空心 canvas.DrawCircle((int)item.X, (int)item.Y, Element.Circle_R, paint); } } }
void OnDown (GestureMotionEvent e) { //TODO - should really be possible until all taps/fingers are satisfied. State = GestureRecognizerState.Began; // State = (e.PointerCount == SwipeGestureRecognizer.NumberOfTouchesRequired) ? GestureRecognizerState.Began : GestureRecognizerState.Failed; FirstTouchPoint = new Xamarin.Forms.Point (e.GetX (0), e.GetY (0)); _startTime = DateTime.Now; }
void OnDown(GestureMotionEvent e) { //TODO - should really be possible until all taps/fingers are satisfied. State = GestureRecognizerState.Began; // State = (e.PointerCount == SwipeGestureRecognizer.NumberOfTouchesRequired) ? GestureRecognizerState.Began : GestureRecognizerState.Failed; FirstTouchPoint = new Xamarin.Forms.Point(e.GetX(0), e.GetY(0)); _startTime = DateTime.Now; }
IFeature[] GetFeaturesAroundPoint(Point point, double radius, string[] layers) { var output = new List <IFeature>(); RectF rect = point.ToRect(Context.ToPixels(radius)); var listFeatures = map.QueryRenderedFeatures(rect, layers); return(listFeatures.Select(x => x.ToFeature()) .Where(x => x != null) .ToArray()); }
public static Point GetNativeScreenPosition(this BindableObject bindableObject) { var view = bindableObject.GetNativeView (); var point = Point.Zero; if (view != null) { int[] location = new int[2]; view.GetLocationOnScreen (location); point = new Xamarin.Forms.Point (location [0], location [1]); } return point; }
private void OverlayViewRenderer_Tap(object sender, GestureEventArgs e) { var tappableView = Element as TappableView; if (tappableView != null) { var nativePoint = e.GetPosition(this); var xfPoint = new Xamarin.Forms.Point(nativePoint.X, nativePoint.Y); tappableView.OnTap(xfPoint); } }
private void _tapGetsureListener_SingleTap(object sender, MotionEvent e) { if (Element == null) { return; } float scale = Resources.System.DisplayMetrics.Density; Xamarin.Forms.Point pt = new Xamarin.Forms.Point((e.GetX() / scale), (e.GetY() / scale)); (Element as MyCarouselViewControl).LastTapPosition = pt; }
void OnDown (GestureMotionEvent e) { //TODO - should really be possible until all taps/fingers are satisfied. State = (e.PointerCount == TapGestureRecognizer.NumberOfTouchesRequired) ? GestureRecognizerState.Began : GestureRecognizerState.Failed; _currentTapCount = 0; //TODO track all pointers that are down. PointerId = e.GetPointerId (0); FirstTouchPoint = new Xamarin.Forms.Point (e.GetX (0), e.GetY (0)); if (TapGestureRecognizer.NumberOfTapsRequired > 1 && State == GestureRecognizerState.Began) { ResetMultiTapTimer (true); } }
void OnDown(GestureMotionEvent e) { //TODO - should really be possible until all taps/fingers are satisfied. State = (e.PointerCount == TapGestureRecognizer.NumberOfTouchesRequired) ? GestureRecognizerState.Began : GestureRecognizerState.Failed; _currentTapCount = 0; //TODO track all pointers that are down. PointerId = e.GetPointerId(0); FirstTouchPoint = new Xamarin.Forms.Point(e.GetX(0), e.GetY(0)); if (TapGestureRecognizer.NumberOfTapsRequired > 1 && State == GestureRecognizerState.Began) { ResetMultiTapTimer(true); } }
void OnDown (GestureMotionEvent e) { //TODO - should really be possible until all taps/fingers are satisfied. if (e.PointerCount == LongPressGestureRecognizer.NumberOfTouchesRequired) { State = GestureRecognizerState.Began; PointerId = e.GetPointerId (0); FirstTouchPoint = new Xamarin.Forms.Point (e.GetX (0), e.GetY (0)); ResetLongPressTimer (true); } else { State = GestureRecognizerState.Failed; } }
public static Point GetNativeScreenPosition(this VisualElement element) { var view = element.GetNativeView(); var point = Point.Zero; if (view != null) { int[] location = new int[2]; view.GetLocationOnScreen(location); point = new Xamarin.Forms.Point(location[0], location[1]); } return(point); }
void GetScrollPosition(object obj) { var func = obj as Func <Point, object>; if (func == null) { return; } var point = new Point(_recyclerView.GetHorizontalScrollOffset() / _density, _recyclerView.GetVerticalScrollOffset() / _density); func.Invoke(point); }
public static Point GetNativeScreenPosition(this VisualElement element) { var view = element.GetNativeView(); var point = Point.Zero; if (view != null) { int[] location = new int[2]; var p = view.TransformToVisual((UIElement)view.Parent).TransformPoint(new Windows.Foundation.Point(0.0, 0.0)); point = new Xamarin.Forms.Point(location[0], location[1]); } return(point); }
private void OnMove(object sender, ManipulationDeltaRoutedEventArgs e) { if (Element is CarouselLayout layout && _touchDown && layout.IsPanEnabled) { if (_firstLayout != null && layout != _firstLayout) { return; } Xamarin.Forms.Point delta = GetPositionDelta(_start, e.Position); layout.OnPanUpdated(layout, new PanUpdatedEventArgs(GestureStatus.Running, 1, -delta.X, -delta.Y)); e.Handled = true; } }
public virtual void OnClick(global::Android.Views.View view) { var touchPosition = new Xamarin.Forms.Point(downX / density, downY / density); long currentTouchTime = Java.Lang.JavaSystem.CurrentTimeMillis(); if (previousClickTime == 0 || (currentTouchTime - previousClickTime > 250)) { previousClickTime = currentTouchTime; if (previousClickTime != 0 && TransparentPageElement != null) { TransparentPageElement.RaiseItemClicked(touchPosition); } } }
private void btn_Delete_Click(object sender, EventArgs e) { string strHex = lblSelected.Text; ColorCode colorcd = new ColorCode(); foreach (ImageColorInfo info in qList) { if (info.HEXValue.Equals(strHex)) { qList.Remove(info); break; } } _point = new Xamarin.Forms.Point(0.0, 0.0); lastXMove = lastXMoveBak; lastYMove = lastYMoveBak; if (qList.Count > 0) { string hex = qList[qList.Count - 1].HEXValue; btnColor.BackgroundColor = Xamarin.Forms.Color.FromHex(hex); lblSelected.Text = hex; lblHex.Text = hex; Rgb rgb = colorcd.getRgb(hex); lblRgb.Text = colorcd.getRgbString(rgb); lblHsl.Text = colorcd.getHslString(rgb); lblHsv.Text = colorcd.getHsvString(rgb); lblCmyk.Text = colorcd.getCmykString(rgb); lblLab.Text = colorcd.getLabString(rgb); lblMunsell.Text = colorcd.getMunsellString(rgb); lblPccs.Text = colorcd.getPCCSTone(rgb); lblJis.Text = JisUtil.getJisByMunsell(lblMunsell.Text); } else { btnColor.BackgroundColor = Xamarin.Forms.Color.White; lblSelected.Text = string.Empty; lblHex.Text = string.Empty; lblRgb.Text = string.Empty; lblHsl.Text = string.Empty; lblHsv.Text = string.Empty; lblCmyk.Text = string.Empty; lblLab.Text = string.Empty; lblMunsell.Text = string.Empty; lblPccs.Text = string.Empty; lblJis.Text = string.Empty; } // カンバス更新 canvasView.InvalidateSurface(); }
public static Xamarin.Forms.Point[] GetTouches(UIGestureRecognizer gestureRecognizer, CGPoint locationAtStart) { nint numberOfTouches = gestureRecognizer.NumberOfTouches; var array = new Xamarin.Forms.Point[numberOfTouches]; for (int i = 0; i < numberOfTouches; i++) { //var viewPoint = gestureRecognizer.LocationOfTouch(i, gestureRecognizer.View); //var windowPoint = gestureRecognizer.View.ConvertPointToView (viewPoint, null); var windowPoint = gestureRecognizer.LocationOfTouch(i, null); array[i] = new Xamarin.Forms.Point(windowPoint.X - locationAtStart.X, windowPoint.Y - locationAtStart.Y); } return(array); }
void OnDown(GestureMotionEvent e) { //TODO - should really be possible until all taps/fingers are satisfied. if (e.PointerCount == LongPressGestureRecognizer.NumberOfTouchesRequired) { State = GestureRecognizerState.Began; PointerId = e.GetPointerId(0); FirstTouchPoint = new Xamarin.Forms.Point(e.GetX(0), e.GetY(0)); ResetLongPressTimer(true); } else { State = GestureRecognizerState.Failed; } }
protected void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == ExtendedScrollView.PositionProperty.PropertyName) { ExtendedScrollView sv = (ExtendedScrollView)Element; Point pt = sv.Position; if (System.Math.Abs(this.Bounds.Location.Y - pt.Y) < EPSILON && System.Math.Abs(this.Bounds.Location.X - pt.X) < EPSILON) { return; } this.ScrollRectToVisible( new RectangleF((float)pt.X, (float)pt.Y, Bounds.Width, Bounds.Height), sv.AnimateScroll); } }
async void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e) { ClearRtlScrollCheck(); // Adding items into the view while scrolling to the end can cause it to fail, as // the items have not actually been laid out and return incorrect scroll position // values. The ScrollViewRenderer for Android does something similar by waiting up // to 10ms for layout to occur. int cycle = 0; while (Element != null && !Element.IsInNativeLayout) { await Task.Delay(TimeSpan.FromMilliseconds(1)); cycle++; if (cycle >= 10) { break; } } if (Element == null) { return; } double x = e.ScrollX, y = e.ScrollY; ScrollToMode mode = e.Mode; if (mode == ScrollToMode.Element) { Point pos = Element.GetScrollPositionForElement((VisualElement)e.Element, e.Position); x = pos.X; y = pos.Y; mode = ScrollToMode.Position; } if (mode == ScrollToMode.Position) { Control.ChangeView(x, y, null, !e.ShouldAnimate); } Element.SendScrollFinished(); }
private IEnumerable <View> ViewsContainingImpl(Point pt, List <View> views, ViewGroup root) { for (var i = 0; i < root.ChildCount; i++) { var child = root.GetChildAt(i); var bounds = new Rect(); child.GetHitRect(bounds); var ver = child as IVisualElementRenderer; if (ver == null || !(ver.Element is View) || !bounds.Contains(Convert.ToInt32(pt.X), Convert.ToInt32(pt.Y))) { continue; } views.Add(ver.Element as View); //check to see if this containing child has any other containing children ViewsContainingImpl(pt, views, ver.ViewGroup); } return(views); }
/** * We have an issue with Android that makes it pretty much impossible to compose gestures. * Below is my stab at picking up gestures from the activity - the idea is that the main activity would pass all touches to this method * the system will work, and will work very richly (with delay touch, cancel touches, delegate callback for should * recognize in parallel, etc) * However, my time is limited, so this is crude for now. */ public void ProcessGestureMotionEvent(GestureMotionEvent gestureEvent) { var ev = gestureEvent.MotionEvent; var nativeViewScreenLocation = Recognizer.View.GetNativeScreenPosition(); var offset = Xamarin.Forms.Point.Zero; var touchPoint = new Xamarin.Forms.Point(ev.GetX(), ev.GetY()); var mainPointerId = ev.GetPointerId(0); //1. is it inside the view? // Console.WriteLine ("touch point {0} vlocs {1} vlocw {2}", touchPoint.PrettyPrint (), nativeViewScreenLocation.PrettyPrint (), nativeViewWindowLocation.PrettyPrint ()); // Console.WriteLine ("touch point {0} view bounds {1} size {2},{3}", touchPoint, nativeViewScreenLocation, NativeView.Width, NativeView.Height); var isInsideOfView = touchPoint.X >= nativeViewScreenLocation.X && touchPoint.Y >= nativeViewScreenLocation.Y && touchPoint.X <= (NativeView.Width + nativeViewScreenLocation.X) && touchPoint.Y <= (NativeView.Height + nativeViewScreenLocation.Y); //2. report touches inside, or outside but tracked? (so cancels can occur) //TODO track more touches if (isInsideOfView || PointerId == mainPointerId) { //if letting the view know, translate the coords into local view coords (apply the offsets to the touch) offset.X = -nativeViewScreenLocation.X; offset.Y = -nativeViewScreenLocation.Y; ev.OffsetLocation((float)offset.X, (float)offset.Y); var offsetLocation = new Xamarin.Forms.Point(ev.GetX(), ev.GetY()); if (isInsideOfView) { // Console.WriteLine ("INSIDE " + ev.Action + " offset " + offset.PrettyPrint () + " results in " + offsetLocation.PrettyPrint ()); } else { // Console.WriteLine ("touch outside view, but was tracked " + offset); } //TODO - ask the view if it's happy to process this touch at the same time as another gesture - I see no way to make it work for views.. (without //an entire Touch dispatching mechanism:/) //that will be done by 2 parses - one to discover all *gestures* that want the touch, then another parse to go back through and either cancel //or pass the touches long //that's not implemented yet though (time) ProcessMotionEvent(gestureEvent); //remove the offset ev.OffsetLocation((float)-offset.X, (float)-offset.Y); } // Console.WriteLine ("location " + ev.GetX () + ", " + ev.GetY () + " offset " + offset); }
private void OnStart(object sender, ManipulationStartedRoutedEventArgs e) { if (Element is CarouselLayout layout && layout.IsPanEnabled) { if (_firstLayout != null && layout != _firstLayout) { return; } _firstLayout = layout; _start = new Windows.Foundation.Point(e.Position.X, e.Position.Y); Xamarin.Forms.Point delta = GetPositionDelta(_start, _start); layout.OnPanUpdated(layout, new PanUpdatedEventArgs(GestureStatus.Started, 1, -delta.X, -delta.Y)); _touchDown = true; e.Handled = true; } }
void OnUp (GestureMotionEvent e) { NumberOfTouches = e.PointerCount; var tookTooLong = (DateTime.Now - _startTime).Milliseconds > MaxSwipeDuration; var wrongAmountOfTouches = NumberOfTouches < SwipeGestureRecognizer.NumberOfTouchesRequired; if (tookTooLong || wrongAmountOfTouches) { State = GestureRecognizerState.Failed; return; } var endTouchPoint = new Xamarin.Forms.Point (e.GetX (0), e.GetY (0)); double velocityX = endTouchPoint.X - FirstTouchPoint.X; double velocityY = endTouchPoint.Y - FirstTouchPoint.Y; var direction = GetSwipeDirection (velocityX, velocityY); var expectedDirection = (Recognizer as SwipeGestureRecognizer).Direction; if (direction == expectedDirection) { State = GestureRecognizerState.Recognized; } else { State = GestureRecognizerState.Failed; Console.WriteLine ("failed gesture was expecting {0} got {1}", expectedDirection, direction); } }
public static Xamarin.Forms.Point[] GetTouches(this UIGestureRecognizer gestureRecognizer, UIView view) { nint numberOfTouches = gestureRecognizer.NumberOfTouches; var array = new Xamarin.Forms.Point[numberOfTouches]; for (int i = 0; i < numberOfTouches; i++) { /* * if (view == null) * { * var page = Xamarin.Forms.Application.Current.MainPage; * if (page is Xamarin.Forms.NavigationPage navPage) * page = navPage.CurrentPage; * if (Xamarin.Forms.Platform.iOS.Platform.GetRenderer(page) is Xamarin.Forms.Platform.iOS.IVisualElementRenderer renderer) * view = renderer.NativeView; * } */ var point = gestureRecognizer.LocationOfTouch(i, view); array[i] = point.ToPoint(); } return(array); }
protected Xamarin.Forms.Point GetLocationInAncestorView(Xamarin.Forms.Point location, Xamarin.Forms.VisualElement view) { int[] nativeViewLocation = new int[2]; NativeView.GetLocationOnScreen(nativeViewLocation); var nativeViewLocationOnScreen = new Xamarin.Forms.Point(nativeViewLocation [0], nativeViewLocation [1]); var offsetLocation = new Xamarin.Forms.Point(location.X + nativeViewLocationOnScreen.X, location.Y + nativeViewLocationOnScreen.Y); var targetViewRenderer = view.GetRenderer(); var targetView = targetViewRenderer.ViewGroup; int[] targetViewLocation = new int[2]; targetView.GetLocationOnScreen(targetViewLocation); var nativeViewScreenLocation = new Xamarin.Forms.Point(targetViewLocation [0], targetViewLocation [1]); var returnPoint = offsetLocation; returnPoint.X -= nativeViewScreenLocation.X; returnPoint.Y -= nativeViewScreenLocation.Y; // Console.WriteLine ("offsetLocation {0} nativeViewLocationOnScreen {1} returnPoint", offsetLocation, nativeViewLocationOnScreen); // Console.WriteLine ("location {0} parentViewLoc {1} returnPoint {2}", location, nativeViewScreenLocation, returnPoint); return(returnPoint); }
public override bool DispatchTouchEvent(MotionEvent e) { if (e.Action == MotionEventActions.Down) { downTime = DateTime.UtcNow; downPosition = new Xamarin.Forms.Point((double)e.RawX, (double)e.RawY); } if (e.Action != MotionEventActions.Up) return base.DispatchTouchEvent(e); Android.Views.View currentFocus1 = ((Activity) Context).CurrentFocus; bool flag = base.DispatchTouchEvent(e); if (currentFocus1 is EditText) { Android.Views.View currentFocus2 = ((Activity) Context).CurrentFocus; if (currentFocus1 == currentFocus2 && this.downPosition.Distance(new Xamarin.Forms.Point((double)e.RawX, (double)e.RawY)) <= ContextExtensions.ToPixels(Context, 20.0) && !(DateTime.UtcNow - downTime > TimeSpan.FromMilliseconds(200.0))) { int[] location = new int[2]; currentFocus1.GetLocationOnScreen(location); float num1 = e.RawX + currentFocus1.Left - location[0]; float num2 = e.RawY + currentFocus1.Top - location[1]; if (!new Rectangle((double)currentFocus1.Left, (double)currentFocus1.Top, (double)currentFocus1.Width, (double)currentFocus1.Height).Contains((double)num1, (double)num2)) { ContextExtensions.HideKeyboard(Context, currentFocus1); RequestFocus(); currentFocus1.ClearFocus(); } } } return flag; }
void DraggableViewRenderer_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { // Move drag visual // var x = Canvas.GetLeft(_dragVisual); var y = Canvas.GetTop(_dragVisual); _dragVisual.SetValue(Canvas.LeftProperty, x + e.DeltaManipulation.Translation.X); _dragVisual.SetValue(Canvas.TopProperty, y + e.DeltaManipulation.Translation.Y); var draggableView = Element as DraggableView; if (draggableView != null) { var delta = e.CumulativeManipulation.Translation; var pt = new Xamarin.Forms.Point(draggableView.Bounds.Center.X + delta.X, draggableView.Bounds.Center.Y + delta.Y); draggableView.OnDragging(pt); } e.Handled = true; }
public PointerEventArgs(PointerEventType Type, Point Previous, Point Current, bool Down) : base() { this.Type = Type; this.Previous = Previous; this.Current = Current; PointerDown = Down; }
void DraggableViewRenderer_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e) { var delta = e.TotalManipulation.Translation; var draggableView = Element as DraggableView; // Complete the drag // if (draggableView != null) { var pt = new Xamarin.Forms.Point(draggableView.Bounds.Center.X + delta.X, draggableView.Bounds.Center.Y + delta.Y); draggableView.OnDragged(pt); ClearDragVisual(); } e.Handled = true; }
SKPoint ConvertToPixel(Xamarin.Forms.Point pt) { return(new SKPoint((float)(CanvasSize.Width * pt.X / Width), (float)(CanvasSize.Height * pt.Y / Height))); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnTouchEffectAction(object sender, TouchActionEventArgs args) { try { var point = args.Location[0]; var id = args.Id; switch (args.Type) { case TouchActionType.Pressed: // 2指タッチ if (args.PointerCount == 2) { touchId = args.Id; pressPoint1 = args.Location[0]; pressPoint2 = args.Location[1]; pressTime = DateTime.Now; lastFingerDis = distanceBetweenFingers(args); _colorChanged = false; } else { _colorChanged = true; } break; case TouchActionType.Moved: if (args.PointerCount == 2) { TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts2 = new TimeSpan(pressTime.Ticks); TimeSpan ts3 = ts1.Subtract(ts2); double xMove1 = pressPoint1.X - args.Location[0].X; double yMove1 = pressPoint1.Y - args.Location[0].Y; double xMove2 = pressPoint2.X - args.Location[1].X; double yMove2 = pressPoint2.Y - args.Location[1].Y; if (!distanceBetweenFingers(xMove1, yMove1, xMove2, yMove2)) { _colorChanged = false; lastXMove = xMove1 + lastXMoveBak; lastYMove = yMove1 + lastYMoveBak; canvasView.InvalidateSurface(); } else { iTime += (long)float.Parse(ts3.TotalMilliseconds.ToString()); if (iTime > 2000) { double fingerDis = distanceBetweenFingers(args); if (fingerDis > lastFingerDis) { _colorChanged = false; if (scaledRatio == double.Parse(dicConfig["scaledRatio1"])) { scaledRatio = double.Parse(dicConfig["scaledRatio2"]); } else if (scaledRatio == double.Parse(dicConfig["scaledRatio2"])) { scaledRatio = double.Parse(dicConfig["scaledRatio3"]); } else if (scaledRatio == double.Parse(dicConfig["scaledRatio3"])) { scaledRatio = double.Parse(dicConfig["scaledRatio4"]); } else if (scaledRatio == double.Parse(dicConfig["scaledRatio4"])) { scaledRatio = double.Parse(dicConfig["scaledRatio5"]); } } else { if (scaledRatio == double.Parse(dicConfig["scaledRatio5"])) { scaledRatio = double.Parse(dicConfig["scaledRatio4"]); } else if (scaledRatio == double.Parse(dicConfig["scaledRatio4"])) { scaledRatio = double.Parse(dicConfig["scaledRatio3"]); } else if (scaledRatio == double.Parse(dicConfig["scaledRatio3"])) { scaledRatio = double.Parse(dicConfig["scaledRatio2"]); } else if (scaledRatio == double.Parse(dicConfig["scaledRatio2"])) { scaledRatio = double.Parse(dicConfig["scaledRatio1"]); } _colorChanged = false; } iTime = 0; canvasView.InvalidateSurface(); } } } break; case TouchActionType.Released: if (args.PointerCount == 1) { if (_colorChanged) { if (point != _point) { _colorChanged = true; _point = point; canvasView.InvalidateSurface(); } else { _colorChanged = false; } } lastXMoveBak = lastXMove; lastYMoveBak = lastYMove; } break; case TouchActionType.Cancelled: lastXMoveBak = lastXMove; lastYMoveBak = lastYMove; break; } } catch (Exception ex) { } }
protected Xamarin.Forms.Point GetLocationInAncestorView (Xamarin.Forms.Point location, Xamarin.Forms.VisualElement view) { int[] nativeViewLocation = new int[2]; NativeView.GetLocationOnScreen (nativeViewLocation); var nativeViewLocationOnScreen = new Xamarin.Forms.Point (nativeViewLocation [0], nativeViewLocation [1]); var offsetLocation = new Xamarin.Forms.Point (location.X + nativeViewLocationOnScreen.X, location.Y + nativeViewLocationOnScreen.Y); var targetViewRenderer = view.GetRenderer (); var targetView = targetViewRenderer.ViewGroup; int[] targetViewLocation = new int[2]; targetView.GetLocationOnScreen (targetViewLocation); var nativeViewScreenLocation = new Xamarin.Forms.Point (targetViewLocation [0], targetViewLocation [1]); var returnPoint = offsetLocation; returnPoint.X -= nativeViewScreenLocation.X; returnPoint.Y -= nativeViewScreenLocation.Y; // Console.WriteLine ("offsetLocation {0} nativeViewLocationOnScreen {1} returnPoint", offsetLocation, nativeViewLocationOnScreen); // Console.WriteLine ("location {0} parentViewLoc {1} returnPoint {2}", location, nativeViewScreenLocation, returnPoint); return returnPoint; }
/** * We have an issue with Android that makes it pretty much impossible to compose gestures. * Below is my stab at picking up gestures from the activity - the idea is that the main activity would pass all touches to this method * the system will work, and will work very richly (with delay touch, cancel touches, delegate callback for should * recognize in parallel, etc) * However, my time is limited, so this is crude for now. */ public void ProcessGestureMotionEvent (GestureMotionEvent gestureEvent) { var ev = gestureEvent.MotionEvent; var nativeViewScreenLocation = Recognizer.View.GetNativeScreenPosition (); var offset = Xamarin.Forms.Point.Zero; var touchPoint = new Xamarin.Forms.Point (ev.GetX (), ev.GetY ()); var mainPointerId = ev.GetPointerId (0); //1. is it inside the view? // Console.WriteLine ("touch point {0} vlocs {1} vlocw {2}", touchPoint.PrettyPrint (), nativeViewScreenLocation.PrettyPrint (), nativeViewWindowLocation.PrettyPrint ()); // Console.WriteLine ("touch point {0} view bounds {1} size {2},{3}", touchPoint, nativeViewScreenLocation, NativeView.Width, NativeView.Height); var isInsideOfView = touchPoint.X >= nativeViewScreenLocation.X && touchPoint.Y >= nativeViewScreenLocation.Y && touchPoint.X <= (NativeView.Width + nativeViewScreenLocation.X) && touchPoint.Y <= (NativeView.Height + nativeViewScreenLocation.Y); //2. report touches inside, or outside but tracked? (so cancels can occur) //TODO track more touches if (isInsideOfView || PointerId == mainPointerId) { //if letting the view know, translate the coords into local view coords (apply the offsets to the touch) offset.X = -nativeViewScreenLocation.X; offset.Y = -nativeViewScreenLocation.Y; ev.OffsetLocation ((float)offset.X, (float)offset.Y); var offsetLocation = new Xamarin.Forms.Point (ev.GetX (), ev.GetY ()); if (isInsideOfView) { // Console.WriteLine ("INSIDE " + ev.Action + " offset " + offset.PrettyPrint () + " results in " + offsetLocation.PrettyPrint ()); } else { // Console.WriteLine ("touch outside view, but was tracked " + offset); } //TODO - ask the view if it's happy to process this touch at the same time as another gesture - I see no way to make it work for views.. (without //an entire Touch dispatching mechanism:/) //that will be done by 2 parses - one to discover all *gestures* that want the touch, then another parse to go back through and either cancel //or pass the touches long //that's not implemented yet though (time) ProcessMotionEvent (gestureEvent); //remove the offset ev.OffsetLocation ((float)-offset.X, (float)-offset.Y); } // Console.WriteLine ("location " + ev.GetX () + ", " + ev.GetY () + " offset " + offset); }