android.support.v7.widget.OrientationHelper Java Examples

The following examples show how to use android.support.v7.widget.OrientationHelper. 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: Demo4Activity.java    From RecyclerViewDemo with Apache License 2.0 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerview = (RecyclerView) findViewById(R.id.recyclerview);
//        recyclerview.setLayoutManager(new GridLayoutManager(this, 3));
//        recyclerview.setLayoutManager(new LinearLayoutManager(this,
//                LinearLayoutManager.VERTICAL, false));
        recyclerview.setLayoutManager(new StaggeredGridLayoutManager(2, OrientationHelper.VERTICAL));

        Divider divider = new Divider(new ColorDrawable(0xffff0000), OrientationHelper.VERTICAL);
        //单位:px
        divider.setMargin(50, 50, 50, 50);
        divider.setHeight(20);
        recyclerview.addItemDecoration(divider);
        recyclerview.setAdapter(new Demo3Adapter(this));
    }
 
Example #2
Source File: GravitySnapHelper.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
private int getDistanceToEnd(View targetView, @NonNull OrientationHelper helper) {
    int distance;

    if (!snapToPadding) {
        int childEnd = helper.getDecoratedEnd(targetView);
        if (childEnd >= helper.getEnd() - (helper.getEnd() - helper.getEndAfterPadding()) / 2) {
            distance = helper.getDecoratedEnd(targetView) - helper.getEnd();
        } else {
            distance = childEnd - helper.getEndAfterPadding();
        }
    } else {
        distance = helper.getDecoratedEnd(targetView) - helper.getEndAfterPadding();
    }

    return distance;
}
 
Example #3
Source File: PatchedRecyclerView.java    From ExpandableRecyclerView with Apache License 2.0 6 votes vote down vote up
public PatchedRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.PatchedRecyclerView);
    boolean nestedScrollingEnabled = ta
            .getBoolean(R.styleable.PatchedRecyclerView_nestedScrollingEnabled, true);
    boolean hasFixedSize = ta.getBoolean(R.styleable.PatchedRecyclerView_hasFixedSize, false);
    int orientation =
            ta.getInt(R.styleable.PatchedRecyclerView_orientation, OrientationHelper.VERTICAL);
    ta.recycle();

    LayoutManager layoutManager = getLayoutManager();
    if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
        int currOrientation = linearLayoutManager.getOrientation();
        if (currOrientation != orientation) {
            linearLayoutManager.setOrientation(orientation);
        }
    }

    setHasFixedSize(hasFixedSize);
    setNestedScrollingEnabled(nestedScrollingEnabled);
    setFocusable(nestedScrollingEnabled);
}
 
Example #4
Source File: HomeFragment.java    From WanAndroid with MIT License 6 votes vote down vote up
@Override
protected void initView() {
    initData();
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
    linearLayoutManager.setOrientation(OrientationHelper.VERTICAL);
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));

    FrameLayout headView = (FrameLayout) LayoutInflater.from(getContext()).inflate(R.layout.banner_home, null);
    homeBanner = headView.findViewById(R.id.home_banner);
    headView.removeView(homeBanner);
    homeBanner.setImageLoader(new HomeBannerLoader());
    homeBanner.setImages(bannerList);
    homeBanner.start();

    commonArticleAdapter = new CommonArticleAdapter(R.layout.item_article, articleList);
    commonArticleAdapter.addHeaderView(homeBanner);
    commonArticleAdapter.setEnableLoadMore(true);

    recyclerView.setAdapter(commonArticleAdapter);
    refreshAndloadMore();
}
 
Example #5
Source File: WrapRecyclerViewItemActivity.java    From Gloading with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecyclerView recyclerView = new RecyclerView(this);
    setContentView(recyclerView);
    DisplayMetrics dm = getResources().getDisplayMetrics();
    size = dm.widthPixels >> 1;

    GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
    layoutManager.setOrientation(OrientationHelper.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    RecyclerAdapter adapter = new RecyclerAdapter(initData());
    recyclerView.setAdapter(adapter);
}
 
