Example usage for android.view MotionEvent getSource

List of usage examples for android.view MotionEvent getSource

Introduction

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

Prototype

@Override
public final int getSource() 

Source Link

Usage

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

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override//  w ww .  j  a  v a2s. 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 vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                if (vscroll != 0) {
                    final int delta = (int) (vscroll * getVerticalScrollFactorUnhide());
                    if (!trackMotionScroll(delta, delta)) {
                        return true;
                    }
                }
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}

From source file:cn.ismartv.tvrecyclerview.widget.RecyclerView.java

public boolean onGenericMotionEvent(MotionEvent event) {
    if (mLayout == null) {
        return false;
    }/*from  ww  w. j av a 2s . co  m*/
    if (mLayoutFrozen) {
        return false;
    }
    if ((event.getSource() & InputDeviceCompat.SOURCE_CLASS_POINTER) != 0) {
        if (event.getAction() == MotionEventCompat.ACTION_SCROLL) {
            final float vScroll, hScroll;
            if (mLayout.canScrollVertically()) {
                // Inverse the sign of the vertical scroll to align the scroll orientation
                // with AbsListView.
                vScroll = -MotionEventCompat.getAxisValue(event, MotionEventCompat.AXIS_VSCROLL);
            } else {
                vScroll = 0f;
            }
            if (mLayout.canScrollHorizontally()) {
                hScroll = MotionEventCompat.getAxisValue(event, MotionEventCompat.AXIS_HSCROLL);
            } else {
                hScroll = 0f;
            }

            if (vScroll != 0 || hScroll != 0) {
                final float scrollFactor = getScrollFactor();
                scrollByInternal((int) (hScroll * scrollFactor), (int) (vScroll * scrollFactor), event);
            }
        }
    }
    return false;
}