GithubHelp home page GithubHelp logo

Comments (7)

AEFeinstein avatar AEFeinstein commented on July 19, 2024

I can confirm this bug

from devsmartlib-android.

vrash avatar vrash commented on July 19, 2024

Replacing dispatchTouchEvent with @OverRide
public boolean onTouchEvent(MotionEvent event) {
boolean handled = mGesture.onTouchEvent(event);
return handled;
}
and

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch( ev.getActionMasked() ){
        case MotionEvent.ACTION_DOWN:
             mInitialX = ev.getX();
             mInitialY = ev.getY();             
             return false;
        case MotionEvent.ACTION_MOVE:
             float deltaX = Math.abs(ev.getX() - mInitialX);
             float deltaY = Math.abs(ev.getY() - mInitialY);
             return ( deltaX > 5 || deltaY > 5 );
        default:
             return super.onInterceptTouchEvent(ev);
    }
}

??

from devsmartlib-android.

orgmir avatar orgmir commented on July 19, 2024

I can confirm that the previous solution corrects the bug, thanks for that.

from devsmartlib-android.

httpdispatch avatar httpdispatch commented on July 19, 2024

@vrash your fix doesn't work properly. It causes big view jumps

from devsmartlib-android.

kamilzych avatar kamilzych commented on July 19, 2024

@httpdispatch well, @vrash fix is almost correct. It's working very good for me after I changed return false; to return true; in case ACTION_DOWN - so:

@Override
public boolean dispatchTouchEvent(final MotionEvent ev) {
    boolean handled = super.dispatchTouchEvent(ev);
    handled |= mGesture.onTouchEvent(ev);
    return handled;
}

@Override
public boolean onInterceptTouchEvent(final MotionEvent ev) {
    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mInitialX = ev.getX();
        mInitialY = ev.getY();
        //HERE RETURN TRUE INSTEAD OF FALSE
        return true;
    case MotionEvent.ACTION_MOVE:
        final float deltaX = Math.abs(ev.getX() - mInitialX);
        final float deltaY = Math.abs(ev.getY() - mInitialY);
        return deltaX > 5 || deltaY > 5;
    default:
        return super.onInterceptTouchEvent(ev);
    }
}

from devsmartlib-android.

DollyBansal avatar DollyBansal commented on July 19, 2024

Thanks @vrash, its solved my problem :)

from devsmartlib-android.

httpdispatch avatar httpdispatch commented on July 19, 2024

@kamilzych your approach also has issue. I am testing new one

    float mInitialX;
    float mInitialY;
    boolean mIsMoving;
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        // experimental update to avoid view flickers and onclick events fired
        // after move
        boolean handled = mGesture.onTouchEvent(ev);
        switch (ev.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                mInitialX = ev.getX();
                mInitialY = ev.getY();
                mIsMoving = false;
                break;
            case MotionEvent.ACTION_MOVE: {
                final float deltaX = Math.abs(ev.getX() - mInitialX);
                final float deltaY = Math.abs(ev.getY() - mInitialY);
                mIsMoving = deltaX > 5 || deltaY > 5;
            }
                break;
        }
        if (!mIsMoving) {
            handled |= super.dispatchTouchEvent(ev);
        }
        return handled;
    }

It also has an issue that child component may not receive ACTION_UP event, but at least view should not flicker and on click works as expected

from devsmartlib-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.