Example #6
Source File: ItemDragHelper.java    From MultiItem with Apache License 2.0 6 votes vote down vote up
/**
     * 当item位置变换,滚动recycler到正确的位置
     * TODO: 2017/2/21 0021 整理更优雅的写法  还有scrollToPosition(0)是否必要?
     */
    private void scrollToRightPositionWhenItemChanged(RecyclerView recyclerView, View itemView, int itemPos) {
        final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        if (layoutManager instanceof ItemTouchHelper.ViewDropHandler) {
            OrientationHelper helper = OrientationHelper.createVerticalHelper(layoutManager);
            int start = helper.getDecoratedStart(itemView);
            int end = helper.getDecoratedEnd(itemView);
            ((LinearLayoutManager) layoutManager).scrollToPositionWithOffset(
                    itemPos, lastItemPos > itemPos ? start : end - itemViewHeight);
//                System.out.println(lastItemPos + "-" + childPos + "OrientationHelperOrientationHelper:"
//                        + height + "==" + itemViewHeight + "=||=" + start + "===" + end + "||||||" + myStart + "===" + itemTargetView.getHeight() );
        }
        if (lastItemPos == 0 || itemPos == 0) {
            recyclerView.scrollToPosition(0);
        }
    }
 
Example #7
Source File: MultipleHeaderBottomFragment.java    From AndroidRecyclerViewDemo with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (type == TYPE_GRID_LAYOUT) {
        gridLayoutManager = new GridLayoutManager(getActivity(), 2);
        mRecyclerView.setLayoutManager(gridLayoutManager);//这里用线性宫格显示 类似于grid view
    } else if (type == TYPE_STAGGERED_GRID_LAYOUT) {
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, OrientationHelper.VERTICAL));//这里用线性宫格显示 类似于瀑布流
    } else {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));//这里用线性显示 类似于list view
    }
    mAdapter = new HeaderBottomItemAdapter(getActivity());
    mRecyclerView.setAdapter(mAdapter);
    if (gridLayoutManager != null) {//设置头部及底部View占据整行空间
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return (mAdapter.isHeaderView(position) || mAdapter.isBottomView(position)) ? gridLayoutManager.getSpanCount() : 1;
            }
        });
    }
}
 
Example #8
Source File: MultipleHeaderBottomFragment.java    From TitanRecyclerView with MIT License 6 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (type == TYPE_GRID_LAYOUT) {
        gridLayoutManager = new GridLayoutManager(getActivity(), 2);
        mAttackView.setLayoutManager(gridLayoutManager);//这里用线性宫格显示 类似于grid view
    } else if (type == TYPE_STAGGERED_GRID_LAYOUT) {
        mAttackView.setLayoutManager(new StaggeredGridLayoutManager(2, OrientationHelper.VERTICAL));//这里用线性宫格显示 类似于瀑布流
    } else {
        mAttackView.setLayoutManager(new LinearLayoutManager(getActivity()));//这里用线性显示 类似于list view
    }
    mAdapter = new HeaderBottomItemAdapter(getActivity());
    mAdapter.setHeaderView(LayoutInflater.from(getActivity()).inflate(R.layout.item_image, mAttackView, false));
    mAdapter.setFooterView(LayoutInflater.from(getActivity()).inflate(R.layout.item_image, mAttackView, false));
    mAttackView.setAdapter(mAdapter);
}
 
Example #9
Source File: Demo3Activity2.java    From RecyclerViewDemo with Apache License 2.0 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerview = (RecyclerView) findViewById(R.id.recyclerview);
//        recyclerview.setLayoutManager(new GridLayoutManager(this, 3));
//        recyclerview.setLayoutManager(new LinearLayoutManager(this,
//                LinearLayoutManager.VERTICAL, false));
        recyclerview.setLayoutManager(new StaggeredGridLayoutManager(2, OrientationHelper.VERTICAL));

        recyclerview.setAdapter(new Demo3Adapter(this));
    }
 
