Example usage for android.view MotionEvent AXIS_VSCROLL

List of usage examples for android.view MotionEvent AXIS_VSCROLL

Introduction

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

Prototype

int AXIS_VSCROLL

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

Click Source Link

Document

Axis constant: Vertical Scroll axis of a motion event.

Usage

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. j a  v  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  w  ww. j av  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);
                scrollBy((int) (hScroll * hFactor), (int) (vScroll * vFactor));
            }
        }
    }
    return false;
}

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

public boolean guessDirection(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        return false;
    }/* w  w w. j  av  a 2  s  . c o  m*/
    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.TabPageIndicator.java

@Override
public boolean onGenericMotionEvent(final MotionEvent event) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1)
        return false;
    if (mAdapter == null)
        return false;
    if ((MotionEventAccessor.getSource(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            final float vscroll = MotionEventAccessor.getAxisValue(event, MotionEvent.AXIS_VSCROLL);
            if (vscroll < 0) {
                if (mCurrentItem + 1 < mAdapter.getCount()) {
                    setCurrentItem(mCurrentItem + 1);
                }/*from www . j a  v a 2  s  .c  o m*/
            } else if (vscroll > 0) {
                if (mCurrentItem - 1 >= 0) {
                    setCurrentItem(mCurrentItem - 1);
                }
            }
            // if (vscroll != 0) {
            // final int delta = (int) (vscroll *
            // getVerticalScrollFactor());
            // if (!trackMotionScroll(delta, delta)) {
            // return true;
            // }
            // }
        }
        }
    }
    return true;
}

From source file:com.afayear.android.client.view.TabPageIndicator.java

@Override
public boolean onGenericMotionEvent(final MotionEvent event) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1)
        return false;
    if (mTabProvider == null)
        return false;
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
            if (vscroll < 0) {
                if (mCurrentItem + 1 < mTabProvider.getCount()) {
                    setCurrentItem(mCurrentItem + 1);
                }//from   ww w . j av a 2  s.  c  om
            } else if (vscroll > 0) {
                if (mCurrentItem - 1 >= 0) {
                    setCurrentItem(mCurrentItem - 1);
                }
            }
        }
        }
    }
    return true;
}

From source file:org.connectbot.util.TerminalTextViewOverlay.java

@Override
@TargetApi(12)/*from www .j av a2  s .c  o m*/
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((MotionEventCompat.getSource(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL:
            // Process scroll wheel movement:
            float yDistance = MotionEventCompat.getAxisValue(event, MotionEvent.AXIS_VSCROLL);

            vt320 vtBuffer = (vt320) terminalView.bridge.buffer;
            boolean mouseReport = vtBuffer.isMouseReportEnabled();
            if (mouseReport) {
                int row = (int) Math.floor(event.getY() / terminalView.bridge.charHeight);
                int col = (int) Math.floor(event.getX() / terminalView.bridge.charWidth);

                vtBuffer.mouseWheel(yDistance > 0, col, row,
                        (event.getMetaState() & KeyEvent.META_CTRL_ON) != 0,
                        (event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0,
                        (event.getMetaState() & KeyEvent.META_META_ON) != 0);
                return true;
            }
        }
    }

    return super.onGenericMotionEvent(event);
}

From source file:org.connectbot.TerminalView.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((MotionEventCompat.getSource(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL:
            // Process scroll wheel movement:
            float yDistance = MotionEventCompat.getAxisValue(event, MotionEvent.AXIS_VSCROLL);
            if (yDistance != 0) {
                int base = bridge.buffer.getWindowBase();
                bridge.buffer.setWindowBase(base - Math.round(yDistance));
                return true;
            }//  ww w  . j av  a2 s  .  co  m
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:com.hippo.widget.BothScrollView.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            if (!mIsBeingDragged) {
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    final float hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    if (hscroll != 0) {
                        final int delta = (int) (hscroll * getHorizontalScrollFactor());
                        final int range = getHorizontalScrollRange();
                        int oldScrollX = getScrollX();
                        int newScrollX = oldScrollX + delta;
                        if (newScrollX < 0) {
                            newScrollX = 0;
                        } else if (newScrollX > range) {
                            newScrollX = range;
                        }//from  w ww.  j ava 2 s . c  o m
                        if (newScrollX != oldScrollX) {
                            super.scrollTo(newScrollX, getScrollY());
                            return true;
                        }
                    }
                } else {
                    final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    if (vscroll != 0) {
                        final int delta = (int) (vscroll * getVerticalScrollFactor());
                        final int range = getVerticalScrollRange();
                        int oldScrollY = getScrollY();
                        int newScrollY = oldScrollY - delta;
                        if (newScrollY < 0) {
                            newScrollY = 0;
                        } else if (newScrollY > range) {
                            newScrollY = range;
                        }
                        if (newScrollY != oldScrollY) {
                            super.scrollTo(getScrollX(), newScrollY);
                            return true;
                        }
                    }
                }
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}

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;// w ww .  java 2  s.co  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) {
                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;/*from   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);
}