use of com.alexvasilkov.gestures.transition.tracker.SimpleTracker in project GestureViews by alexvasilkov.
the class DemoActivity method initPagerAnimator.
/**
* Initializing grid-to-pager animation.
*/
private void initPagerAnimator() {
final SimpleTracker gridTracker = new SimpleTracker() {
@Override
public View getViewAt(int pos) {
RecyclerView.ViewHolder holder = views.grid.findViewHolderForLayoutPosition(pos);
return holder == null ? null : PhotoListAdapter.getImage(holder);
}
};
final SimpleTracker pagerTracker = new SimpleTracker() {
@Override
public View getViewAt(int pos) {
RecyclePagerAdapter.ViewHolder holder = pagerAdapter.getViewHolder(pos);
return holder == null ? null : PhotoPagerAdapter.getImage(holder);
}
};
listAnimator = GestureTransitions.from(views.grid, gridTracker).into(views.pager, pagerTracker);
// Setting up and animating image transition
listAnimator.addPositionUpdateListener(this::applyFullPagerState);
}
use of com.alexvasilkov.gestures.transition.tracker.SimpleTracker in project GestureViews by alexvasilkov.
the class ListViewToPagerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_screen);
final Painting[] paintings = Painting.list(getResources());
// Initializing ListView
list = findViewById(R.id.list_view);
list.setAdapter(new ListAdapter(paintings, this::onPaintingClick));
// Initializing ViewPager
pager = findViewById(R.id.list_pager);
pagerAdapter = new PagerAdapter(pager, paintings, getSettingsController());
pager.setAdapter(pagerAdapter);
pager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.view_pager_margin));
// Initializing images animator. It requires us to provide FromTracker and IntoTracker items
// that are used to find images views for particular item IDs in the list and in the pager
// to keep them in sync.
// In this example we will use SimpleTracker which will track images by their positions,
// if you have a more complicated case see "complex" package for advanced examples.
final SimpleTracker listTracker = new SimpleTracker() {
@Override
public View getViewAt(int position) {
View itemView = list.getChildAt(position - list.getFirstVisiblePosition());
return itemView == null ? null : ListAdapter.getImageView(itemView);
}
};
final SimpleTracker pagerTracker = new SimpleTracker() {
@Override
public View getViewAt(int position) {
RecyclePagerAdapter.ViewHolder holder = pagerAdapter.getViewHolder(position);
return holder == null ? null : PagerAdapter.getImageView(holder);
}
};
animator = GestureTransitions.from(list, listTracker).into(pager, pagerTracker);
// Setting up background animation during image transition
background = findViewById(R.id.list_full_background);
animator.addPositionUpdateListener((pos, isLeaving) -> applyImageAnimationState(pos));
}
use of com.alexvasilkov.gestures.transition.tracker.SimpleTracker in project GestureViews by alexvasilkov.
the class RecyclerToPagerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_recycler_screen);
final Painting[] paintings = Painting.list(getResources());
// Initializing ListView
list = findViewById(R.id.recycler_list);
list.setLayoutManager(new LinearLayoutManager(this));
list.setAdapter(new RecyclerAdapter(paintings, this::onPaintingClick));
// Initializing ViewPager
pager = findViewById(R.id.recycler_pager);
pagerAdapter = new PagerAdapter(pager, paintings, getSettingsController());
pager.setAdapter(pagerAdapter);
pager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.view_pager_margin));
// Initializing images animator. It requires us to provide FromTracker and IntoTracker items
// that are used to find images views for particular item IDs in the list and in the pager
// to keep them in sync.
// In this example we will use SimpleTracker which will track images by their positions,
// if you have a more complicated case see further examples.
final SimpleTracker listTracker = new SimpleTracker() {
@Override
public View getViewAt(int position) {
RecyclerView.ViewHolder holder = list.findViewHolderForLayoutPosition(position);
return holder == null ? null : RecyclerAdapter.getImageView(holder);
}
};
final SimpleTracker pagerTracker = new SimpleTracker() {
@Override
public View getViewAt(int position) {
RecyclePagerAdapter.ViewHolder holder = pagerAdapter.getViewHolder(position);
return holder == null ? null : PagerAdapter.getImageView(holder);
}
};
animator = GestureTransitions.from(list, listTracker).into(pager, pagerTracker);
// Setting up background animation during image transition
background = findViewById(R.id.recycler_full_background);
animator.addPositionUpdateListener((pos, isLeaving) -> applyImageAnimationState(pos));
}
use of com.alexvasilkov.gestures.transition.tracker.SimpleTracker in project GestureViews by alexvasilkov.
the class ComplexListV2Activity method createAnimator.
@Override
protected ViewsTransitionAnimator createAnimator(final RecyclerView list, final ViewPager pager) {
// Initializing images animator. It requires us to provide FromTracker and IntoTracker items
// that are used to find images views for particular item IDs in the list and in the pager
// to keep them in sync.
// In this example we will show several images from single list item in a pager.
// When image is clicked we will store selected list item position locally and then request
// particular image within this item (by image position inside the item).
final FromTracker<Integer> listTracker = new FromTracker<Integer>() {
@Override
public View getViewById(@NonNull Integer imagePos) {
// We should return image view of particular image inside current list item
RecyclerView.ViewHolder holder = list.findViewHolderForLayoutPosition(currItemPos);
return holder == null ? null : ListAdapter.getImageView(holder, imagePos);
}
@Override
public int getPositionById(@NonNull Integer imagePos) {
// images belonging to a single list item we can just return this item's position
return currItemPos;
}
};
final IntoTracker<Integer> pagerTracker = new SimpleTracker() {
@Override
protected View getViewAt(int imagePos) {
// We should return image view for a given pager position
PagerAdapter adapter = (PagerAdapter) pager.getAdapter();
RecyclePagerAdapter.ViewHolder holder = adapter.getViewHolder(imagePos);
return holder == null ? null : PagerAdapter.getImageView(holder);
}
};
return animator = GestureTransitions.from(list, listTracker).into(pager, pagerTracker);
}
Aggregations