0

i am trying to do finger swipe but it is not detected .i am trying to draw a path which describes the area through which finger swipe but only when i swipe with force then only swipe get detected and else not detected

public boolean onTouchEvent(MotionEvent event) {
if (System.currentTimeMillis() - lastClick > 500) {
       lastClick = System.currentTimeMillis();
       synchronized (getHolder()) {
           int eventaction = event.getAction();
           if(event.getPressure()>0.00001||event.getSize()>0.00001)
           {

           float a,b,c;
           switch(eventaction)
           {
           case MotionEvent.ACTION_DOWN:

               xdown = event.getX();
               ydown =event.getY();
               pres=true;

               break;

           case MotionEvent.ACTION_MOVE:
               if(pres)
               {

               xmove = event.getX();
               ymove =event.getY();
               a = (float) Math.sqrt(Math.pow(xdown - xmove,2) +Math.pow( ydown - ymove,2)); 
            b=(float) (xdown-(((xdown - xmove) / a) * 150));
            c=(float) (ydown-((( ydown - ymove)/a)*150));
            move.moveTo(xdown, ydown);
            move.lineTo(b, c);
               pres=false;
               lmove=true;

               }
               break;
           case MotionEvent.ACTION_CANCEL:
           case MotionEvent.ACTION_POINTER_UP:
               move.reset();
                   xmove = 0;
                   ymove =0;
                   xdown=0;
                   ydown=0;
               lmove=false;
               pres=false;
               break;
           default:
               return true;

           }
       }
       }}
return true;

       } 
  • possible duplicate of [Android: How to handle right to left swipe gestures](http://stackoverflow.com/questions/4139288/android-how-to-handle-right-to-left-swipe-gestures) – marko Mar 09 '14 at 12:40

2 Answers2

0

Android has a class for that. Check http://developer.android.com/reference/android/view/GestureDetector.html I believe it is one of in touch events

Rado
  • 155
  • 12
0

See the code here: Simple swipe gesture to activity tutorial?

Using a SimpleOnGestureListener is easiest, and if you override the onFling method, it's easy/

Community
  • 1
  • 1
ElectronicGeek
  • 3,312
  • 2
  • 23
  • 35