Skip to content

Commit

Permalink
Reset GravitySnapHelper on changing between horizontal/vertical examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensousa committed Aug 17, 2019
1 parent 915b3f2 commit 515a406
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,37 @@
import android.view.Gravity;
import android.view.MenuItem;

import com.github.rubensousa.gravitysnaphelper.GravitySnapHelper;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.github.rubensousa.gravitysnaphelper.GravitySnapHelper;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements Toolbar.OnMenuItemClickListener {

public static final String ORIENTATION = "orientation";

private RecyclerView mRecyclerView;
private boolean mHorizontal;
private GravitySnapHelper mGravitySnapHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
mGravitySnapHelper = new GravitySnapHelper(Gravity.TOP, false,
new GravitySnapHelper.SnapListener() {
@Override
public void onSnap(int position) {
Log.d("Snapped", position + "");
}
});
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.main);
toolbar.setOnMenuItemClickListener(this);
Expand Down Expand Up @@ -62,15 +70,11 @@ private void setupAdapter() {
snapAdapter.addSnap(new Snap(Gravity.END, "Snap end with padding", true, apps));
snapAdapter.addSnap(new Snap(Gravity.CENTER, "GravityPager snap", false, apps));
mRecyclerView.setAdapter(snapAdapter);
mGravitySnapHelper.attachToRecyclerView(null);
} 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);
mGravitySnapHelper.attachToRecyclerView(mRecyclerView);
}
}

Expand Down

0 comments on commit 515a406

Please sign in to comment.