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); }
public static Android.Graphics.Point LocationInNativeCoord(this Android.Views.View view) { var p = new int[2]; view.GetLocationOnScreen(p); return(new Android.Graphics.Point(p[0], p[1])); }
void CheckForBoundaryHop(int id, Point pointerLocation) { TouchEffect touchEffectHit = null; foreach (Android.Views.View view in viewDictionary.Keys) { // Get the view rectangle try { view.GetLocationOnScreen(twoIntArray); } catch // System.ObjectDisposedException: Cannot access a disposed object. { continue; } Rectangle viewRect = new Rectangle(twoIntArray[0], twoIntArray[1], view.Width, view.Height); if (viewRect.Contains(pointerLocation)) { touchEffectHit = viewDictionary[view]; } } if (touchEffectHit != idToEffectDictionary[id]) { if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Exited, pointerLocation, true); } if (touchEffectHit != null) { FireEvent(touchEffectHit, id, TouchActionType.Entered, pointerLocation, true); } idToEffectDictionary[id] = touchEffectHit; } }
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); }
// Fix for "CloseWhenBackgroundIsClicked not works on Android with Xamarin.Forms 2.4.0.280" #173 private bool IsInRegion(float x, float y, View v) { var mCoordBuffer = new int[2]; v.GetLocationOnScreen(mCoordBuffer); return(mCoordBuffer[0] + v.Width > x && // right edge mCoordBuffer[1] + v.Height > y && // bottom edge mCoordBuffer[0] < x && // left edge mCoordBuffer[1] < y); // top edge }
private void OnTouch(object sender, Android.Views.View.TouchEventArgs args) { gestureRecognizer?.OnTouchEvent(args.Event); // Two object common to all the events Android.Views.View senderView = sender as Android.Views.View; MotionEvent motionEvent = args.Event; // Get the pointer index int pointerIndex = motionEvent.ActionIndex; // Get the id that identifies a finger over the course of its progress int id = motionEvent.GetPointerId(pointerIndex); senderView.GetLocationOnScreen(twoIntArray); Point screenPointerCoords = new Point( twoIntArray[0] + motionEvent.GetX(pointerIndex), twoIntArray[1] + motionEvent.GetY(pointerIndex)); // Use ActionMasked here rather than Action to reduce the number of possibilities switch (args.Event.ActionMasked) { case MotionEventActions.Down: case MotionEventActions.PointerDown: FireEvent(this, id, TouchActionType.Pressed, screenPointerCoords, true); break; case MotionEventActions.Up: case MotionEventActions.Pointer1Up: FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false); break; case MotionEventActions.Cancel: FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false); break; } }
void OnTouch(object sender, Android.Views.View.TouchEventArgs args) { // Two object common to all the events Android.Views.View senderView = sender as Android.Views.View; MotionEvent motionEvent = args.Event; // Get the pointer index int pointerIndex = motionEvent.ActionIndex; // Get the id that identifies a finger over the course of its progress int id = motionEvent.GetPointerId(pointerIndex); senderView.GetLocationOnScreen(twoIntArray); List <Point> points = new List <Point>(); for (int i = 0; i < motionEvent.PointerCount; i++) { Point screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(i), twoIntArray[1] + motionEvent.GetY(i)); points.Add(screenPointerCoords); } // Use ActionMasked here rather than Action to reduce the number of possibilities switch (args.Event.ActionMasked) { case MotionEventActions.Down: case MotionEventActions.PointerDown: FireEvent(this, id, TouchActionType.Pressed, points, true); idToEffectDictionary.Add(id, this); _capture = _pclTouchEffect.Capture; break; case MotionEventActions.Move: // Multiple Move events are bundled, so handle them in a loop for (pointerIndex = 0; pointerIndex < motionEvent.PointerCount; pointerIndex++) { id = motionEvent.GetPointerId(pointerIndex); if (_capture) { FireEvent(this, id, TouchActionType.Moved, points, true); } else { CheckForBoundaryHop(id, points); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Moved, points, true); } } } break; case MotionEventActions.Up: case MotionEventActions.Pointer1Up: if (_capture) { FireEvent(this, id, TouchActionType.Released, points, false); } else { CheckForBoundaryHop(id, points); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Released, points, false); } } idToEffectDictionary.Remove(id); break; case MotionEventActions.Cancel: if (_capture) { FireEvent(this, id, TouchActionType.Cancelled, points, false); } else { if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Cancelled, points, false); } } idToEffectDictionary.Clear(); break; } }
private static Rect CalculateAnchorRect(View anchor) { var location = new int[2]; anchor.GetLocationOnScreen(location); return new Rect(location[0], location[1], location[0] + anchor.Width, location[1] + anchor.Height); }
void OnTouch(object sender, Android.Views.View.TouchEventArgs args) { // Two object common to all the events Android.Views.View senderView = sender as Android.Views.View; MotionEvent motionEvent = args.Event; // Don't set as Handled to allow event propagation to child for ListView (ItemsView<Cell>) and CarouselView, CollectionView (ItemsView) if ((Element is ItemsView <Cell>) || (Element is ItemsView)) { args.Handled = false; } // Get the pointer index int pointerIndex = motionEvent.ActionIndex; // Get the id that identifies a finger over the course of its progress int id = motionEvent.GetPointerId(pointerIndex); senderView.GetLocationOnScreen(twoIntArray); Point screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex), twoIntArray[1] + motionEvent.GetY(pointerIndex)); // Use ActionMasked here rather than Action to reduce the number of possibilities switch (args.Event.ActionMasked) { case MotionEventActions.Down: case MotionEventActions.PointerDown: FireEvent(this, id, TouchActionType.Pressed, screenPointerCoords, true); if (!idToEffectDictionary.ContainsKey(id)) { idToEffectDictionary.Add(id, this); } capture = libTouchEffect.Capture; break; case MotionEventActions.Move: // Multiple Move events are bundled, so handle them in a loop for (pointerIndex = 0; pointerIndex < motionEvent.PointerCount; pointerIndex++) { id = motionEvent.GetPointerId(pointerIndex); if (capture) { senderView.GetLocationOnScreen(twoIntArray); screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex), twoIntArray[1] + motionEvent.GetY(pointerIndex)); FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true); } else { CheckForBoundaryHop(id, screenPointerCoords); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Moved, screenPointerCoords, true); } } } break; case MotionEventActions.Up: case MotionEventActions.Pointer1Up: if (capture) { FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false); } else { CheckForBoundaryHop(id, screenPointerCoords); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Released, screenPointerCoords, false); } } idToEffectDictionary.Remove(id); break; case MotionEventActions.Cancel: if (capture) { FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false); } else { if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Cancelled, screenPointerCoords, false); } } idToEffectDictionary.Remove(id); break; } }
private bool IsPointInsideView (float x, float y, View view) { var location = new int[2]; view.GetLocationOnScreen (location); int viewX = location [0]; //point is inside view bounds if (x > viewX && x < (viewX + view.Width)) { return true; } return false; }
void OnTouch(object sender, Android.Views.View.TouchEventArgs args) { // Two object common to all the events Android.Views.View senderView = sender as Android.Views.View; MotionEvent motionEvent = args.Event; // Get the pointer index int pointerIndex = motionEvent.ActionIndex; // Get the id that identifies a finger over the course of its progress int id = motionEvent.GetPointerId(pointerIndex); senderView.GetLocationOnScreen(twoIntArray); Point screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex), twoIntArray[1] + motionEvent.GetY(pointerIndex)); // Use ActionMasked here rather than Action to reduce the number of possibilities switch (args.Event.ActionMasked) { case MotionEventActions.Down: case MotionEventActions.PointerDown: FireEvent(this, id, TouchActionType.Pressed, screenPointerCoords, true); // BUG FIXING: added a check for ContainsKey because id=0 was occasionally added multiple times resulting in an untrappable IllegalArgument exception in external Thread if (!idToEffectDictionary.ContainsKey(id)) // hoping for the best { idToEffectDictionary.Add(id, this); } capture = libTouchEffect.Capture; break; case MotionEventActions.Move: // Multiple Move events are bundled, so handle them in a loop for (pointerIndex = 0; pointerIndex < motionEvent.PointerCount; pointerIndex++) { id = motionEvent.GetPointerId(pointerIndex); if (capture) { senderView.GetLocationOnScreen(twoIntArray); screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex), twoIntArray[1] + motionEvent.GetY(pointerIndex)); FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true); } else { CheckForBoundaryHop(id, screenPointerCoords); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Moved, screenPointerCoords, true); } } } break; case MotionEventActions.Up: case MotionEventActions.Pointer1Up: if (capture) { FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false); } else { CheckForBoundaryHop(id, screenPointerCoords); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Released, screenPointerCoords, false); } } idToEffectDictionary.Remove(id); break; case MotionEventActions.Cancel: if (capture) { FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false); } else { if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Cancelled, screenPointerCoords, false); } } idToEffectDictionary.Remove(id); break; } }
//******************************************************************** // STATIC METHODS //******************************************************************** /** * Get the Rect frame for a view (relative to the Window of the application) * @param v The view to get the rect from * @return The rect of the view, relative to the application window */ public static Rect getFrameForView (View v) { int[] location = new int [2]; v.GetLocationOnScreen (location); Rect viewRect = new Rect (location [0], location [1], location [0] + v.Width, location [1] + v.Height); return viewRect; }
void OnTouch(object sender, Android.Views.View.TouchEventArgs args) { // Two object common to all the events Android.Views.View senderView = sender as Android.Views.View; MotionEvent motionEvent = args.Event; // Get the pointer index int pointerIndex = motionEvent.ActionIndex; // Get the id that identifies a finger over the course of its progress int id = motionEvent.GetPointerId(pointerIndex); senderView.GetLocationOnScreen(twoIntArray); Point screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex), twoIntArray[1] + motionEvent.GetY(pointerIndex)); // Use ActionMasked here rather than Action to reduce the number of possibilities switch (args.Event.ActionMasked) { case MotionEventActions.Down: case MotionEventActions.PointerDown: FireEvent(this, id, TouchActionType.Pressed, screenPointerCoords, true); if (!idToEffectDictionary.ContainsKey(id)) { idToEffectDictionary.Add(id, this); } capture = libTouchEffect.Capture; break; case MotionEventActions.Move: // Multiple Move events are bundled, so handle them in a loop for (pointerIndex = 0; pointerIndex < motionEvent.PointerCount; pointerIndex++) { id = motionEvent.GetPointerId(pointerIndex); if (capture) { senderView.GetLocationOnScreen(twoIntArray); screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex), twoIntArray[1] + motionEvent.GetY(pointerIndex)); FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true); } else { CheckForBoundaryHop(id, screenPointerCoords); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Moved, screenPointerCoords, true); } } } break; case MotionEventActions.Up: case MotionEventActions.Pointer1Up: if (capture) { FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false); } else { CheckForBoundaryHop(id, screenPointerCoords); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Released, screenPointerCoords, false); } } idToEffectDictionary.Remove(id); break; case MotionEventActions.Cancel: if (capture) { FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false); } else { if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Cancelled, screenPointerCoords, false); } } idToEffectDictionary.Remove(id); break; } // Used to debug gesture types //Console.WriteLine("Number of ids in idToEffectDictionary: ", idToEffectDictionary.Count); //Console.WriteLine("Motion Event Type: {0}", args.Event.ActionMasked); //foreach (var dictId in idToEffectDictionary) //{ // Console.WriteLine("ID: {0}\t Effect: {1}", dictId.Key, dictId.Value); //} }
Rect GetAnchorRectangle(View view) { var location = new int[2]; view.GetLocationOnScreen(location); var anchorRect = new Rect(location[0], location[1], location[0] + view.Width, location[1] + view.Height); return anchorRect; }
private void OnTouch(object sender, Android.Views.View.TouchEventArgs args) { // Two object common to all the events Android.Views.View senderView = sender as Android.Views.View; MotionEvent motionEvent = args.Event; // Get the pointer index int pointerIndex = motionEvent.ActionIndex; // Get the id that identifies a finger over the course of its progress int id = motionEvent.GetPointerId(pointerIndex); senderView.GetLocationOnScreen(twoIntArray); Point screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex), twoIntArray[1] + motionEvent.GetY(pointerIndex)); // Use ActionMasked here rather than Action to reduce the number of possibilities switch (args.Event.ActionMasked) { case MotionEventActions.Down: case MotionEventActions.PointerDown: Console.WriteLine("GridBuuttonRenderer"); //CrossWordDrawLineViewModel.touchPressed = new SKPoint(twoIntArray[0] + motionEvent.GetX(pointerIndex), //twoIntArray[1] + motionEvent.GetY(pointerIndex)); CrossWordDrawLineViewModel.changeLineColor = false; CrossWordDrawLineViewModel.changeLineColorMethod(); CrossWordDrawLineViewModel.touchPressed = GetPressedViewCenterPoint(senderView); FireEvent(this, id, TouchActionType.Pressed, screenPointerCoords, true); idToEffectDictionary.Add(id, this); capture = libTouchEffect.Capture; break; case MotionEventActions.Move: // Multiple Move events are bundled, so handle them in a loop for (pointerIndex = 0; pointerIndex < motionEvent.PointerCount; pointerIndex++) { id = motionEvent.GetPointerId(pointerIndex); if (capture) { senderView.GetLocationOnScreen(twoIntArray); screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex), twoIntArray[1] + motionEvent.GetY(pointerIndex)); FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true); } else { CrossWordDrawLineViewModel.changeLineColor = false; CheckForBoundaryHop(id, screenPointerCoords); new MessageCenterHelper().SendMessageMenu(null); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Moved, screenPointerCoords, true); } } } break; case MotionEventActions.Up: case MotionEventActions.Pointer1Up: if (capture) { FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false); } else { CheckForBoundaryHop(id, screenPointerCoords); //CrossWordDrawLineViewModel.touchReleased = new SKPoint((float)screenPointerCoords.X, (float)screenPointerCoords.Y); CrossWordDrawLineViewModel.changeLineColor = false; new MessageCenterHelper().SendMessageMenu(null); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Released, screenPointerCoords, false); } } idToEffectDictionary.Remove(id); break; case MotionEventActions.Cancel: if (capture) { FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false); } else { if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Cancelled, screenPointerCoords, false); } } idToEffectDictionary.Remove(id); break; } }
private void OnTouch(object obj, Android.Views.View.TouchEventArgs ev) { Android.Views.View senderView = obj as Android.Views.View; senderView.GetLocationOnScreen(twoIntArray); // タップポインターのID int actID = ev.Event.ActionIndex; // タップした指を識別するID int pointID = ev.Event.GetPointerId(actID); // 相対座標を取得する場合 float x = ev.Event.GetX(actID); float y = ev.Event.GetY(actID); // 絶対座標を取得する場合 float x_Raw = ev.Event.RawX; float y_Raw = ev.Event.RawY; Point screenPointerCoords = new Point(x_Raw, y_Raw); DragDrop.View.MyEffect.TouchEventArgs args; switch (ev.Event.Action) { case MotionEventActions.ButtonPress: case MotionEventActions.Down: case MotionEventActions.PointerDown: if (!idToEffectDictionary.ContainsKey(pointID)) { idToEffectDictionary.Add(pointID, this); FireEvent(this, pointID, View.MyEffect.TouchEventArgs.TouchEventType.Pressed, screenPointerCoords, true); } break; case MotionEventActions.ButtonRelease: case MotionEventActions.Up: case MotionEventActions.Pointer1Up: if (idToEffectDictionary[pointID] != null) { FireEvent(this, pointID, View.MyEffect.TouchEventArgs.TouchEventType.Released, screenPointerCoords, false); idToEffectDictionary.Remove(pointID); } break; case MotionEventActions.Move: // Moveイベントは複数同時に取得されるため、ループで処理する for (var i = 0; i < ev.Event.PointerCount; i++) { pointID = ev.Event.GetPointerId(actID); if (idToEffectDictionary[pointID] != null) { FireEvent(this, pointID, View.MyEffect.TouchEventArgs.TouchEventType.Moved, screenPointerCoords, true); } } break; case MotionEventActions.Cancel: if (idToEffectDictionary[pointID] != null) { FireEvent(this, pointID, View.MyEffect.TouchEventArgs.TouchEventType.Released, screenPointerCoords, false); } idToEffectDictionary.Remove(pointID); break; } }