Search in sources :

Example 31 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project GestureViews by alexvasilkov.

the class EndlessRecyclerAdapter method loadNextItemsIfNeeded.

private void loadNextItemsIfNeeded(RecyclerView recyclerView) {
    if (!isLoading && !isError) {
        View lastVisibleChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1);
        int lastVisiblePos = recyclerView.getChildAdapterPosition(lastVisibleChild);
        int total = getItemCount();
        if (lastVisiblePos >= total - loadingOffset) {
            // We need to use runnable, since recycler view does not like when we are notifying
            // about changes during scroll callback.
            recyclerView.post(new Runnable() {

                @Override
                public void run() {
                    loadNextItems();
                }
            });
        }
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 32 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project Carbon by ZieIony.

the class IconTextListItemActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listcomponent);
    Samples.initToolbar(this, getString(R.string.iconTextListItemActivity_title));
    RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
    recycler.setLayoutManager(new LinearLayoutManager(this));
    RowListAdapter adapter = new RowListAdapter<>(DefaultIconTextItem.class, IconTextRow::new);
    adapter.addFactory(DefaultIconSearchItem.class, parent -> new IconSearchRow(parent, new ArraySearchDataProvider(new String[] {}), filterResults -> {
    }));
    recycler.setAdapter(adapter);
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(new ColorDrawable(Carbon.getThemeColor(this, R.attr.carbon_dividerColor)), getResources().getDimensionPixelSize(R.dimen.carbon_1dip));
    dividerItemDecoration.setDrawRules(position -> position == 0);
    recycler.addItemDecoration(dividerItemDecoration);
    VectorDrawable drawable = new VectorDrawable(getResources(), R.raw.ic_face_24px);
    adapter.setItems(Arrays.asList(new DefaultIconSearchItem(this), new DefaultIconTextItem(drawable, "text"), new DefaultIconTextItem(drawable, "text"), new DefaultIconTextItem(drawable, "text"), new DefaultIconTextItem(drawable, "text")));
}
Also used : Arrays(java.util.Arrays) Bundle(android.os.Bundle) IconSearchRow(carbon.component.IconSearchRow) DividerItemDecoration(carbon.recycler.DividerItemDecoration) IconTextRow(carbon.component.IconTextRow) ColorDrawable(android.graphics.drawable.ColorDrawable) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultIconTextItem(carbon.component.DefaultIconTextItem) DefaultIconSearchItem(carbon.component.DefaultIconSearchItem) Carbon(carbon.Carbon) RecyclerView(carbon.widget.RecyclerView) SamplesActivity(tk.zielony.carbonsamples.SamplesActivity) VectorDrawable(carbon.drawable.VectorDrawable) R(tk.zielony.carbonsamples.R) RowListAdapter(carbon.recycler.RowListAdapter) Nullable(android.support.annotation.Nullable) ArraySearchDataProvider(carbon.widget.ArraySearchDataProvider) Samples(tk.zielony.carbonsamples.Samples) DefaultIconSearchItem(carbon.component.DefaultIconSearchItem) ColorDrawable(android.graphics.drawable.ColorDrawable) IconTextRow(carbon.component.IconTextRow) RowListAdapter(carbon.recycler.RowListAdapter) RecyclerView(carbon.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(carbon.recycler.DividerItemDecoration) DefaultIconTextItem(carbon.component.DefaultIconTextItem) IconSearchRow(carbon.component.IconSearchRow) VectorDrawable(carbon.drawable.VectorDrawable) ArraySearchDataProvider(carbon.widget.ArraySearchDataProvider)

Example 33 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project Carbon by ZieIony.

the class ImageTextSubtextDateListItemActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listcomponent);
    Samples.initToolbar(this, getString(R.string.imageTextSubtextDateListItemActivity_title));
    RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
    recycler.setLayoutManager(new LinearLayoutManager(this));
    RowListAdapter adapter = new RowListAdapter<>(DefaultImageTextSubtextDateItem.class, ImageTextSubtextDateRow::new);
    adapter.addFactory(DefaultHeaderItem.class, PaddedHeaderRow.FACTORY);
    recycler.setAdapter(adapter);
    Drawable drawable = getResources().getDrawable(R.drawable.watermelon);
    String date = format.format(new Date().getTime());
    adapter.setItems(Arrays.asList(new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date)));
}
Also used : DefaultHeaderItem(carbon.component.DefaultHeaderItem) ImageTextSubtextDateRow(carbon.component.ImageTextSubtextDateRow) Drawable(android.graphics.drawable.Drawable) RowListAdapter(carbon.recycler.RowListAdapter) RecyclerView(carbon.widget.RecyclerView) DefaultImageTextSubtextDateItem(carbon.component.DefaultImageTextSubtextDateItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Date(java.util.Date)

Example 34 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 35 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)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)113 View (android.view.View)107 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)20 TextView (android.widget.TextView)19 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 Bundle (android.os.Bundle)7 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)7 SuppressLint (android.annotation.SuppressLint)6 Context (android.content.Context)6 ViewGroup (android.view.ViewGroup)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