Example usage for android.view MotionEvent AXIS_HSCROLL

List of usage examples for android.view MotionEvent AXIS_HSCROLL

Introduction

In this page you can find the example usage for android.view MotionEvent AXIS_HSCROLL.

Prototype

int AXIS_HSCROLL

To view the source code for android.view MotionEvent AXIS_HSCROLL.

Click Source Link

Document

Axis constant: Horizontal Scroll axis of a motion event.

Usage

From source file:org.mariotaku.twidere.util.MouseScrollDirectionDecider.java

public boolean guessDirection(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        return false;
    }/*from w w  w . ja v a2s  .  c  om*/
    if (event.getAction() != MotionEventCompat.ACTION_SCROLL)
        return false;
    verticalScroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
    horizontalScroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
    verticalView.onGenericMotionEvent(event);
    horizontalView.onGenericMotionEvent(event);
    return verticalScroll != 0 || horizontalScroll != 0;
}

From source file:org.mariotaku.twidere.view.RecyclerViewBackport.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    final LayoutManager lm = getLayoutManager();
    if (lm == null) {
        return false;
    }//w  ww .jav a  2 s . c o m
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        if (event.getAction() == MotionEventCompat.ACTION_SCROLL) {
            final float vScroll, hScroll;
            if (lm.canScrollVertically()) {
                vScroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                if (!mMouseScrollDirectionDecider.isVerticalAvailable()) {
                    mMouseScrollDirectionDecider.guessDirection(event);
                }
            } else {
                vScroll = 0f;
            }
            if (lm.canScrollHorizontally()) {
                hScroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                if (!mMouseScrollDirectionDecider.isHorizontalAvailable()) {
                    mMouseScrollDirectionDecider.guessDirection(event);
                }
            } else {
                hScroll = 0f;
            }
            if ((vScroll != 0 || hScroll != 0)) {
                final float scrollFactor = getScrollFactorBackport();
                float horizontalDirection = mMouseScrollDirectionDecider.getHorizontalDirection();
                float verticalDirection = mMouseScrollDirectionDecider.getVerticalDirection();
                final float hFactor = scrollFactor * (horizontalDirection != 0 ? horizontalDirection : -1);
                final float vFactor = scrollFactor * (verticalDirection != 0 ? verticalDirection : -1);
                smoothScrollBy((int) (hScroll * hFactor), (int) (vScroll * vFactor));
            }
        }
    }
    return false;
}

From source file:org.mariotaku.twidere.view.ExtendedRecyclerView.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    final LayoutManager lm = getLayoutManager();
    if (lm == null) {
        return false;
    }//from ww w.j  a  v a2 s  . co m
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        if (event.getAction() == MotionEventCompat.ACTION_SCROLL) {
            final float vScroll, hScroll;
            if (lm.canScrollVertically()) {
                vScroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                if (!mMouseScrollDirectionDecider.isVerticalAvailable()) {
                    mMouseScrollDirectionDecider.guessDirection(event);
                }
            } else {
                vScroll = 0f;
            }
            if (lm.canScrollHorizontally()) {
                hScroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                if (!mMouseScrollDirectionDecider.isHorizontalAvailable()) {
                    mMouseScrollDirectionDecider.guessDirection(event);
                }
            } else {
                hScroll = 0f;
            }
            if ((vScroll != 0 || hScroll != 0)) {
                final float scrollFactor = getScrollFactorBackport();
                float horizontalDirection = mMouseScrollDirectionDecider.getHorizontalDirection();
                float verticalDirection = mMouseScrollDirectionDecider.getVerticalDirection();
                final float hFactor = scrollFactor * (horizontalDirection != 0 ? horizontalDirection : -1);
                final float vFactor = scrollFactor * (verticalDirection != 0 ? verticalDirection : -1);
                scrollBy((int) (hScroll * hFactor), (int) (vScroll * vFactor));
            }
        }
    }
    return false;
}

From source file:com.android.launcher2.PagedView.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            // Handle mouse (or ext. device) by shifting the page depending on the scroll
            final float vscroll;
            final float hscroll;
            if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                vscroll = 0;//from www . j a  va2s  .com
                hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
            } else {
                vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
            }
            if (hscroll != 0 || vscroll != 0) {
                if (hscroll > 0 || vscroll > 0) {
                    scrollRight();
                } else {
                    scrollLeft();
                }
                return true;
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:cc.flydev.launcher.Page.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            // Handle mouse (or ext. device) by shifting the page depending on the scroll
            final float vscroll;
            final float hscroll;
            if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                vscroll = 0;/* w w  w  .  j av a2  s . c  o  m*/
                hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
            } else {
                vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
            }
            if (hscroll != 0 || vscroll != 0) {
                boolean isForwardScroll = isLayoutRtl() ? (hscroll < 0 || vscroll < 0)
                        : (hscroll > 0 || vscroll > 0);
                if (isForwardScroll) {
                    scrollRight();
                } else {
                    scrollLeft();
                }
                return true;
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:com.n2hsu.launcher.Page.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            // Handle mouse (or ext. device) by shifting the page depending
            // on the scroll
            final float vscroll;
            final float hscroll;
            if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                vscroll = 0;//  w w  w  . ja  v  a  2s.  c o  m
                hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
            } else {
                vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
            }
            if (hscroll != 0 || vscroll != 0) {
                boolean isForwardScroll = isLayoutRtl() ? (hscroll < 0 || vscroll < 0)
                        : (hscroll > 0 || vscroll > 0);
                if (isForwardScroll) {
                    scrollRight();
                } else {
                    scrollLeft();
                }
                return true;
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:com.appunite.list.AbsHorizontalListView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override// ww w.ja  v a2 s.c o m
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            if (mTouchMode == TOUCH_MODE_REST) {
                final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                if (hscroll != 0) {
                    final int delta = (int) (hscroll * getHorizontalScrollFactorUnhide());
                    if (!trackMotionScroll(delta, delta)) {
                        return true;
                    }
                }
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}