Search in sources :

Example 1 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project UltimateAndroid by cymcsg.

the class StaggeredGridLayoutManager method moveLayoutToPosition.

@Override
void moveLayoutToPosition(int position, int offset, Recycler recycler, State state) {
    final boolean isVertical = isVertical();
    final Lanes lanes = getLanes();
    lanes.reset(0);
    for (int i = 0; i <= position; i++) {
        StaggeredItemEntry entry = (StaggeredItemEntry) getItemEntryForPosition(i);
        if (entry != null) {
            mTempLaneInfo.set(entry.startLane, entry.anchorLane);
            // removed item. See BaseLayoutManager.invalidateItemLanes().
            if (mTempLaneInfo.isUndefined()) {
                lanes.findLane(mTempLaneInfo, getLaneSpanForPosition(i), Direction.END);
                entry.setLane(mTempLaneInfo);
            }
            lanes.getChildFrame(mTempRect, entry.width, entry.height, mTempLaneInfo, Direction.END);
        } else {
            final View child = recycler.getViewForPosition(i);
            // XXX: This might potentially cause stalls in the main
            // thread if the layout ends up having to measure tons of
            // child views. We might need to add different policies based
            // on known assumptions regarding certain layouts e.g. child
            // views have stable aspect ratio, lane size is fixed, etc.
            measureChild(child, Direction.END);
            // The measureChild() call ensures an entry is created for
            // this position.
            entry = (StaggeredItemEntry) getItemEntryForPosition(i);
            mTempLaneInfo.set(entry.startLane, entry.anchorLane);
            lanes.getChildFrame(mTempRect, getDecoratedMeasuredWidth(child), getDecoratedMeasuredHeight(child), mTempLaneInfo, Direction.END);
            cacheItemFrame(entry, mTempRect);
        }
        if (i != position) {
            pushChildFrame(entry, mTempRect, entry.startLane, entry.span, Direction.END);
        }
    }
    lanes.getLane(mTempLaneInfo.startLane, mTempRect);
    lanes.reset(Direction.END);
    lanes.offset(offset - (isVertical ? mTempRect.bottom : mTempRect.right));
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 2 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project UltimateAndroid by cymcsg.

the class TwoWayLayoutManager method recycleChildrenFromEnd.

private void recycleChildrenFromEnd(Direction direction, Recycler recycler) {
    final int childrenEnd = getEndWithPadding();
    final int childCount = getChildCount();
    int firstDetachedPos = 0;
    int detachedCount = 0;
    for (int i = childCount - 1; i >= 0; i--) {
        final View child = getChildAt(i);
        final int childStart = getChildStart(child);
        if (childStart <= childrenEnd) {
            break;
        }
        firstDetachedPos = i;
        detachedCount++;
        detachChild(child, direction);
    }
    while (--detachedCount >= 0) {
        final View child = getChildAt(firstDetachedPos);
        removeAndRecycleViewAt(firstDetachedPos, recycler);
        updateLayoutEdgesFromRemovedChild(child, direction);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 3 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project RecyclerRefreshLayout by dinuscxj.

the class HeaderViewRecyclerAdapter method adjustSpanSize.

public void adjustSpanSize(RecyclerView recycler) {
    if (recycler.getLayoutManager() instanceof GridLayoutManager) {
        final GridLayoutManager layoutManager = (GridLayoutManager) recycler.getLayoutManager();
        layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                boolean isHeaderOrFooter = isHeaderPosition(position) || isFooterPosition(position);
                return isHeaderOrFooter ? layoutManager.getSpanCount() : 1;
            }
        });
    }
    if (recycler.getLayoutManager() instanceof StaggeredGridLayoutManager) {
        this.mIsStaggeredGrid = true;
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager)

Example 4 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project SuperSLiM by TonicArtos.

the class LayoutManager method scrollVerticallyBy.

@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
    int numChildren = getChildCount();
    if (numChildren == 0) {
        return 0;
    }
    LayoutState layoutState = new LayoutState(this, recycler, state);
    final Direction direction = dy > 0 ? Direction.END : Direction.START;
    final boolean isDirectionEnd = direction == Direction.END;
    final int height = getHeight();
    final int leadingEdge = isDirectionEnd ? height + dy : dy;
    // from the bottom up.
    if (isDirectionEnd) {
        final View end = getAnchorAtEnd();
        LayoutParams params = (LayoutParams) end.getLayoutParams();
        SectionLayoutManager slm = getSlm(params);
        final int endEdge = slm.getLowestEdge(params.getTestedFirstPosition(), getChildCount() - 1, getDecoratedBottom(end));
        if (endEdge < height - getPaddingBottom() && getPosition(end) == (state.getItemCount() - 1)) {
            return 0;
        }
    }
    final int fillEdge = fillUntil(leadingEdge, direction, layoutState);
    final int delta;
    if (isDirectionEnd) {
        // Add padding so we scroll to inset area at scroll end.
        int fillDelta = fillEdge - height + getPaddingBottom();
        delta = fillDelta < dy ? fillDelta : dy;
    } else {
        int fillDelta = fillEdge - getPaddingTop();
        delta = fillDelta > dy ? fillDelta : dy;
    }
    if (delta != 0) {
        offsetChildrenVertical(-delta);
        trimTail(isDirectionEnd ? Direction.START : Direction.END, layoutState);
    }
    layoutState.recycleCache();
    return delta;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 5 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project SeriesGuide by UweTrottmann.

the class ShowsNowFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_now, container, false);
    unbinder = ButterKnife.bind(this, v);
    swipeRefreshLayout.setSwipeableChildren(R.id.scrollViewNow, R.id.recyclerViewNow);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refreshStream();
        }
    });
    swipeRefreshLayout.setProgressViewOffset(false, getResources().getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_start_margin), getResources().getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_end_margin));
    emptyView.setText(R.string.now_empty);
    showError(null);
    snackbarButton.setText(R.string.refresh);
    snackbarButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            refreshStream();
        }
    });
    // recycler view layout manager
    final int spanCount = getResources().getInteger(R.integer.grid_column_count);
    final GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), spanCount);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            if (adapter == null) {
                return 1;
            }
            if (position >= adapter.getItemCount()) {
                return 1;
            }
            // make headers and more links span all columns
            int type = adapter.getItem(position).type;
            return (type == NowAdapter.ItemType.HEADER || type == NowAdapter.ItemType.MORE_LINK) ? spanCount : 1;
        }
    });
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(new GridInsetDecoration(getResources()));
    recyclerView.setHasFixedSize(true);
    return v;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) GridInsetDecoration(com.battlelancer.seriesguide.util.GridInsetDecoration) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) EmptyViewSwipeRefreshLayout(com.battlelancer.seriesguide.widgets.EmptyViewSwipeRefreshLayout) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)106 View (android.view.View)100 TextView (android.widget.TextView)19 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)15 ImageView (android.widget.ImageView)13 OrientationHelper (android.support.v7.widget.OrientationHelper)12 GridLayoutManager (android.support.v7.widget.GridLayoutManager)10 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)10 Point (android.graphics.Point)7 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)7 SuppressLint (android.annotation.SuppressLint)6 Context (android.content.Context)6 Bundle (android.os.Bundle)6 ActivityManager (android.app.ActivityManager)5 AccessibilityNodeInfoCompat (android.support.v4.view.accessibility.AccessibilityNodeInfoCompat)5 SpanSizeLookup (android.support.v7.widget.GridLayoutManager.SpanSizeLookup)5 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)5 Recycler (android.support.v7.widget.RecyclerView.Recycler)5 RecyclerListener (android.support.v7.widget.RecyclerView.RecyclerListener)5 ViewGroup (android.view.ViewGroup)5