Example #10
Source File: RecyclerViewActivity.java    From Android-HTTPS-based-on-MVVM with Apache License 2.0 5 votes vote down vote up
private void initRecyclerView() {
    RecyclerViewAdapter recycleAdapter = viewModel.adapter;
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(OrientationHelper.VERTICAL);//设置为垂直布局,这也是默认的
    binding.recyclerView.setLayoutManager(layoutManager); //设置布局管理器
    binding.recyclerView.setAdapter(recycleAdapter); //设置Adapter
    binding.recyclerView.setItemAnimator(new DefaultItemAnimator());//设置增加或删除条目的动画
    binding.recyclerView.addItemDecoration(new DividerItemDecoration(this,
            DividerItemDecoration.VERTICAL_LIST));
}
 
Example #11
Source File: GravitySnapHelper.java    From MangoBloggerAndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
private int distanceToStart(View targetView, OrientationHelper helper, boolean fromEnd) {
    if (mIsRtlHorizontal && !fromEnd) {
        return distanceToEnd(targetView, helper, true);
    }

    return helper.getDecoratedStart(targetView) - helper.getStartAfterPadding();
}
 
Example #12
Source File: Demo1Activity.java    From RecyclerViewDemo with Apache License 2.0 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerview = (RecyclerView) findViewById(R.id.recyclerview);
//        recyclerview.setLayoutManager(new GridLayoutManager(this, 3));
//        recyclerview.setLayoutManager(new LinearLayoutManager(this,
//                LinearLayoutManager.VERTICAL, false));
        recyclerview.setLayoutManager(new StaggeredGridLayoutManager(3, OrientationHelper.VERTICAL));

        recyclerview.setAdapter(new Demo1Adapter(this, DataUtils.getDatas()));
    }
 
Example #13
Source File: GravitySnapHelper.java    From MangoBloggerAndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
private int distanceToEnd(View targetView, OrientationHelper helper, boolean fromStart) {
    if (mIsRtlHorizontal && !fromStart) {
        return distanceToStart(targetView, helper, true);
    }

    return helper.getDecoratedEnd(targetView) - helper.getEndAfterPadding();
}
 
Example #14
Source File: ScrollLinearHelper.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
@NonNull
private OrientationHelper getVerticalHelper(@NonNull RecyclerView.LayoutManager layoutManager) {
    if (mVerticalHelper == null) {
        mVerticalHelper = OrientationHelper.createVerticalHelper(layoutManager);
    }
    return mVerticalHelper;
}
 
Example #15
Source File: GalleryLayoutManager.java    From GalleryLayoutManager with Apache License 2.0 5 votes vote down vote up
/**
 * @param child
 * @param pendingOffset child view will scroll by
 * @return
 */
private int calculateDistanceCenter(View child, float pendingOffset) {
    OrientationHelper orientationHelper = getOrientationHelper();
    int parentCenter = (orientationHelper.getEndAfterPadding() - orientationHelper.getStartAfterPadding()) / 2 + orientationHelper.getStartAfterPadding();
    if (mOrientation == GalleryLayoutManager.HORIZONTAL) {
        return (int) (child.getWidth() / 2 - pendingOffset + child.getLeft() - parentCenter);
    } else {
        return (int) (child.getHeight() / 2 - pendingOffset + child.getTop() - parentCenter);
    }

}
 
Example #16
Source File: ScrollSnapHelper.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
private float computeDistancePerChild(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) {
    View minPosView = null;
    View maxPosView = null;
    int minPos = Integer.MAX_VALUE;
    int maxPos = Integer.MIN_VALUE;
    int childCount = layoutManager.getChildCount();
    if (childCount == 0) {
        return INVALID_DISTANCE;
    }
    for (int i = 0; i < childCount; i++) {
        View child = layoutManager.getChildAt(i);
        final int pos = layoutManager.getPosition(child);
        if (pos == RecyclerView.NO_POSITION) {
            continue;
        }
        if (pos < minPos) {
            minPos = pos;
            minPosView = child;
        }
        if (pos > maxPos) {
            maxPos = pos;
            maxPosView = child;
        }
    }
    if (minPosView == null || maxPosView == null) {
        return INVALID_DISTANCE;
    }
    int start = Math.min(helper.getDecoratedStart(minPosView), helper.getDecoratedStart(maxPosView));
    int end = Math.max(helper.getDecoratedEnd(minPosView), helper.getDecoratedEnd(maxPosView));
    int distance = end - start;
    if (distance == 0) {
        return INVALID_DISTANCE;
    }
    return 1f * distance / ((maxPos - minPos) + 1);
}
 
