Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6238965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:18:32+00:00 2026-05-24T11:18:32+00:00

im trying to detect when a user make a left or right swing in

  • 0

im trying to detect when a user make a left or right swing in the activity.
Currently I’m using a OnGestureListener and the method onFling() and my problem is that I don’t achieve a nice way of detecting it.

I’d like a behaviour similar to the others applications and the “native” Android swing detection but with the code (appended below) I have a lot of wrong swing detections. If someone have already solved that I’d like a tip =)

Thats the code I’m using

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) {
    //Get Position
    float ev1X = e1.getX();
    float ev2X = e2.getX();

    //Get distance of X (e1) to X (e2)
    final float xdistance = Math.abs(ev1X - ev2X);
    //Get velocity of cursor
    final float xvelocity = Math.abs(velocityX);

    if( (xvelocity > SWIPE_MIN_VELOCITY) && (xdistance > SWIPE_MIN_DISTANCE) )
    {
        if(ev1X > ev2X)//Switch Left
        {
            if (Manager.debug) Log.d(Manager.appname,"SWING_LEFT_EVENT");
            moveToRight();
        }
        else//Switch Right
        {
            if (Manager.debug) Log.d(Manager.appname,"SWING_RIGHT_EVENT");
            moveToLeft();
        }
    }

    return false;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:18:34+00:00Added an answer on May 24, 2026 at 11:18 am

    I am not sure how far this is useful, but this is how I do it.

    private static final int SWIPE_MIN_DISTANCE = 120;
    private static final int SWIPE_MAX_OFF_PATH = 250;
    private static final int SWIPE_THRESHOLD_VELOCITY = 100;
    @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                float velocityY) {
            Log.d("---onFling---", e1.toString() + e2.toString() + "");
    
            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) {
                    //do your code
    
                } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                        && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    //left to right flip
                    }
                }
            } catch (Exception e) {
                // nothing
            }
            return false;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to detect which web in sharepoint that the user is looking
I'm trying to determine how I can detect when the user changes the Windows
I'm trying to figure out a way to detect files that are not opened
I'm trying to detect which controller I'm using or what controller I'm on and
I'm trying to make a game (using irrlicht engine with c++) where you can
I'm trying to make a simple image browser for TinyMCE which I am using
I am trying to make a page that allows users to select 8 checkboxes
I'm trying to detect and change browser behavior if a user clicks on the
I am trying to detect touches, but the touchesBegan method is not being called.
Answerers: How does one literally detect the user's font scale, so that it may

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.