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 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); }
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 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); }
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); }
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)); }
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); }
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); } }
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 void GetPointerCoords(int pointerIndex, MotionEvent.PointerCoords outPointerCoords) { MotionEvent.GetPointerCoords(pointerIndex, outPointerCoords); }
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); }
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); } }