public override bool OnTouchEvent(MotionEvent e) { if (e.PointerCount == 0 || Element == null) { return(false); } var scale = Element.Width / Width; var touchInfo = new List <Point>(); var coord = new MotionEvent.PointerCoords(); e.GetPointerCoords(0, coord); var point = new Point(coord.X * scale, coord.Y * scale); // Handle touch actions switch (e.Action) { case MotionEventActions.Down: Element.OnTouchesBegan(point); break; case MotionEventActions.Up: Element.OnTouchesEnded(point); break; //TODO add more action types } return(true); }
public static Point[] GetRawTouches(MotionEvent current) { var result = new Point[current.PointerCount]; /* * // second point is jumps around a lot * if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Q) * { * for (int i = 0; i < current.PointerCount; i++) * { * var x = current.GetRawX(i) / Display.Scale; * var y = current.GetRawY(i) / Display.Scale; * var point = new Point(x, y); * result[i] = point; * } * if (result.Length>1) * System.Diagnostics.Debug.WriteLine("p0["+result[0].ToString("N2")+"] p1["+result[1].ToString("N2")+"]"); * * } * else * { */ var offsetX = current.RawX / Display.Scale - current.GetX(); var offsetY = current.RawY / Display.Scale - current.GetY(); MotionEvent.PointerCoords touch = new MotionEvent.PointerCoords(); for (int i = 0; i < current.PointerCount; i++) { current.GetPointerCoords(i, touch); var point = new Point(touch.X + offsetX, touch.Y + offsetY); result[i] = point; } //} return(result); }
public bool OnTouch(View v, MotionEvent e) { switch (e.Action) { case MotionEventActions.Down: _parent._isTouching = true; break; case MotionEventActions.Move: var pointerCoords = new MotionEvent.PointerCoords(); e.GetPointerCoords(0, pointerCoords); _parent._position = new Vector2(pointerCoords.X, pointerCoords.Y); break; case MotionEventActions.Up: _parent._isTouching = false; break; default: return(false); } // TODO: Not sure if this should be called here or somewhere else _parent.Update(); return(true); }
private void DrawLine(MotionEvent.PointerCoords point1, MotionEvent.PointerCoords point2) { // Draw the line _canvas.DrawLine(point1.X - 0.5f, point1.Y - 0.5f, point2.X, point2.Y, _currentPaint); // Set the bitmap to the ImageView this.Control.SetImageBitmap(_bitmap); }
public override bool OnTouchEvent(MotionEvent e) { //System.Diagnostics.Debug.WriteLine("============================================================="); //System.Diagnostics.Debug.WriteLine("NativeGestureDetector.OnTouchEvent e.Action=[" + e.Action + "]"); bool handled = base.OnTouchEvent(e); //System.Diagnostics.Debug.WriteLine("NativeGestureDetector.OnTouchEvent handled=" + handled); if (e.PointerCount > 1 && _listener != null) { // multi point gesture ? bool[] valid = new bool[6]; MotionEvent.PointerCoords[] coords = new MotionEvent.PointerCoords[6]; for (int i = 0; i < Math.Min(e.PointerCount, 6); i++) { coords[i] = new MotionEvent.PointerCoords(); var index = e.FindPointerIndex(i); if (index > -1 && index < 6) { valid[index] = true; e.GetPointerCoords(index, coords[i]); if (_lastCoords != null && _lastCoords[i] != null) { _avgCoords[i].X = (float)((coords[i].X + _lastCoords[i].X) / 2.0); _avgCoords[i].Y = (float)((coords[i].Y + _lastCoords[i].Y) / 2.0); } _lastCoords = coords; } } if (e.Action == MotionEventActions.Down || e.Action == MotionEventActions.Pointer1Down || e.Action == MotionEventActions.Pointer2Down) { handled = handled || _listener.OnMultiDown(e, _lastCoords); } else if (e.Action == MotionEventActions.Move) { handled = handled || _listener.OnMultiMove(e, _avgCoords); } else if (e.Action == MotionEventActions.Cancel || e.Action == MotionEventActions.Up || e.Action == MotionEventActions.Pointer1Up || e.Action == MotionEventActions.Pointer2Up) { handled = handled || _listener.OnMultiUp(e, _avgCoords); _lastCoords = null; } } // the following line was once needed but now it seems to cause double "UPS" to be called when used with Bc3.Forms.KeypadButton; //else if (e.ActionMasked == MotionEventActions.Up || e.ActionMasked == MotionEventActions.Pointer1Up || (e.Action == MotionEventActions.Down && _lastMotionEvent != null && _lastMotionEvent.Action == MotionEventActions.Down)) else if (e.ActionMasked == MotionEventActions.Up || e.ActionMasked == MotionEventActions.Pointer1Up) { _listener?.OnUp(e); } else if (e.Action == MotionEventActions.Cancel) { _listener?.Cancel(e); } _lastMotionEvent = e; return(handled); }
// E/JniUtils(11823): couldn't get gazeEventFromNative, (FFZZLandroid/app/Activity;)V private static void gazeEventFromNative(float x, float y, bool press, bool release, Activity target) { Log.d(TAG, "gazeEventFromNative( " + x + " " + y + " " + press + " " + release + " " + target); (new Handler(Looper.getMainLooper())).post( new xRunnable() { yield = delegate { long now = SystemClock.uptimeMillis(); if (press) { downTime = now; } MotionEvent.PointerProperties pp = new MotionEvent.PointerProperties(); pp.toolType = MotionEvent.TOOL_TYPE_FINGER; pp.id = 0; MotionEvent.PointerProperties[] ppa = new MotionEvent.PointerProperties[1]; ppa[0] = pp; MotionEvent.PointerCoords pc = new MotionEvent.PointerCoords(); pc.x = x; pc.y = y; MotionEvent.PointerCoords[] pca = new MotionEvent.PointerCoords[1]; pca[0] = pc; int eventType = MotionEvent.ACTION_MOVE; if (press) { eventType = MotionEvent.ACTION_DOWN; } else if (release) { eventType = MotionEvent.ACTION_UP; } MotionEvent ev = MotionEvent.obtain( downTime, now, eventType, 1, ppa, pca, 0, /* meta state */ 0, /* button state */ 1.0f, 1.0f, /* precision */ 10, /* device ID */ 0, /* edgeFlags */ InputDevice.SOURCE_TOUCHSCREEN, 0 /* flags */); Log.d(TAG, "Synthetic:" + ev); Window w = target.getWindow(); View v = w.getDecorView(); v.dispatchTouchEvent(ev); } }); }
public override bool OnTouchEvent(MotionEvent e) { System.Diagnostics.Debug.WriteLine("NativeGestureDetector.OnTouchEvent e.Action=[" + e.Action + "]"); bool handled = base.OnTouchEvent(e); //System.Diagnostics.Debug.WriteLine("NativeGestureDetector.OnTouchEvent handled=" + handled); if (e.PointerCount > 1 && _listener != null) { // multi point gesture ? bool[] valid = new bool[6]; MotionEvent.PointerCoords[] coords = null; coords = new MotionEvent.PointerCoords[6]; for (int i = 0; i < Math.Min(e.PointerCount, 6); i++) { coords[i] = new MotionEvent.PointerCoords(); var index = e.FindPointerIndex(i); if (index > -1 && index < 6) { valid[index] = true; e.GetPointerCoords(index, coords[i]); if (_lastCoords != null && _lastCoords[i] != null) { _avgCoords[i].X = (float)((coords[i].X + _lastCoords[i].X) / 2.0); _avgCoords[i].Y = (float)((coords[i].Y + _lastCoords[i].Y) / 2.0); } _lastCoords = coords; } } if (e.Action == MotionEventActions.Down || e.Action == MotionEventActions.Pointer1Down || e.Action == MotionEventActions.Pointer2Down) { handled = handled || _listener.OnMultiDown(e, _lastCoords); } else if (e.Action == MotionEventActions.Move) { handled = handled || _listener.OnMultiMove(e, _avgCoords); } else if (e.Action == MotionEventActions.Cancel || e.Action == MotionEventActions.Up || e.Action == MotionEventActions.Pointer1Up || e.Action == MotionEventActions.Pointer2Up) { handled = handled || _listener.OnMultiUp(e, _avgCoords); _lastCoords = null; } } else if (e.ActionMasked == MotionEventActions.Up || e.ActionMasked == MotionEventActions.Pointer1Up) { _listener?.OnUp(e); } else if (e.Action == MotionEventActions.Cancel) { _listener?.Cancel(); } return(handled); }
//int _lastEventPointerCount; public NativeGestureDetector(Context context, NativeGestureListener listener) : base(context, listener) { _listener = listener; IsLongpressEnabled = false; _avgCoords = new MotionEvent.PointerCoords[6]; for (int i = 0; i < 6; i++) { _avgCoords[i] = new MotionEvent.PointerCoords(); } }
public override bool OnTouchEvent(MotionEvent e) { if (e.Action == MotionEventActions.Down) { if (!IsEnabled) { return(base.OnTouchEvent(e)); } try { MotionEvent.PointerCoords pointReal = new MotionEvent.PointerCoords(); e.GetPointerCoords(0, pointReal); NGraphics.Point point; if (IsTitleOnTop) { point = new NGraphics.Point(pointReal.X, pointReal.Y + textHeight); } else { point = new NGraphics.Point(pointReal.X, pointReal.Y - textHeight); } if (Center.HasValue && RadiusAll.HasValue) { double selectedRadian = RadianOfPoint(point); double sumRadian = 0.0; foreach (var eachSegment in ListItems) { if (sumRadian <= selectedRadian && selectedRadian <= sumRadian + eachSegment.Radian) { eachSegment.IsSelected = true; SelectedItem = eachSegment; ItemSelected?.Invoke(this, eachSegment); } sumRadian += eachSegment.Radian; } } } // Analysis disable once EmptyGeneralCatchClause catch (Exception exc) { #if DEBUG throw; #endif } } return(base.OnTouchEvent(e)); }
/// <Docs>The motion event.</Docs> /// <returns>To be added.</returns> /// <para tool="javadoc-to-mdoc">Implement this method to handle touch screen motion events.</para> /// <format type="text/html">[Android Documentation]</format> /// <since version="Added in API level 1"></since> /// <summary> /// Raises the touch event event. /// </summary> /// <param name="e">E.</param> public override bool OnTouchEvent(MotionEvent e) { var scale = Element.Width / Width; var touchInfo = new List <NGraphics.Point>(); for (var i = 0; i < e.PointerCount; i++) { var coord = new MotionEvent.PointerCoords(); e.GetPointerCoords(i, coord); touchInfo.Add(new NGraphics.Point(coord.X * scale, coord.Y * scale)); } var result = false; // Handle touch actions switch (e.Action) { case MotionEventActions.Down: if (Element != null) { result = Element.TouchesBegan(touchInfo); } break; case MotionEventActions.Move: if (Element != null) { result = Element.TouchesMoved(touchInfo); } break; case MotionEventActions.Up: if (Element != null) { result = Element.TouchesEnded(touchInfo); } break; case MotionEventActions.Cancel: if (Element != null) { result = Element.TouchesCancelled(touchInfo); } break; } return(result); }
public static Point[] GetTouches(MotionEvent current, Android.Views.View view, Listener listener) { int pointerCount = current.PointerCount; var pointerCoords = new MotionEvent.PointerCoords[pointerCount]; using (var pointerCoord = new MotionEvent.PointerCoords()) { for (int i = 0; i < pointerCount; i++) { current.GetPointerCoords(i, pointerCoord); pointerCoords[i] = new MotionEvent.PointerCoords(pointerCoord); } } return(GetTouches(pointerCoords, view, listener)); }
private MotionEvent.PointerCoords GetPointerCoords(Android.Views.MotionEvent e, int pointerId) { // Get the pointer coords var pointerIndex = e.FindPointerIndex(pointerId); if (pointerIndex < 0) { return(null); } var point = new MotionEvent.PointerCoords(); e.GetPointerCoords(pointerIndex, point); return(point); }
public override bool OnTouchEvent(Android.Views.MotionEvent e) { var action = e.ActionMasked; var index = e.ActionIndex; Debug.WriteLine($"ACTION:{action}"); var coords = new MotionEvent.PointerCoords(); e.GetPointerCoords(index, coords); var position = new SKPoint(coords.X, coords.Y); if (action == MotionEventActions.Down) { var current = new Touch() { StartPosition = position, Position = position, State = TouchState.Began, }; this.touches[index] = current; this.view.Touch(new [] { current }); return(true); } else if (action == MotionEventActions.Move) { var current = this.touches[index]; current.Position = position; current.State = TouchState.Moved; this.view.Touch(new[] { current }); return(true); } else if (action == MotionEventActions.Cancel || action == MotionEventActions.Up) { var current = this.touches[index]; this.touches.Remove(index); current.Position = position; current.State = TouchState.Ended; this.view.Touch(new[] { current }); return(true); } return(base.OnTouchEvent(e)); }
public static Point[] GetTouches(MotionEvent current, Android.Views.View view, int[] startLocation) { //System.Diagnostics.Debug.WriteLine("c0=["+current.GetX()+","+current.GetY()+"]"); int[] viewLocation = { 0, 0 }; view?.GetLocationInWindow(viewLocation); var pointerCoords = new MotionEvent.PointerCoords(); int pointerCount = current.PointerCount; var array = new Point[pointerCount]; for (int i = 0; i < pointerCount; i++) { current.GetPointerCoords(i, pointerCoords); array[i] = DIP.ToPoint((double)(pointerCoords.X + viewLocation[0] - startLocation[0]), (double)(pointerCoords.Y + viewLocation[1] - startLocation[1])); //System.Diagnostics.Debug.WriteLine ("i=["+i+"] pc=["+pointerCoords.X+", "+pointerCoords.Y+"] a=["+array[i]+"]"); } return(array); }
private double DetectResizeMotion(TouchEventArgs e) { if (_resizeReady) { if (e.Event.PointerCount != 2) { return(-1); } MotionEvent.PointerCoords p0 = new MotionEvent.PointerCoords(); e.Event.GetPointerCoords(0, p0); Console.WriteLine(string.Format("X:{0}, Y:{1}", p0.X, p0.Y)); MotionEvent.PointerCoords p1 = new MotionEvent.PointerCoords(); e.Event.GetPointerCoords(1, p1); Console.WriteLine(string.Format("X:{0}, Y:{1}", p1.X, p1.Y)); double resize = Math.Sqrt(Math.Abs(p0.X - p1.X) * Math.Abs(p0.X - p1.X) + Math.Abs(p0.Y - p1.Y) * Math.Abs(p0.Y - p1.Y)); Console.WriteLine(string.Format("resize:{0}", resize)); return(resize); } return(-1); }
public override bool OnTouchEvent(MotionEvent e) { base.OnTouchEvent(e); switch (e.ActionMasked) { case MotionEventActions.Down: { int id = e.GetPointerId(0); var start = new MotionEvent.PointerCoords(); e.GetPointerCoords(id, start); coords.Add(id, start); return(true); } case MotionEventActions.Move: { for (int index = 0; index < e.PointerCount; index++) { var id = e.GetPointerId(index); float x = e.GetX(index); float y = e.GetY(index); drawCanvas.DrawLine(coords[id].X, coords[id].Y, x, y, drawPaint); coords[id].X = x; coords[id].Y = y; } Invalidate(); return(true); } case MotionEventActions.Up: { int id = e.GetPointerId(0); coords.Remove(id); return(true); } default: return(false); } }
bool OnMove(GestureMotionEvent e) { _currentScreenPoint = new Xamarin.Forms.Point(e.GetX(), e.GetY()); var currentViewPosition = new Xamarin.Forms.Point(NativeView.GetX(), NativeView.GetY()); var currentViewOffset = new Xamarin.Forms.Point(currentViewPosition.X - _startPoint.X, currentViewPosition.Y - _startPoint.Y); var eventPoint = new Xamarin.Forms.Point(e.GetX() + currentViewOffset.X, e.GetY() + currentViewOffset.Y); var coords = new MotionEvent.PointerCoords(); e.GetPointerCoords(0, coords); // Console.WriteLine ("CHANGED e2{0} coords {1},{2}", eventPoint, coords.X, coords.Y); if (State != GestureRecognizerState.Possible && State != GestureRecognizerState.Began && State != GestureRecognizerState.Changed) { return(false); } if (e.GetX() < 0 || e.GetX() > NativeView.Width || e.GetY() < 0 || e.GetY() > NativeView.Height) { Console.WriteLine("Gesture exited from view - it's over"); State = GestureRecognizerState.Ended; PointerId = -1; SendGestureEvent(); return(false); } if (e.ActionMasked == MotionEventActions.Move || e.ActionMasked == MotionEventActions.Scroll) { _previousPoint = _currentPoint; _currentPoint = eventPoint; _velocity = new Xamarin.Forms.Point(_currentPoint.X - _previousPoint.X, _currentPoint.Y - _previousPoint.Y); //TODO proper conversion _rawTranslation.X += _velocity.X / 2; _rawTranslation.Y += _velocity.Y / 2; State = State == GestureRecognizerState.Possible ? GestureRecognizerState.Began : GestureRecognizerState.Changed; e.IsCancelled = Recognizer.CancelsTouchesInView; } // Console.WriteLine ("State " + State + "_previousPoint " + _previousPoint + " _currentPoint" + _currentPoint); SendGestureEvent(); return(false); }
public bool OnTouch(View v, MotionEvent e) { switch (e.Action) { case MotionEventActions.Down: _parent._isTouching = true; break; case MotionEventActions.Move: var pointerCoords = new MotionEvent.PointerCoords(); e.GetPointerCoords(0, pointerCoords); _parent._position = new Vector2(pointerCoords.X, pointerCoords.Y); break; case MotionEventActions.Up: _parent._isTouching = false; break; default: return(false); } return(true); }
public override bool OnTouchEvent(MotionEvent e) { switch (e.ActionMasked) { case MotionEventActions.Down: { int id = e.GetPointerId(0); var start = new MotionEvent.PointerCoords(); e.GetPointerCoords(id, start); koordinatlar.Add(id, start); return(true); } case MotionEventActions.PointerDown: { int id = e.GetPointerId(e.ActionIndex); var start = new MotionEvent.PointerCoords(); e.GetPointerCoords(id, start); koordinatlar.Add(id, start); return(true); } case MotionEventActions.Move: { for (int index = 0; index < e.PointerCount; index++) { var id = e.GetPointerId(index); float x = e.GetX(index); float y = e.GetY(index); cizimAlani.DrawLine(koordinatlar[id].X, koordinatlar[id].Y, x, y, cizilenResim); koordinatlar[id].X = x; koordinatlar[id].Y = y; CizimBasladi?.Invoke(this, EventArgs.Empty); } Invalidate(); return(true); } case MotionEventActions.PointerUp: { int id = e.GetPointerId(e.ActionIndex); koordinatlar.Remove(id); return(true); } case MotionEventActions.Up: { int id = e.GetPointerId(0); koordinatlar.Remove(id); return(true); } default: return(false); } }
public override bool OnTouchEvent(MotionEvent e) { // Get current position of pointer at index 0. // This will be the first pointer down and the last pointer up even if not the same System.Drawing.PointF curr = new System.Drawing.PointF(e.GetX(), e.GetY()); switch (e.Action) { case MotionEventActions.PointerDown: pointer2Index = 1; break; case MotionEventActions.Down: // Set the current box and add it to the List<Box> mBoxes if (mCurrentBox == null) { mCurrentBox = new Box(curr, e.GetPointerId(0)); mBoxes.Add(mCurrentBox); } break; case MotionEventActions.Pointer2Down: // Handle 2nd touch. Set the start point of the rotation if (mRotationStart == null) { // Get coordinates of pointer 2 MotionEvent.PointerCoords pCoords = new MotionEvent.PointerCoords(); e.GetPointerCoords(1, pCoords); // Set the starting coordinates for the rotation mRotationStart = new Box(new System.Drawing.PointF(pCoords.X, pCoords.Y), e.GetPointerId(1)); mInitialRotation = mCurrentBox.Rotation; pointer2Index = 1; } break; case MotionEventActions.Move: // Handle first pointer move, set end point for rectangle if (mCurrentBox != null && mCurrentBox.PointerId == e.GetPointerId(0)) { mCurrentBox.Current = curr; } // Handle second pointer move, set rotation amount if (mRotationStart != null && mRotationStart.PointerId == e.GetPointerId(pointer2Index)) { // Get coordinates of pointer 2 MotionEvent.PointerCoords pCoords = new MotionEvent.PointerCoords(); e.GetPointerCoords(pointer2Index, pCoords); // Set the rotation of the box to the difference between the origin of mRotation and the current position of pointer 2 mCurrentBox.Rotation = mInitialRotation + pCoords.Y - mRotationStart.Origin.Y; } Invalidate(); break; case MotionEventActions.Pointer2Up: mRotationStart = null; break; case MotionEventActions.PointerUp: pointer2Index = 0; break; case MotionEventActions.Up: mCurrentBox = null; mRotationStart = null; break; case MotionEventActions.Cancel: mCurrentBox = null; mRotationStart = null; break; } return(true); }
//Shared handler functions private Point GetPoint(Android.Views.View.TouchEventArgs args, int index) { MotionEvent.PointerCoords temp = new MotionEvent.PointerCoords(); args.Event.GetPointerCoords(index, temp); return(new Point(temp.X, temp.Y)); }
public void GetPointerCoords(int pointerIndex, MotionEvent.PointerCoords outPointerCoords) { MotionEvent.GetPointerCoords(pointerIndex, outPointerCoords); }
void HandleTouch(object sender, TouchEventArgs e) { bool cancelBase = false; if (e.Event.ActionMasked == MotionEventActions.Down) { _tapedDownTime = e.Event.EventTime; _tapedX = e.Event.RawX; _tapedY = e.Event.RawY; GestureFrame _gi = (GestureFrame)this.Element; _gi.OnDown(sender, e, e.Event.RawX, e.Event.RawY, e.Event.ActionIndex); } if (e.Event.ActionMasked == MotionEventActions.Pointer1Up) { GestureFrame _gi = (GestureFrame)this.Element; _gi.OnResizeDone(sender, e); _resizeReady = false; ignore_action = true; } if (e.Event.ActionMasked == MotionEventActions.Pointer1Down) { _resizeReady = true; ignore_action = false; if (_resizeReady) { MotionEvent.PointerCoords p0 = new MotionEvent.PointerCoords(); MotionEvent.PointerCoords p1 = new MotionEvent.PointerCoords(); e.Event.GetPointerCoords(0, p0); e.Event.GetPointerCoords(1, p1); _resize = Math.Sqrt(Math.Abs(p0.X - p1.X) * Math.Abs(p0.X - p1.X) + Math.Abs(p0.Y - p1.Y) * Math.Abs(p0.Y - p1.Y)); } } else if (e.Event.ActionMasked == MotionEventActions.Up) { GestureFrame _gi = (GestureFrame)this.Element; _gi.OnUp(sender, e, e.Event.RawX, e.Event.RawY); if ((e.Event.EventTime - _tapedDownTime < 250) && Math.Abs(_tapedX - e.Event.RawX) < 20 && Math.Abs(_tapedY - e.Event.RawY) < 20) { _gi.OnTapped(sender, e, e.Event.RawX, e.Event.RawY); } if (e.Event.PointerCount <= 1) { ignore_action = false; } } else if (e.Event.ActionMasked == MotionEventActions.Move) { GestureFrame _gi = (GestureFrame)this.Element; double rs = DetectResizeMotion(e); if (-1 != rs) { _gi.OnResize(sender, e, _resize, rs); } else if (!ignore_action) { float d = Forms.Context.ApplicationContext.Resources.DisplayMetrics.Density; float deltaX = _tapedX - e.Event.RawX; float deltaY = _tapedY - e.Event.RawY; cancelBase = _gi.OnMove(sender, e, deltaX / d, deltaY / d); } } _detector.OnTouchEvent(e.Event); }