Example #17
Source File: EndlessRecyclerOnScrollListener.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
private View findOneVisibleChild(int fromIndex, int toIndex, boolean completelyVisible, boolean acceptPartiallyVisible) {
    if (mLayoutManager.canScrollVertically() != mIsOrientationHelperVertical || mOrientationHelper == null) {
        mIsOrientationHelperVertical = mLayoutManager.canScrollVertically();
        mOrientationHelper = mIsOrientationHelperVertical ? OrientationHelper.createVerticalHelper(mLayoutManager) : OrientationHelper.createHorizontalHelper(mLayoutManager);
    }

    final int start = mOrientationHelper.getStartAfterPadding();
    final int end = mOrientationHelper.getEndAfterPadding();
    final int next = toIndex > fromIndex ? 1 : -1;
    View partiallyVisible = null;
    for (int i = fromIndex; i != toIndex; i += next) {
        final View child = mLayoutManager.getChildAt(i);
        if (child != null) {
            final int childStart = mOrientationHelper.getDecoratedStart(child);
            final int childEnd = mOrientationHelper.getDecoratedEnd(child);
            if (childStart < end && childEnd > start) {
                if (completelyVisible) {
                    if (childStart >= start && childEnd <= end) {
                        return child;
                    } else if (acceptPartiallyVisible && partiallyVisible == null) {
                        partiallyVisible = child;
                    }
                } else {
                    return child;
                }
            }
        }
    }
    return partiallyVisible;
}
 
Example #18
Source File: ScrollSnapHelper.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
private int estimateNextPositionDiffForFling(RecyclerView.LayoutManager layoutManager, OrientationHelper helper, int velocityX, int velocityY) {
    int[] distances = calculateScrollDistance(velocityX, velocityY);
    float distancePerChild = computeDistancePerChild(layoutManager, helper);
    if (distancePerChild <= 0) {
        return 0;
    }
    int distance = distances[0];
    if (distance > 0) {
        return (int) Math.floor(distance / distancePerChild);
    } else {
        return (int) Math.ceil(distance / distancePerChild);
    }
}
 
Example #19
Source File: GalleryLayoutManager.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
private OrientationHelper getOrientationHelper() {
    if (mOrientation == HORIZONTAL) {
        if (mHorizontalHelper == null) {
            mHorizontalHelper = OrientationHelper.createHorizontalHelper(this);
        }
        return mHorizontalHelper;
    } else {
        if (mVerticalHelper == null) {
            mVerticalHelper = OrientationHelper.createVerticalHelper(this);
        }
        return mVerticalHelper;
    }
}
 
Example #20
Source File: GravitySnapHelper.java    From MangoBloggerAndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
private View findEndView(RecyclerView.LayoutManager layoutManager,
                         OrientationHelper helper) {

    if (layoutManager instanceof LinearLayoutManager) {
        int lastChild = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();

        if (lastChild == RecyclerView.NO_POSITION) {
            return null;
        }

        View child = layoutManager.findViewByPosition(lastChild);

        float visibleWidth;

        if (mIsRtlHorizontal) {
            visibleWidth = (float) helper.getDecoratedEnd(child)
                    / helper.getDecoratedMeasurement(child);
        } else {
            visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
                    / helper.getDecoratedMeasurement(child);
        }

        // If we're at the start of the list, we shouldn't snap
        // to avoid having the first item not completely visible.
        boolean startOfList = ((LinearLayoutManager) layoutManager)
                .findFirstCompletelyVisibleItemPosition() == 0;

        if (visibleWidth > 0.5f && !startOfList) {
            return child;
        } else if (mSnapLastItemEnabled && startOfList) {
            return child;
        } else if (startOfList) {
            return null;
        } else {
            // If the child wasn't returned, we need to return the previous view
            return layoutManager.findViewByPosition(lastChild - 1);
        }
    }
    return null;
}
 
