Sunday, 24 June 2012

ANDROID - Swipe Gesture

For most of us newbees, we all know how to simply decorate the xmls but man when it comes to slight animation, we are screwed quite literally ! The latest problem we faced was related to the swipe gesture !
After understanding the whole deal, we thought man, we must make a library where the gestures could be detected and user could simplify its use on the lines of usage of events like - onClickListner  / onTouchListner. So we started to code ! But man we love GOOGLE :)

We got link to this post. The guy has done all that we planned to do. Simply awesome!
So without taking those pains, we used his library and it worked like a charm! It gives you the direction of the swipe, the displacement, and whether it was really a swipe or a click ! I think all that one amateur would want !

The link to his blog is - Awesome Swipe Gesture Implementation

However, we would like to present the jist of the same in our words here in this blog as well.

Steps To Create -

  1. Copy this project into your workspace - Swipe Me
  2. Once done, add the .jar file to your library.
  3. Import the “SwipeMe.OnSwipeListener”.
  4. Set OnTouchlistener to the view object by sending OnSwipeListener as the listener.
  5. Override the onSwipe() method and do whatever you want
  6. Use the getSwipedTo() to know the direction of the swipe

The sample code -

Here is a sample code adding the swipe action and implementing the four direction swipe actions on a button:
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
// importing the onSwipeListener
import SwipeMe.OnSwipeListener;

public class SwipeMeActivity extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        Button test = (Button) findViewById(;

        //adding onTouch action to test button
        //but by sending it the on swipe listener
        test.setOnTouchListener(new OnSwipeListener() {

            public void onSwipe(View v, MotionEvent event) {
                // TODO Auto-generated method stub

                //checking the direction of the swipe
                case SWIPED_LEFT :
                    //swiped to left
                    Toast.makeText(getApplicationContext(), "Swiped Left",
                case SWIPED_RIGHT :
                    //swiped to right
                    Toast.makeText(getApplicationContext(), "Swiped Right",
                case SWIPED_UP :
                    //swiped up
                    Toast.makeText(getApplicationContext(), "Swiped Up",
                case SWIPED_DOWN :
                    //swiped down
                    Toast.makeText(getApplicationContext(), "Swiped Down",
                case CLICKED:
                    Toast.makeText(getApplicationContext(), "clicked",


  1. thanks..this is helpful

  2. That link is not working..
    please.. can you share the jar file....


Feel free to contact us via our website -