// Check touch position on button public bool OnTouch(View v, MotionEvent e) { switch (e.Action) { // Get the x and y position for a touch (always before move) case MotionEventActions.Down: old_x = e.GetX (); old_y = e.GetY (); Console.WriteLine ("x = " + old_x + " y = " + old_y); break; // Get the x and y position difference continously case MotionEventActions.Move: // Get the difference between current position and old position new_x = e.GetX () - old_x; new_y = e.GetY () - old_y; // Convert to int, to remove decimal numbers (apparently can't be send through the tcp listener) int_x = Convert.ToInt32 (new_x); int_y = Convert.ToInt32 (new_y); // Convert to string, so it can be send send_x = Convert.ToString (int_x); send_y = Convert.ToString (int_y); // Send x and y position over two messages Connect (ipAddress, send_x); Connect (ipAddress, send_y); // Set old position to current position old_x = e.GetX (); old_y = e.GetY (); break; } return true; }
private static float CalculateRotation(MotionEvent motionEvent) { double deltaX = (motionEvent.GetX(0) - motionEvent.GetX(1)); double deltaY = (motionEvent.GetY(0) - motionEvent.GetY(1)); var radians = Math.Atan2(deltaY, deltaX); return (float) ToDegrees(radians); }
protected internal override void UpdateStateByEvent(MotionEvent curr) { base.UpdateStateByEvent(curr); MotionEvent prev = mPrevEvent; mCurrLen = -1; mPrevLen = -1; // Previous float px0 = prev.GetX(0); float py0 = prev.GetY(0); float px1 = prev.GetX(1); float py1 = prev.GetY(1); float pvx = px1 - px0; float pvy = py1 - py0; mPrevFingerDiffX = pvx; mPrevFingerDiffY = pvy; // Current float cx0 = curr.GetX(0); float cy0 = curr.GetY(0); float cx1 = curr.GetX(1); float cy1 = curr.GetY(1); float cvx = cx1 - cx0; float cvy = cy1 - cy0; mCurrFingerDiffX = cvx; mCurrFingerDiffY = cvy; }
public override bool OnTouchEvent (MotionEvent e) { if (e.Action == MotionEventActions.Move) { if (oldX == 0) { oldX = (int)e.GetX (); } if (oldY == 0) { oldY = (int)e.GetY (); } newX = (int)e.GetX (); newY = (int)e.GetY (); if (newY > oldY + buffer) { CurrentDirection = DirectionUp; } else if (newY + buffer < oldY) { CurrentDirection = DirectionDown; } else { CurrentDirection = DirectionNone; } if (newY > oldY + buffer) { oldY = (int)e.GetY (); } if (newY + buffer < oldY) { oldY = (int)e.GetY (); } oldX = (int)e.GetX (); } else if (e.Action == MotionEventActions.Up) { oldX = 0; oldY = 0; } return base.OnTouchEvent (e); }
public bool Detect(MotionEvent e) { switch (e.Action) { case MotionEventActions.Down: this.startX = e.GetX(); this.startY = e.GetY(); this.tapPossiable = true; break; case MotionEventActions.Move: if (this.tapPossiable) { if (Math.Abs(e.GetX() - this.startX) > this.slop || Math.Abs(e.GetY() - this.startY) > this.slop) { this.tapPossiable = false; } } break; case MotionEventActions.Up: if (this.tapPossiable && e.EventTime - e.DownTime < tapTimeout) { ((ITapableView)this.owner).WrapedNativeRaiseTap(); } break; } return false; }
public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // Swipe left if (e1.GetX() > e2.GetX()) { Console.WriteLine("Left"); _id++; if (_id == _point.Count) { _id = 0; } } // Swipe right else if (e2.GetX() > e1.GetX()) { Console.WriteLine("Right"); _id--; if (_id < 0) { _id = _point.Count - 1; } } _webview.LoadUrl("file://" + ThisApp.GetEPUBPage(ThisApp.Language, "w_E_20130315", _point[_id].Source).Path); return base.OnFling(e1, e2, velocityX, velocityY); }
/// <summary> /// Updates the current state with the given event. /// </summary> /// <param name="curr">The current event.</param> protected override void UpdateStateByEvent (MotionEvent curr) { base.UpdateStateByEvent (curr); MotionEvent prev = _previousEvent; _currLen = -1; _prevLen = -1; if (prev != null && prev.PointerCount > 1 && curr.PointerCount > 1) { // previous float px0 = prev.GetX (0); float py0 = prev.GetY (0); float px1 = prev.GetX (1); float py1 = prev.GetY (1); float pvx = px1 - px0; float pvy = py1 - py0; _prevFingerDiffX = pvx; _prevFingerDiffY = pvy; // current float cx0 = curr.GetX (0); float cy0 = curr.GetY (0); float cx1 = curr.GetX (1); float cy1 = curr.GetY (1); float cvx = cx1 - cx0; float cvy = cy1 - cy0; _currFingerDiffX = cvx; _currFingerDiffY = cvy; } }
public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if ( Math.Abs ( e1.GetY () - e2.GetY () ) > SWIPE_MAX_OFF_PATH ) return false; // right to left swipe if ( e1.GetX () - e2.GetX () > SWIPE_MIN_DISTANCE && Math.Abs ( velocityX ) > SWIPE_THRESHOLD_VELOCITY && LeftEvent != null ) { RightEvent (); } else if ( e2.GetX () - e1.GetX () > SWIPE_MIN_DISTANCE && Math.Abs ( velocityX ) > SWIPE_THRESHOLD_VELOCITY && RightEvent != null ) { if(e1.GetX()<100) { Console.WriteLine("e1.GetX() : "+ e1.GetX()); Console.WriteLine("e2.GetX() : "+ e2.GetX()); LeftEvent (); } } } catch ( Exception e ) { Console.WriteLine ( "Gesture listener didn't worked properly..." +e.Message); } return false; }
public bool OnFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // Right to left swipe if (e1.GetX() - e2.GetX() > MinSwipeDistance && Math.Abs(velocityX) > SwipeThreadsholdVelocity) { if (_page.CaptureSwipeRightToLeft) _page.OnSwipeRightToLeft (); } // Left to right swipe else if (e2.GetX() - e1.GetX() > MinSwipeDistance && Math.Abs(velocityX) > SwipeThreadsholdVelocity) { if (_page.CaptureSwipeLeftToRight) _page.OnSwipeLeftToRight (); } if (e1.GetY() - e2.GetY() > MinSwipeDistance && Math.Abs(velocityY) > SwipeThreadsholdVelocity) { if (_page.CaptureSwipeBottomToTop) _page.OnSwipeBottomToTop (); } // Left to right swipe else if (e2.GetY() - e1.GetY() > MinSwipeDistance && Math.Abs(velocityY) > SwipeThreadsholdVelocity) { if (_page.CaptureSwipeTopToBottom) _page.OnSwipeTopToBottom (); } return true; }
public override float GetActiveX(MotionEvent ev) { try { return ev.GetX(mActivePointerIndex); } catch (Exception e) { return ev.GetX(); } }
private static float GetRotation(MotionEvent e) { var deltaX = e.GetX(0) - e.GetX(1); var deltaY = e.GetY(0) - e.GetY(1); var radians = (float)Math.Atan2(deltaY, deltaX); return MathHelper.RadiansToDegrees(radians); }
public bool OnDown(MotionEvent e) { State = GestureRecognizerState.Began; _currentTranslation = new Xamarin.Forms.Point (e.GetX (), e.GetY ()); _currentPoint = new Xamarin.Forms.Point (e.GetX (), e.GetY ()); _previousPoint = new Xamarin.Forms.Point (e.GetX (), e.GetY ()); OnGesture (); return true; }
public override bool OnTouchEvent (MotionEvent ev) { _scaleDetector.OnTouchEvent (ev); MotionEventActions action = ev.Action & MotionEventActions.Mask; int pointerIndex; switch (action) { case MotionEventActions.Down: _lastTouchX = ev.GetX (); _lastTouchY = ev.GetY (); _activePointerId = ev.GetPointerId (0); break; case MotionEventActions.Move: pointerIndex = ev.FindPointerIndex (_activePointerId); float x = ev.GetX (pointerIndex); float y = ev.GetY (pointerIndex); if (!_scaleDetector.IsInProgress) { // Only move the ScaleGestureDetector isn't already processing a gesture. float deltaX = x - _lastTouchX; float deltaY = y - _lastTouchY; _posX += deltaX; _posY += deltaY; Invalidate (); } _lastTouchX = x; _lastTouchY = y; break; case MotionEventActions.Up: case MotionEventActions.Cancel: // This events occur when something cancels the gesture (for example the // activity going in the background) or when the pointer has been lifted up. // We no longer need to keep track of the active pointer. _activePointerId = InvalidPointerId; break; case MotionEventActions.PointerUp: // We only want to update the last touch position if the the appropriate pointer // has been lifted off the screen. pointerIndex = (int)(ev.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift; int pointerId = ev.GetPointerId (pointerIndex); if (pointerId == _activePointerId) { // This was our active pointer going up. Choose a new // action pointer and adjust accordingly int newPointerIndex = pointerIndex == 0 ? 1 : 0; _lastTouchX = ev.GetX (newPointerIndex); _lastTouchY = ev.GetY (newPointerIndex); _activePointerId = ev.GetPointerId (newPointerIndex); } break; } return true; }
public override bool OnTouchEvent(MotionEvent e) { switch (e.Action) { case MotionEventActions.Down: lastX = e.GetX (); lastY = e.GetY (); break; case MotionEventActions.Up: var diffX = Math.Abs (e.GetX () - lastX); var diffY = Math.Abs (e.GetY () - lastY); if (diffX > diffY) { if (diffX > 100) { if (ScaleX == 1.0f) { this.Animate ().ScaleX (0.0f).WithEndAction (new Java.Lang.Runnable (() => { textView.Text = cards.Card[counter].Foreign[0].ItemElement.Text; this.Animate ().ScaleX (0.999f); })); } else this.Animate ().ScaleX (0.0f).WithEndAction (new Java.Lang.Runnable (() => { textView.Text = cards.Card[counter].Native[0].ItemElement.Text; this.Animate ().ScaleX (1.00f); })); } } else { this.Animate ().ScaleX (0f); this.Animate ().ScaleY (0f); this.Animate ().Alpha (0f).WithEndAction (new Java.Lang.Runnable (() => { counter++; if (counter < cards.Card.Count) { levelView.Level = cards.Card [counter].Level; textView.Text = cards.Card[counter].Native[0].ItemElement.Text; this.TranslationY = 0.0f; this.ScaleX = 0.0f; this.ScaleY = 0.0f; this.Alpha = 1.0f; this.Animate ().ScaleX (1.0f); this.Animate ().ScaleY (1.0f); } })); if (e.GetY () - lastY > 0) { cards.Card [counter].Level++; this.Animate ().TranslationYBy (1000f); } else { cards.Card [counter].Level = 0; this.Animate ().TranslationYBy (-1000f); } } break; default: break; } return true;// base.OnTouchEvent (e); }
/** * When the user swipes their finger horizontally, dispatch * those touch events to the ViewPager. When they swipe * vertically, dispatch those touch events to the date or * time picker (depending on which page we're currently on). * * @param event */ public override bool DispatchTouchEvent (MotionEvent e) { switch (e.Action) { case MotionEventActions.Down: _x1 = e.GetX(); _y1 = e.GetY(); break; case MotionEventActions.Move: _x2 = e.GetX(); _y2 = e.GetY(); if (isScrollingHorizontal(_x1, _y1, _x2, _y2)) { // When the user is scrolling the ViewPager horizontally, // block the pickers from scrolling vertically. return base.DispatchTouchEvent(e); } break; } // As long as the ViewPager isn't scrolling horizontally, // dispatch the event to the DatePicker or TimePicker, // depending on which page the ViewPager is currently on. switch (CurrentItem) { case 0: if (_datePicker != null) _datePicker.DispatchTouchEvent(e); break; case 1: if (_timePicker != null) _timePicker.DispatchTouchEvent(e); break; } // need this for the ViewPager to scroll horizontally at all return base.DispatchTouchEvent (e); }
public override bool OnTouchEvent (MotionEvent event1) { Console.WriteLine ("touch event"); float x = event1.GetX (); float y = event1.GetY (); switch (event1.Action) { case MotionEventActions.Down: drawPath.MoveTo (x, y); break; case MotionEventActions.Move: drawPath.LineTo (x, y); break; case MotionEventActions.Up: drawCanvas.DrawPath (drawPath, drawPaint); drawPath.Reset (); break; default: return false; } Invalidate (); return true; }
private void AndroidMap_MapSingleTap(object sender, Android.Views.MotionEvent e) { PointF location = new PointF(e.GetX(), e.GetY()); PointShape position = ExtentHelper.ToWorldCoordinate(androidMap.CurrentExtent, location.X, location.Y, androidMap.Width, androidMap.Height); longitudeLabelView.Text = string.Format("Longitude : {0:N4}", position.X); latitudeLabelView.Text = string.Format("Latitude : {0:N4}", position.Y); LayerOverlay worldOverlay = (LayerOverlay)androidMap.Overlays["WorldOverlay"]; FeatureLayer worldLayer = (FeatureLayer)worldOverlay.Layers["WorldLayer"]; LayerOverlay highlightOverlay = (LayerOverlay)androidMap.Overlays["HighlightOverlay"]; InMemoryFeatureLayer highlightLayer = (InMemoryFeatureLayer)highlightOverlay.Layers["HighlightLayer"]; worldLayer.Open(); Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(position, new string[1] { "CNTRY_NAME" }); worldLayer.Close(); highlightLayer.Open(); highlightLayer.InternalFeatures.Clear(); if (selectedFeatures.Count > 0) { highlightLayer.InternalFeatures.Add(selectedFeatures[0]); } highlightLayer.Close(); highlightOverlay.Refresh(); }
public override bool OnTouchEvent(MotionEvent ev) { MotionEventActions action = ev.Action; switch (action & MotionEventActions.Mask) { case MotionEventActions.Down: mActivePointerId = ev.GetPointerId(0); break; case MotionEventActions.Cancel: case MotionEventActions.Up: mActivePointerId = INVALID_POINTER_ID; break; case MotionEventActions.PointerUp: // Ignore deprecation, ACTION_POINTER_ID_MASK and // ACTION_POINTER_ID_SHIFT has same value and are deprecated // You can have either deprecation or lint target api warning int pointerIndex = Compat.GetPointerIndex(ev.Action); int pointerId = ev.GetPointerId(pointerIndex); if (pointerId == mActivePointerId) { // This was our active pointer going up. Choose a new // active pointer and adjust accordingly. int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = ev.GetPointerId(newPointerIndex); mLastTouchX = ev.GetX(newPointerIndex); mLastTouchY = ev.GetY(newPointerIndex); } break; } mActivePointerIndex = ev .FindPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0); return base.OnTouchEvent(ev); }
public bool OnTouch(View v, MotionEvent e) { switch (e.Action) { case MotionEventActions.Down: _viewX = e.GetX (); _viewY = e.GetY (); break; case MotionEventActions.Move: var left = (int)(e.RawX - _viewX); var right = (int)(left + v.Width); var top = (int)(e.RawY - _viewY); var bottom = (int)(v.Height + top); Console.WriteLine (left); Console.WriteLine (v.Width); if (left == v.Width-40) { // TextView tv=new TextView(GetApplicationContext()); // tv.SetText("Avoided call with ex!"); // Resource.Layout.exDragGame AddView(tv); Console.WriteLine ("hit the edge"); } v.Layout (left, top, right, bottom); // Console.WriteLine (" L " + left + " R " + right + " T " + top + " B " + bottom); break; } return true; }
public override bool OnTouchEvent(MotionEvent e) { //detect any flings this.mDetector.OnTouchEvent(e); //find the action, get the percent and send to the right master detail int action = MotionEventCompat.GetActionMasked(e); float percent = 1 - ((Width - e.GetX()) / Width); switch (e.Action) { case MotionEventActions.Down: ((MyMasterDetailPage)Element).doDown(percent); break; case MotionEventActions.Up: ((MyMasterDetailPage)Element).doUp(percent); break; case MotionEventActions.Move: ((MyMasterDetailPage)Element).doMove(percent); break; default: break; } return base.OnTouchEvent(e); }
private void AndroidMap_MapSingleTap(object sender, Android.Views.MotionEvent e) { PointF location = new PointF(e.GetX(), e.GetY()); PointShape position = ExtentHelper.ToWorldCoordinate(androidMap.CurrentExtent, location.X, location.Y, androidMap.Width, androidMap.Height); LayerOverlay worldOverlay = (LayerOverlay)androidMap.Overlays["WorldOverlay"]; FeatureLayer worldLayer = (FeatureLayer)worldOverlay.Layers["WorldLayer"]; LayerOverlay highlightOverlay = (LayerOverlay)androidMap.Overlays["HighlightOverlay"]; InMemoryFeatureLayer highlightLayer = (InMemoryFeatureLayer)highlightOverlay.Layers["HighlightLayer"]; worldLayer.Open(); Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(position, new string[1] { "CNTRY_NAME" }); worldLayer.Close(); highlightLayer.Open(); highlightLayer.InternalFeatures.Clear(); if (selectedFeatures.Count > 0) { AreaBaseShape areaShape = (AreaBaseShape)selectedFeatures[0].GetShape(); double area = areaShape.GetArea(GeographyUnit.DecimalDegree, AreaUnit.SquareKilometers); messageTextView.Text = string.Format(CultureInfo.InvariantCulture, "{0} has an area of {1:N0} square kilometers.", selectedFeatures[0].ColumnValues["CNTRY_NAME"].Trim(), area); highlightLayer.InternalFeatures.Add(selectedFeatures[0]); } highlightLayer.Close(); highlightOverlay.Refresh(); }
private void AndroidMapMapSingleTap(object sender, Android.Views.MotionEvent e) { PointF location = new PointF(e.GetX(), e.GetY()); PointShape position = ExtentHelper.ToWorldCoordinate(androidMap.CurrentExtent, location.X, location.Y, androidMap.Width, androidMap.Height); LayerOverlay overlay = androidMap.Overlays["RoadOverlay"] as LayerOverlay; FeatureLayer roadLayer = overlay.Layers["TXlkaA40"] as FeatureLayer; LayerOverlay highlightOverlay = androidMap.Overlays["HighlightOverlay"] as LayerOverlay; InMemoryFeatureLayer highlightLayer = (InMemoryFeatureLayer)highlightOverlay.Layers["HighlightLayer"]; roadLayer.Open(); Collection <Feature> selectedFeatures = roadLayer.QueryTools.GetFeaturesNearestTo(position, GeographyUnit.DecimalDegree, 1, new string[1] { "fename" }); roadLayer.Close(); if (selectedFeatures.Count > 0) { LineBaseShape lineShape = (LineBaseShape)selectedFeatures[0].GetShape(); highlightLayer.Open(); highlightLayer.InternalFeatures.Clear(); highlightLayer.InternalFeatures.Add(new Feature(lineShape)); highlightLayer.Close(); double length = lineShape.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Meter); string lengthMessage = string.Format(CultureInfo.InvariantCulture, "{0} has a length of {1:F2} meters.", selectedFeatures[0].ColumnValues["fename"].Trim(), length); messageLabel.Text = lengthMessage; highlightOverlay.Refresh(); } }
/*protected override void OnDraw (Canvas canvas) { base.OnDraw (canvas); paint.SetStyle(Paint.Style.Stroke); canvas.DrawCircle(point.X, point.Y, 50, paint); }*/ public override bool OnTouchEvent (MotionEvent e) { if(e.Action == MotionEventActions.Move) { if (surfaceHolder.Surface.IsValid) { point.X = (int)e.GetX(); point.Y = (int)e.GetY(); Console.WriteLine("X " + point.X + " Y " + point.Y); //Invalidate(); //return true; Canvas canvas = surfaceHolder.LockCanvas(); canvas.DrawColor(Color.Black); canvas.DrawCircle(point.X, point.Y, 60, paint); surfaceHolder.UnlockCanvasAndPost(canvas); } } if(e.Action == MotionEventActions.Up) { if (surfaceHolder.Surface.IsValid) { Canvas canvas = surfaceHolder.LockCanvas(); canvas.DrawColor(Color.Black); //canvas.DrawCircle(point.X, point.Y, 100, paint); surfaceHolder.UnlockCanvasAndPost(canvas); } } return true; }
public override bool OnTouchEvent(MotionEvent e) { var touchX = e.GetX(); var touchY = e.GetY(); switch (e.Action) { case MotionEventActions.Down: DrawPath.MoveTo(touchX, touchY); break; case MotionEventActions.Move: DrawPath.LineTo(touchX, touchY); break; case MotionEventActions.Up: DrawCanvas.DrawPath(DrawPath, DrawPaint); DrawPath.Reset(); break; default: return false; } Invalidate(); return true; }
public override bool OnTouchEvent(MotionEvent e) { bool returnValue = base.OnTouchEvent(e); // Get the touch position int x = ((int) e.GetX())/(_blockSize * 5 + StrokeWidthBorder); int y = ((int) e.GetY())/(_blockSize * 5 + StrokeWidthBorder); // Lower the value if it is too high if(x >= Constants.NbProposedPiece/Constants.NbLinePropPiece) { x = Constants.NbProposedPiece/Constants.NbLinePropPiece - 1; } if(y >= Constants.NbLinePropPiece) { y = Constants.NbLinePropPiece - 1; } // Get the piece number int i = x + y * _nbPieceByLine; if(i >= Constants.NbProposedPiece) { i = Constants.NbProposedPiece - 1; } // Select the piece selectPiece(i); Invalidate(); return returnValue; }
public override bool OnSingleTapConfirmed (MotionEvent e) { b.touchPoint = new Point ((int)e.GetX (), (int)e.GetY ()); CommonSampleLibrary.Log.Debug (TAG, "Single tap captured."); b.Toggle (); return true; }
public override bool OnDoubleTap(MotionEvent e) { Console.WriteLine("sadfssdf"); m_ScaleImageView.MaxZoomTo((int)e.GetX(), (int)e.GetY()); m_ScaleImageView.Cutting(); return true; }
public override bool OnTouchEvent(MotionEvent e) { var action = e.Action; switch (action) { case MotionEventActions.Down: if (e.GetX() < handle.GetX()) return false; if (currentAnimator != null) currentAnimator.Cancel(); if (bubble.Visibility == ViewStates.Invisible) showBubble(); handle.Selected = true; setPosition(e.GetY()); setRecyclerViewPosition(e.GetY()); return true; case MotionEventActions.Move: setPosition(e.GetY()); setRecyclerViewPosition(e.GetY()); return true; case MotionEventActions.Up: case MotionEventActions.Cancel: handle.Selected = false; hideBubble(); return true; } return base.OnTouchEvent(e); }
public GestureMotionEvent(MotionEvent e) { _cachedAction = e.Action; _cachedX = e.GetX (); _cachedY = e.GetY (); MotionEvent = e; }
public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { float dx = e2.GetX() - e1.GetX(); float dy = e2.GetY() - e1.GetY(); if (Math.Abs((int) dx) <= MINIMUM_MOVEMENT_DISTANCE && Math.Abs((int) dy) <= MINIMUM_MOVEMENT_DISTANCE) return false; Command cmd = null; if (Math.Abs (dx) > Math.Abs (dy)) { if (dx > 0) cmd = new SwipeRightCommand (); else cmd = new SwipeLeftCommand (); } else { if (dy > 0) cmd = new SwipeDownCommand (); else cmd = new SwipeUpCommand (); } if (cmd != null) Easter.AddCommand (cmd); return false; }
public override bool OnTouchEvent(Android.Views.MotionEvent e) { if (GetCompoundDrawables() [2] != null) { if (e.Action == MotionEventActions.Up) { bool touchable = e.GetX() > (Width - PaddingRight - mClearDrawable.IntrinsicWidth) && (e.GetX() < ((Width - PaddingRight))); if (touchable) { this.Text = ""; } } } return(base.OnTouchEvent(e)); }
public override bool OnTouchEvent(MotionEvent e) { float x; if (e.PointerCount == 1) { x = e.GetX(); if (x < _bounds.Left) x = _bounds.Left; if (x > _bounds.Right) x = _bounds.Right; _sliderPositionRaw = new PointF(x, _bounds.CenterY()); _isActive = e.Action == MotionEventActions.Down || e.Action == MotionEventActions.Move; var scaleX = _bounds.Width() / 2f; x = (x - scaleX) * 100f / scaleX; } else if (e.PointerCount == 2) { x = (e.GetX(0) + e.GetX(1)) / 2f; if (x < _bounds.Left) x = _bounds.Left; if (x > _bounds.Right) x = _bounds.Right; _sliderPositionRaw = new PointF(x, _bounds.CenterY()); _isActive = e.Action == MotionEventActions.Down || e.Action == MotionEventActions.Move; var scaleX = _bounds.Width() / 2f; x = (x - scaleX) * 10f / scaleX; } else { _isActive = false; return true; } switch (e.Action) { case MotionEventActions.Down: OnSliderStart(x); break; case MotionEventActions.Up: OnSliderStop(); break; case MotionEventActions.Move: OnSliderMove(x); break; } Invalidate(); return true; }
public void OnTouchEvent(MotionEvent e) { if (!Enabled) return; Vector2 position = Vector2.Zero; position.X = e.GetX(e.ActionIndex); position.Y = e.GetY(e.ActionIndex); UpdateTouchPosition(ref position); int id = e.GetPointerId(e.ActionIndex); switch (e.ActionMasked) { // DOWN case MotionEventActions.Down: case MotionEventActions.PointerDown: TouchPanel.AddEvent(id, TouchLocationState.Pressed, position); break; // UP case MotionEventActions.Up: case MotionEventActions.PointerUp: TouchPanel.AddEvent(id, TouchLocationState.Released, position); break; // MOVE case MotionEventActions.Move: for (int i = 0; i < e.PointerCount; i++) { id = e.GetPointerId(i); position.X = e.GetX(i); position.Y = e.GetY(i); UpdateTouchPosition(ref position); TouchPanel.AddEvent(id, TouchLocationState.Moved, position); } break; // CANCEL, OUTSIDE case MotionEventActions.Cancel: case MotionEventActions.Outside: for (int i = 0; i < e.PointerCount; i++) { id = e.GetPointerId(i); TouchPanel.AddEvent(id, TouchLocationState.Released, position); } break; } }
public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.Abs(e1.GetY() - e2.GetY()) > SWIPE_MAX_OFF_PATH) return false; // right to left swipe if (e1.GetX() - e2.GetX() > SWIPE_MIN_DISTANCE && Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY && LeftEvent != null) LeftEvent();//Toast.MakeText(view.Context, "Left Swipe", ToastLength.Short).Show(); else if (e2.GetX() - e1.GetX() > SWIPE_MIN_DISTANCE && Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY && RightEvent != null) RightEvent();// Toast.MakeText(view.Context, "Right Swipe", ToastLength.Short).Show(); } catch (Exception e) { // nothing } return false; }
public static MouseEventArgs ToEto(av.MotionEvent e) { if (e.Action == av.MotionEventActions.Down) { return(new MouseEventArgs(MouseButtons.Primary, Key.None, new PointF(e.GetX(), e.GetY()))); } // Is this correct? It generates a mouse event for pointer-up and cancel actions // See the iOS handler as well, which does something similar return(new MouseEventArgs(MouseButtons.Primary, Key.None, Point.Empty)); }
public override bool DispatchTouchEvent(Android.Views.MotionEvent e) { int action = MotionEventCompat.GetActionMasked(e); if (StopScrollWhenTouch) { if ((action == (int)MotionEventActions.Down) && isAutoScroll) { isStopByTouch = true; StopAutoScroll(); } else if (e.Action == MotionEventActions.Up && isStopByTouch) { StartAutoScroll(); } } if (SlideBorderMode == SLIDE_BORDER_MODE_TO_PARENT || SlideBorderMode == SLIDE_BORDER_MODE_CYCLE) { touchX = e.GetX(); if (e.Action == MotionEventActions.Down) { downX = touchX; } int currentItem = CurrentItem; PagerAdapter adapter = Adapter; int pageCount = adapter == null ? 0 : adapter.Count; //current index is first one and slide to right or current index is last one and slide to left. //if slide border mode is to parent, then requestDisallowInterceptTouchEvent false. //else scroll to last one when current item is first one, scroll to first one when current item is last one. if ((currentItem == 0 && downX <= touchX) || (currentItem == pageCount - 1 && downX >= touchX)) { if (SlideBorderMode == SLIDE_BORDER_MODE_TO_PARENT) { Parent.RequestDisallowInterceptTouchEvent(false); } else { if (pageCount > 1) { SetCurrentItem(pageCount - currentItem - 1, IsBorderAnimation); } Parent.RequestDisallowInterceptTouchEvent(true); } return(base.DispatchTouchEvent(e)); } } Parent.RequestDisallowInterceptTouchEvent(true); return(base.DispatchTouchEvent(e)); }
public override bool OnTouchEvent(Android.Views.MotionEvent e) { var touchX = e.GetX(); var touchY = e.GetY(); switch (e.Action) { case MotionEventActions.Down: drawPath.MoveTo(touchX, touchY); break; case MotionEventActions.Move: drawPath.LineTo(touchX, touchY); break; default: return(false); } Invalidate(); return(true); }
private void AndroidMap_MapDoubleTap(object sender, Android.Views.MotionEvent e) { androidMap.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear(); // necessary to reset the search selection androidMap.EditOverlay.EditShapesLayer.InternalFeatures.Clear(); // necessary to reset the search selection PointF location = new PointF(e.GetX(), e.GetY()); PointShape position = ExtentHelper.ToWorldCoordinate(androidMap.CurrentExtent, location.X, location.Y, androidMap.Width, androidMap.Height); var inputDialog = new AlertDialog.Builder(this); inputDialog.SetTitle("Choose Action"); inputDialog.SetPositiveButton( "Get LR No.", (see, ess) => { try { LayerOverlay highlightOverlay = (LayerOverlay)androidMap.Overlays["cadastral"]; FeatureLayer highlightLayer = (FeatureLayer)highlightOverlay.Layers["Cadastral"]; highlightLayer.Open(); Collection <Feature> selectedFeatures = highlightLayer.QueryTools.GetFeaturesContaining(position, new string[1] { "Plotno_1" }); highlightLayer.Close(); if (selectedFeatures.Count > 0) { string p = null; foreach (var v in selectedFeatures) { p = v.ColumnValues["Plotno_1"].ToString(); } var uri = Android.Net.Uri.Parse("http://40.68.99.44/GeoManagerField/pages/valuationform.aspx?lrno=" + p); var intent = new Intent(Intent.ActionView, uri); StartActivity(intent); } } catch (Exception ex) { // do nothing } }); inputDialog.SetNegativeButton("Get Building No.", (afk, kfa) => { try { LayerOverlay highlightOverlay = (LayerOverlay)androidMap.Overlays["building"]; FeatureLayer highlightLayer = (FeatureLayer)highlightOverlay.Layers["Building"]; highlightLayer.Open(); Collection <Feature> selectedFeatures = highlightLayer.QueryTools.GetFeaturesContaining(position, new string[1] { "BLD_NO" }); highlightLayer.Close(); if (selectedFeatures.Count > 0) { string p = null; foreach (var v in selectedFeatures) { p = v.ColumnValues["BLD_NO"].ToString(); } var uri = Android.Net.Uri.Parse("http://40.68.99.44/GeoManagerField/pages/buildingform.aspx?bldno=" + p); var intent = new Intent(Intent.ActionView, uri); StartActivity(intent); } } catch (Exception ex) { //do nothing } }); inputDialog.Show(); }
private bool isScrollingLeft(Android.Views.MotionEvent e1, Android.Views.MotionEvent e2) { return(e2.GetX() > e1.GetX()); }
public override bool OnInterceptTouchEvent(Android.Views.MotionEvent ev) { // switch (ev.Action) { case MotionEventActions.Down: deltaX = 0; deltaY = 0; lastX = ev.GetX(); lastY = ev.GetY(); return(false); break; case MotionEventActions.Move: float moveX = ev.GetX(); float moveY = ev.GetY(); deltaX += Math.Abs(moveX - lastX); deltaY += Math.Abs(moveY - lastY); lastX = moveX; lastY = moveY; if (deltaX > deltaY) { return(false); } break; case MotionEventActions.Up: if (deltaX > deltaY) { return(false); } break; } var test = base.OnInterceptTouchEvent(ev); return(test); // if (x1 == 0) // x1 = ev.GetX (); // // if (ev.Action == Android.Views.MotionEventActions.Move) { // Console.WriteLine ("x1 = {0}, x2 = {1}", x1, ev.GetX ()); // x2 = ev.GetX (); // counter = counter + Math.Abs (x2 - x1); // Console.WriteLine ("New Counter Value = {0}", counter); // x1 = x2; // } // // if (counter > 100 && ev.Action == Android.Views.MotionEventActions.Up) { // Console.WriteLine (ev.Action); // Console.WriteLine ("Reset Counter and Return True"); // counter = 0; // } // // Console.WriteLine (ev.Action); // Console.WriteLine ("Get X: {0}", ev.GetX()); // // if (counter == 0) { // return true; // } else { // return base.OnInterceptTouchEvent (ev); // } }