Wednesday 15 May 2013

view - Android - Receiving wrong touch events -


Here's the code:

  // handling touch events @ override public Boolean On-Touch (View View, Motion Event Speed ​​Event) {Float On OffMapWidth = It. On OffbeatMap.GateVuth (); If (motionEvent.getAction () == MotionEvent.ACTION_UP) {if (this.touchMove) {if (togglePositionX> this .onOffBitmap.getWidth () / 4.0f) {togglePositionX = this.onOffBitmap.getWidth () / 2.0 F - this.togglebitmap.getWidth () / 4.0f; } And if (togglePositionX & lt; = this.onOffBitmap.getWidth () / 4.0f) {togglePositionX = 0.0f; } This.invalidate (); This.touchMove = false; Back true; } Other {return false; }} And (if motion motion) This.invalidate (); } And if (motionEvent.getAction () == MotionEvent.ACTION_MOVE) {this.touchMove = true; Float currentX = motionEvent.getX (); If (currentX> 0.0f & current X <(this.onOffBitmap.getWidth) / 2.0f - this.toggleBitmap.getWidth () / 4.0f)) {togglePositionX = currentX; } And if (currentX> = (this.onOffBitmap.getWidth) / 2.0f - this.toggleBitmap.getWidth () / 4.0f)) {togglePositionX = this.onOffBitmap.getWidth () / 2.0f - this.toggleBitmap getWidth () / 4.0f; } And if (current X <-0 = 0.0f) {togglePositionX = 0.0f; } This.invalidate (); Back true; } Back true; } @ Override Public Zero (see V) {if (togglePositionX = 0.0F) {togglePositionX = this.onOffBitmap.getWidth () / 2.0f - this.togglebitmap.getWidth () / 4.0f; } And {togglePositionX = 0.0f; } This.invalidate (); }   

I am using an onClick event for a null event. The problem is that ACTION_MOVE is called, even though I only tap the screen. I also do this in a weird way (with very tip of my finger)

I have an array I am using the list which includes the history of touch positions that the user performs on the scene + Weather to detect a flag This is not a real ACTION_MOVE or code here, which I implemented inside (If motionEvent.getAction () == MotionEvent.ACTION_MOVE)

  float currentX = motionEvent.getX (); This.userTouchMoveArray.add (currentX); If (this.userTouchMoveArray.size () == 1) {touchIsMoved = false; } Else {float oldestX = userTouchMoveArray.get (0); If (Math.babs (currentX - oldest X)> 2.0F) {touch iced = true; } And {touch id = false; }}   

Working like a charm (you can define your tolerance, here I am using 2 pixels)

No comments:

Post a Comment