Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple swipe gesture to activity tutorial? [closed]

im looking for a turoial with source code on swipe gesutes, I dont want a view pager, I want a swipe gesture tutorial. here is one example I found but doesnt work for me

http://www.eridem.net/android-tip-010-left-and-right-swipe-gesture-events

I would like something like this, thanks Please no view pagers

like image 486
Moussa Avatar asked Aug 06 '12 18:08

Moussa


People also ask

What is touch gestures in Android?

A "touch gesture" occurs when a user places one or more fingers on the touch screen, and your application interprets that pattern of touches as a particular gesture. There are correspondingly two phases to gesture detection: Gather data about touch events.


2 Answers

    SimpleOnGestureListener mySimpleGestureListener = new SimpleOnGestureListener()
 {

    @Override
    public boolean onDoubleTap(MotionEvent e) { 
        Logout.debug("onDoubleTap");
        return super.onDoubleTap(e);
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) 
    {
        String velocity="onFling: \n" + e1.toString() + "\n" + e2.toString() +"\n"
                + "velocityX= " + String.valueOf(velocityX) + "\n"
                + "velocityY= " + String.valueOf(velocityY) + "\n";
        Logout.debug("onFling velocity="+velocity);
                    return super.onFling(e1, e2, velocityX, velocityY);
    }

    @Override
    public void onLongPress(MotionEvent e) {
        Logout.debug("onLongPress: \n" + e.toString());
        super.onLongPress(e);
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        Logout.debug("onSingleTapConfirmed: \n" + e.toString());
        return super.onSingleTapConfirmed(e);
    }

    private boolean permissibleYVelocity(float velocityY)
    {
        if ((velocityY < -200) || (velocityY > 200))
        {
            return false;
        }
        else
        {
            return true;
        }

    }
};

GestureDetector myGestureDetector = new GestureDetector(mSimpleOnGestureListener);

View.OnTouchListener mOnListTouchListener = new  OnTouchListener()
{
    @Override
    public boolean onTouch(View view, MotionEvent event)
    {
        Logout.debug("list onTouch()");
         return myGestureDetector.onTouchEvent(event);
    }
};
like image 162
Code Droid Avatar answered Oct 19 '22 19:10

Code Droid


I would start by googling something like "Android basic swipe gesture". That was kinda what I did, and I ended up with this populare post on the subject: Fling gesture detection on grid layout

First hit on google was this: http://pcfandroid.wordpress.com/2011/07/17/swipe-with-android-android-tutorial/, also applicable for you're question

like image 24
Sindre Avatar answered Oct 19 '22 20:10

Sindre