Example #21
Source File: GalleryLayoutManager.java    From GalleryLayoutManager with Apache License 2.0 5 votes vote down vote up
public OrientationHelper getOrientationHelper() {
    if (mOrientation == HORIZONTAL) {
        if (mHorizontalHelper == null) {
            mHorizontalHelper = OrientationHelper.createHorizontalHelper(this);
        }
        return mHorizontalHelper;
    } else {
        if (mVerticalHelper == null) {
            mVerticalHelper = OrientationHelper.createVerticalHelper(this);
        }
        return mVerticalHelper;
    }
}
 
Example #22
Source File: DividerViewItemLine.java    From YCRefreshView with Apache License 2.0 5 votes vote down vote up
/**
 * 调用的是getItemOffsets会被多次调用,在layoutManager每次测量可摆放的view的时候回调用一次,
 * 在当前状态下需要摆放多少个view这个方法就会回调多少次。
 * @param outRect                   核心参数,这个rect相当于item摆放的时候设置的margin,
 *                                  rect的left相当于item的marginLeft,
 *                                  rect的right相当于item的marginRight
 * @param view                      当前绘制的view,可以用来获取它在adapter中的位置
 * @param parent                    recyclerView
 * @param state                     状态,用的很少
 */
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view,
                           @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
    int position = parent.getChildAdapterPosition(view);
    int orientation = 0;
    int headerCount = 0,footerCount = 0;
    if (parent.getAdapter()==null){
        return;
    }
    //获取header和footer的数量
    if (parent.getAdapter() instanceof RecyclerArrayAdapter){
        headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
        footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
    }

    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof StaggeredGridLayoutManager){
        orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
    }else if (layoutManager instanceof GridLayoutManager){
        orientation = ((GridLayoutManager) layoutManager).getOrientation();
    }else if (layoutManager instanceof LinearLayoutManager){
        orientation = ((LinearLayoutManager) layoutManager).getOrientation();
    }
    int itemCount = parent.getAdapter().getItemCount();
    int count = itemCount-footerCount;

    //下面代码才是重点,更多内容可以看我的GitHub博客汇总:https://github.com/yangchong211/YCBlogs
    if (mDrawHeaderFooter){
        if (position >= headerCount && position<count){
            if (orientation == OrientationHelper.VERTICAL){
                //当是竖直方向的时候,距离底部marginBottom是分割线的高度
                outRect.bottom = mHeight;
            }else {
                //noinspection SuspiciousNameCombination
                outRect.right = mHeight;
            }
        }
    }
}
 
Example #23
Source File: ScrollPageHelper.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
private int distanceToEnd(View targetView, @NonNull OrientationHelper helper, boolean fromStart) {
    if (isRtlHorizontal && !fromStart) {
        return distanceToStart(targetView, helper, true);
    }

    return helper.getDecoratedEnd(targetView) - helper.getEndAfterPadding();
}
 
Example #24
Source File: BindSuperAdapter.java    From LazyRecyclerAdapter with MIT License 5 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent ev) {
    if (normalAdapterManager.mTouchListener != null) {
        return normalAdapterManager.mTouchListener.onTouch(v, ev);
    }
    if (getOrientation(mRecyclerView.getLayoutManager()) == OrientationHelper.HORIZONTAL) {
        return touchX(ev);
    }
    return touchY(ev);
}
 
Example #25
Source File: ScrollPageHelper.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
@NonNull
private OrientationHelper getHorizontalHelper(
        @NonNull RecyclerView.LayoutManager layoutManager) {
    if (mHorizontalHelper == null) {
        mHorizontalHelper = OrientationHelper.createHorizontalHelper(layoutManager);
    }
    return mHorizontalHelper;
}
 
