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

The following examples show how to use android.support.v7.widget.RecyclerView#getContext() . 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: CommunityFragment.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setLayoutManager(final RecyclerView recyclerView) {

    final GridLayoutManager gridLayoutManager = new GridLayoutManager(recyclerView.getContext(), AptoideUtils.UI.getEditorChoiceBucketSize());
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {

            if(!(recyclerView.getAdapter() instanceof SpannableRecyclerAdapter)){
                throw new IllegalStateException("RecyclerView adapter must extend SpannableRecyclerAdapter");
            }

            int spanSize = ((SpannableRecyclerAdapter) recyclerView.getAdapter()).getSpanSize(position);
            if (spanSize >= ((GridLayoutManager) recyclerView.getLayoutManager()).getSpanCount()) {
                return ((GridLayoutManager) recyclerView.getLayoutManager()).getSpanCount();
            } else {
                return spanSize;
            }
        }
    });

    // we need to force the spanCount, or it will crash.
    // https://code.google.com/p/android/issues/detail?id=182400
    gridLayoutManager.setSpanCount(AptoideUtils.UI.getEditorChoiceBucketSize());
    recyclerView.setLayoutManager(gridLayoutManager);
}
 
Example 2
Source File: SupportDividerItemDecoration.java    From fangzhuishushenqi with Apache License 2.0 6 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        android.support.v7.widget.RecyclerView v = new android.support.v7.widget.RecyclerView(parent.getContext());
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 3
Source File: SpeedyLinearLayoutManager.java    From diycode with Apache License 2.0 6 votes vote down vote up
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int
        position) {

    final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView
            .getContext()) {

        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return SpeedyLinearLayoutManager.this.computeScrollVectorForPosition
                    (targetPosition);
        }

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };

    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
Example 4
Source File: WheelPickerLayoutManager.java    From RecyclerWheelPicker with Apache License 2.0 6 votes vote down vote up
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }

        @Nullable
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return WheelPickerLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }
    };

    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
Example 5
Source File: ChannelFragmentAdapter.java    From letv with Apache License 2.0 6 votes vote down vote up
private ImageView addMirrorView(ViewGroup parent, RecyclerView recyclerView, View view) {
    view.destroyDrawingCache();
    view.setDrawingCacheEnabled(true);
    ImageView mirrorView = new ImageView(recyclerView.getContext());
    Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
    mirrorView.setImageBitmap(bitmap);
    view.setDrawingCacheEnabled(false);
    int[] locations = new int[2];
    view.getLocationOnScreen(locations);
    int[] parenLocations = new int[2];
    recyclerView.getLocationOnScreen(parenLocations);
    LayoutParams params = new LayoutParams(bitmap.getWidth(), bitmap.getHeight());
    params.setMargins(locations[0], (locations[1] - parenLocations[1]) + UIsUtils.dipToPx(44.0f), 0, 0);
    parent.addView(mirrorView, params);
    return mirrorView;
}
 
Example 6
Source File: PreCachingLayoutManager.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {

    final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {

        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return PreCachingLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };

    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
Example 7
Source File: DividerItemDecoration.java    From AndroidDemo with MIT License 6 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent)
{
	final int left = parent.getPaddingLeft() + DIVIDER_PADING_LEFT;
	final int right = parent.getWidth() - parent.getPaddingRight();

	final int childCount = parent.getChildCount();

	for (int i = 0; i < childCount; i++)
	{
		final View child = parent.getChildAt(i);
		RecyclerView v = new RecyclerView(
				parent.getContext());
		final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
				.getLayoutParams();
		final int top = child.getBottom() + params.bottomMargin;
		final int bottom = top + mDivider.getIntrinsicHeight();
		mDivider.setBounds(left, top, right, bottom);
		mDivider.draw(c);
	}
}
 
Example 8
Source File: EasyRecyclerViewManagerBuilder.java    From easyrecycleradapters with Apache License 2.0 6 votes vote down vote up
public EasyRecyclerViewManagerBuilder(RecyclerView recyclerView, EasyRecyclerAdapter adapter) {
    if (recyclerView == null) {
        throw new IllegalArgumentException("RecyclerView must not be null.");
    }
    if (recyclerView.getContext() == null) {
        throw new IllegalArgumentException("Context must not be null.");
    }
    if (adapter == null) {
        throw new IllegalArgumentException("Adapter must not be null.");
    }
    this.context = recyclerView.getContext().getApplicationContext();
    this.recyclerView = recyclerView;
    this.adapter = adapter;
    this.emptyTextColor = context.getResources().getColor(R.color.empty_list_text_color);
    this.loadingTextColor = context.getResources().getColor(R.color.empty_list_text_color);
}
 
