Java Code Examples for android.support.v7.widget.RecyclerView#setOnFlingListener()

The following examples show how to use android.support.v7.widget.RecyclerView#setOnFlingListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScrollPageHelper.java    From YCScrollPager with Apache License 2.0 6 votes vote down vote up
/**
 * 这个方法是与recyclerView绑定
 * @param recyclerView                      recyclerView
 * @throws IllegalStateException
 */
@Override
public void attachToRecyclerView(@Nullable RecyclerView recyclerView)
        throws IllegalStateException {
    if (recyclerView != null && !(recyclerView.getLayoutManager()
            instanceof LinearLayoutManager)) {
        throw new IllegalStateException("ScrollPageHelper needs a " +
                "RecyclerView with a LinearLayoutManager");
    }
    if (recyclerView != null) {
        //设置fling监听为null
        recyclerView.setOnFlingListener(null);
        if ((gravity == Gravity.START || gravity == Gravity.END)) {
            isRtlHorizontal = isRtl();
        }
    }
    super.attachToRecyclerView(recyclerView);
}
 
Example 2
Source File: ScrollPageHelper.java    From YCRefreshView with Apache License 2.0 6 votes vote down vote up
@Override
public void attachToRecyclerView(@Nullable RecyclerView recyclerView)
        throws IllegalStateException {
    if (recyclerView != null && !(recyclerView.getLayoutManager()
            instanceof LinearLayoutManager)) {
        throw new IllegalStateException("ScrollPageHelper needs a " +
                "RecyclerView with a LinearLayoutManager");
    }
    if (recyclerView != null) {
        //设置fling监听为null
        recyclerView.setOnFlingListener(null);
        if ((gravity == Gravity.START || gravity == Gravity.END)) {
            isRtlHorizontal = isRtl();
        }
    }
    super.attachToRecyclerView(recyclerView);
}
 
Example 3
Source File: GravitySnapHelper.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void attachToRecyclerView(@Nullable RecyclerView recyclerView)
        throws IllegalStateException {
    if (this.recyclerView != null) {
        this.recyclerView.removeOnScrollListener(scrollListener);
    }
    if (recyclerView != null) {
        recyclerView.setOnFlingListener(null);
        if (gravity == Gravity.START || gravity == Gravity.END) {
            isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())
                    == ViewCompat.LAYOUT_DIRECTION_RTL;
        }
        recyclerView.addOnScrollListener(scrollListener);
        this.recyclerView = recyclerView;
    } else {
        this.recyclerView = null;
    }
    super.attachToRecyclerView(recyclerView);
}
 
Example 4
Source File: RefreshContentWrapper.java    From CollapsingRefresh with Apache License 2.0 5 votes vote down vote up
void attach(RecyclerView recyclerView) {
    //获得原始监听器,用作转发
    Field[] declaredFields = RecyclerView.class.getDeclaredFields();
    if (declaredFields != null) {
        for (Field field : declaredFields) {
            if (RecyclerView.OnFlingListener.class.equals(field.getType())) {
                try {
                    field.setAccessible(true);
                    Object listener = field.get(recyclerView);
                    if (listener != null && !recyclerView.equals(listener)) {
                        mFlingListener = (RecyclerView.OnFlingListener) listener;
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    recyclerView.addOnScrollListener(this);
    recyclerView.setOnFlingListener(new RecyclerView.OnFlingListener() {
        @Override
        public boolean onFling(int velocityX, int velocityY) {
            if (mFlingListener != null) {
                mFlingListener.onFling(velocityX, velocityY);
            }
            lastFlingTime = System.currentTimeMillis();
            return false;
        }
    });
}
 
Example 5
Source File: ScrollPageHelper.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
@Override
public void attachToRecyclerView(@Nullable RecyclerView recyclerView)
        throws IllegalStateException {
    if (recyclerView != null && (!(recyclerView.getLayoutManager() instanceof LinearLayoutManager)
            || recyclerView.getLayoutManager() instanceof GridLayoutManager)) {
        throw new IllegalStateException("ScrollPageHelper needs a RecyclerView with a LinearLayoutManager");
    }
    if (recyclerView != null) {
        recyclerView.setOnFlingListener(null);
        if ((gravity == Gravity.START || gravity == Gravity.END)) {
            isRtlHorizontal = isRtl();
        }
    }
    super.attachToRecyclerView(recyclerView);
}