Example #26
Source File: FamiliarDefaultItemDecoration.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
private void initLayoutManagerType() {
    this.mLayoutManagerType = mRecyclerViewListener.getCurLayoutManagerType();
    RecyclerView.LayoutManager layoutManager = mRecyclerViewListener.getCurLayoutManager();
    switch (mLayoutManagerType) {
        case FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_LINEAR:
            LinearLayoutManager curLinearLayoutManager = (LinearLayoutManager)layoutManager;
            if (curLinearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
                mOrientation = OrientationHelper.HORIZONTAL;
            } else {
                mOrientation = OrientationHelper.VERTICAL;
            }
            break;
        case FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_GRID:
            GridLayoutManager curGridLayoutManager = (GridLayoutManager)layoutManager;
            mGridSpanCount = curGridLayoutManager.getSpanCount();
            if (curGridLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
                mOrientation = OrientationHelper.HORIZONTAL;
            } else {
                mOrientation = OrientationHelper.VERTICAL;
            }
            break;
        case FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_STAGGERED_GRID:
            StaggeredGridLayoutManager curStaggeredGridLayoutManager = (StaggeredGridLayoutManager)layoutManager;
            mGridSpanCount = curStaggeredGridLayoutManager.getSpanCount();
            if (curStaggeredGridLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
                mOrientation = OrientationHelper.HORIZONTAL;
            } else {
                mOrientation = OrientationHelper.VERTICAL;
            }
            break;
        default:
            this.mLayoutManagerType = FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_LINEAR;
    }

    initDivisible();
}
 
Example #27
Source File: ScrollPageHelper.java    From YCRefreshView with Apache License 2.0 5 votes vote down vote up
@NonNull
private OrientationHelper getHorizontalHelper(
        @NonNull RecyclerView.LayoutManager layoutManager) {
    if (mHorizontalHelper == null) {
        mHorizontalHelper = OrientationHelper.createHorizontalHelper(layoutManager);
    }
    return mHorizontalHelper;
}
 
Example #28
Source File: GravitySnapHelper.java    From date_picker_converter with Apache License 2.0 5 votes vote down vote up
private View findEndView(RecyclerView.LayoutManager layoutManager,
                         OrientationHelper helper) {

    if (layoutManager instanceof LinearLayoutManager) {
        int lastChild = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();

        if (lastChild == RecyclerView.NO_POSITION) {
            return null;
        }

        View child = layoutManager.findViewByPosition(lastChild);

        float visibleWidth;

        if (isRtlHorizontal) {
            visibleWidth = (float) helper.getDecoratedEnd(child)
                    / helper.getDecoratedMeasurement(child);
        } else {
            visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
                    / helper.getDecoratedMeasurement(child);
        }

        // If we're at the start of the list, we shouldn't snap
        // to avoid having the first item not completely visible.
        boolean startOfList = ((LinearLayoutManager) layoutManager)
                .findFirstCompletelyVisibleItemPosition() == 0;

        if (visibleWidth > 0.5f && !startOfList) {
            return child;
        } else if (startOfList) {
            return null;
        } else {
            // If the child wasn't returned, we need to return the previous view
            return layoutManager.findViewByPosition(lastChild - 1);
        }
    }
    return null;
}
 
Example #29
Source File: GalleryLinearSnapHelper.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
private int estimateNextPositionDiffForFling(RecyclerView.LayoutManager layoutManager,
                                             OrientationHelper helper, int velocityX, int velocityY) {
    int[] distances = calculateScrollDistance(velocityX, velocityY);
    float distancePerChild = computeDistancePerChild(layoutManager, helper);
    if (distancePerChild <= 0) {
        return 0;
    }
    int distance = distances[0];
    if (distance > 0) {
        return (int) Math.floor(distance / distancePerChild);
    } else {
        return (int) Math.ceil(distance / distancePerChild);
    }
}
 
Example #30
Source File: ScrollPageHelper.java    From YCRefreshView with Apache License 2.0 5 votes vote down vote up
private int distanceToStart(View targetView, @NonNull OrientationHelper helper, boolean fromEnd) {
    if (isRtlHorizontal && !fromEnd) {
        return distanceToEnd(targetView, helper, true);
    }

    return helper.getDecoratedStart(targetView) - helper.getStartAfterPadding();
}