Example 9
Source File: DividerItemDecoration.java    From DesignSupportDemo with Apache License 2.0 6 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        android.support.v7.widget.RecyclerView v = new android.support.v7.widget.RecyclerView(parent.getContext());
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 10
Source File: DividerItemDecoration.java    From MarkdownEditors with Apache License 2.0 6 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        android.support.v7.widget.RecyclerView v = new android.support.v7.widget.RecyclerView(parent.getContext());
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 11
Source File: ScrollSpeedLinearLayoutManager.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()){
        @Nullable
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return ScrollSpeedLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            setSpeedSlow();
            return MILLISECONDS_PER_INCH / displayMetrics.density;
        }
    };

    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);

}
 
Example 12
Source File: SnappingLinearLayoutManager.java    From PowerSwitch_Android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state,
                                   int position) {
    RecyclerView.SmoothScroller smoothScroller = new TopSnappedSmoothScroller(recyclerView.getContext()) {
        //This controls the direction in which smoothScroll looks for your view
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return new PointF(0, 1);
        }

        //This returns the milliseconds it takes to scroll one pixel.
        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
Example 13
Source File: EventFragment.java    From MiPushFramework with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    RecyclerView view = new RecyclerView(getActivity());
    view.setLayoutManager(new LinearLayoutManager(getActivity(),
            LinearLayoutManager.VERTICAL, false));
    view.setAdapter(mAdapter);
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(view.getContext(),
            LinearLayoutManager.VERTICAL);
    view.addItemDecoration(dividerItemDecoration);
    view.addOnScrollListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            loadPage();
        }
    });

    swipeRefreshLayout = new SwipeRefreshLayout(getActivity());
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.addView(view);
    return swipeRefreshLayout;
}
 
Example 14
Source File: ListContentFragment.java    From android-design-library with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    RecyclerView recyclerView = (RecyclerView) inflater.inflate(
            R.layout.recycler_view, container, false);
    ContentAdapter adapter = new ContentAdapter(recyclerView.getContext());
    recyclerView.setAdapter(adapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    return recyclerView;
}
 
Example 15
Source File: MainActivity.java    From ReadMoreOption 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 = (RecyclerView)findViewById(R.id.my_recycler_view);
        LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(mLayoutManager);
        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
                mLayoutManager.getOrientation());
        recyclerView.addItemDecoration(dividerItemDecoration);
        MyAdapter mAdapter = new MyAdapter(this);
        recyclerView.setAdapter(mAdapter);


//        TextView tv = (TextView)findViewById(R.id.tv);
//        tv.setText(getString(R.string.dummy_text));
//
//        ReadMoreOption readMoreOption = new ReadMoreOption.Builder(this)
//              // Optional parameters
//                .textLength(3, ReadMoreOption.TYPE_LINE) //OR
//              //.textLength(300, ReadMoreOption.TYPE_CHARACTER)
//                .moreLabel("MORE")
//                .lessLabel("LESS")
//                .moreLabelColor(Color.RED)
//                .lessLabelColor(Color.BLUE)
//                .labelUnderLine(true)
//                .expandAnimation(true)
//                .build();
//        readMoreOption.addReadMoreTo(tv, getString(R.string.dummy_text));

    }
 
Example 16
Source File: RecyclerViewHelper.java    From Android-RecyclerViewHelper with Apache License 2.0 5 votes vote down vote up
public RecyclerViewHelper(RecyclerView recyclerView, RecyclerView.Adapter itemAdapter,
                          RecyclerView.LayoutManager layoutManager) {
    this.recyclerView = recyclerView;
    this.itemAdapter = itemAdapter;

    if (layoutManager == null) {
        this.layoutManager = new LinearLayoutManager(recyclerView.getContext());
    } else {
        this.layoutManager = layoutManager;
    }

    setup();
}
 
Example 17
Source File: BasePullBindingAdapter.java    From CoreModule with Apache License 2.0 4 votes vote down vote up
public BasePullBindingAdapter(RecyclerView v, int itemLayoutId) {
    super(v.getContext(), itemLayoutId);
    v.addOnScrollListener(new BasePullUpScrollListener());
    footerView = new FooterView(cxt);
}
 
Example 18
Source File: ToolbarActivity.java    From moserp with Apache License 2.0 4 votes vote down vote up
protected void initRecyclerView(RecyclerView view) {
    view.setHasFixedSize(true);
    view.addItemDecoration(new DividerItemDecoration(getApplicationContext(), null));
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(view.getContext());
    view.setLayoutManager(mLayoutManager);
}
 
Example 19
Source File: GroupAdapter.java    From NovelReader with MIT License 4 votes vote down vote up
public GroupAdapter(RecyclerView recyclerView,int spanSize){
    GridLayoutManager manager = new GridLayoutManager(recyclerView.getContext(),spanSize);
    manager.setSpanSizeLookup(new GroupSpanSizeLookup(spanSize));
    recyclerView.setLayoutManager(manager);
}
 
Example 20
Source File: WrapLinearLayoutManager.java    From beaconloc with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
public WrapLinearLayoutManager(RecyclerView view) {
    super(view.getContext());
    this.view = view;
    this.overScrollMode = ViewCompat.getOverScrollMode(view);
}