Search in sources :

Example 1 with GravitySnapHelper

use of com.github.rubensousa.gravitysnaphelper.GravitySnapHelper in project RecyclerViewSnap by rubensousa.

the class GridActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_grid);
    mRecyclerView = findViewById(R.id.recyclerView);
    Adapter adapter = new Adapter(false, false, getApps());
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2, LinearLayoutManager.VERTICAL, true));
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setAdapter(adapter);
    new GravitySnapHelper(Gravity.TOP).attachToRecyclerView(mRecyclerView);
}
Also used : GravitySnapHelper(com.github.rubensousa.gravitysnaphelper.GravitySnapHelper) GridLayoutManager(android.support.v7.widget.GridLayoutManager)

Example 2 with GravitySnapHelper

use of com.github.rubensousa.gravitysnaphelper.GravitySnapHelper in project RecyclerViewSnap by rubensousa.

the class MainActivity method setupAdapter.

private void setupAdapter() {
    List<App> apps = getApps();
    SnapAdapter snapAdapter = new SnapAdapter();
    if (mHorizontal) {
        snapAdapter.addSnap(new Snap(Gravity.CENTER_HORIZONTAL, "Snap center", apps));
        snapAdapter.addSnap(new Snap(Gravity.START, "Snap start", apps));
        snapAdapter.addSnap(new Snap(Gravity.END, "Snap end", apps));
        snapAdapter.addSnap(new Snap(Gravity.CENTER, "GravityPager snap", apps));
        mRecyclerView.setAdapter(snapAdapter);
    } else {
        Adapter adapter = new Adapter(false, false, apps);
        mRecyclerView.setAdapter(adapter);
        new GravitySnapHelper(Gravity.TOP, false, new GravitySnapHelper.SnapListener() {

            @Override
            public void onSnap(int position) {
                Log.d("Snapped", position + "");
            }
        }).attachToRecyclerView(mRecyclerView);
    }
}
Also used : GravitySnapHelper(com.github.rubensousa.gravitysnaphelper.GravitySnapHelper)

Example 3 with GravitySnapHelper

use of com.github.rubensousa.gravitysnaphelper.GravitySnapHelper in project RecyclerViewSnap by rubensousa.

the class SnapAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Snap snap = mSnaps.get(position);
    holder.snapTextView.setText(snap.getText());
    if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
        new GravitySnapHelper(snap.getGravity(), false, this).attachToRecyclerView(holder.recyclerView);
    } else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL || snap.getGravity() == Gravity.CENTER_VERTICAL) {
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext(), snap.getGravity() == Gravity.CENTER_HORIZONTAL ? LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL, false));
        new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
    } else if (snap.getGravity() == Gravity.CENTER) {
        // Pager snap
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
        new GravityPagerSnapHelper(Gravity.START).attachToRecyclerView(holder.recyclerView);
    } else {
        // Top / Bottom
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext()));
        new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
    }
    holder.recyclerView.setAdapter(new Adapter(snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END || snap.getGravity() == Gravity.CENTER_HORIZONTAL, snap.getGravity() == Gravity.CENTER, snap.getApps()));
}
Also used : GravitySnapHelper(com.github.rubensousa.gravitysnaphelper.GravitySnapHelper) LinearSnapHelper(android.support.v7.widget.LinearSnapHelper) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) GravityPagerSnapHelper(com.github.rubensousa.gravitysnaphelper.GravityPagerSnapHelper)

Aggregations

GravitySnapHelper (com.github.rubensousa.gravitysnaphelper.GravitySnapHelper)3 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 LinearSnapHelper (android.support.v7.widget.LinearSnapHelper)1 GravityPagerSnapHelper (com.github.rubensousa.gravitysnaphelper.GravityPagerSnapHelper)1