Search in sources :

Example 1 with SimpleTracker

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);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter) SimpleTracker(com.alexvasilkov.gestures.transition.tracker.SimpleTracker)

Example 2 with SimpleTracker

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));
}
Also used : RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter) View(android.view.View) ListView(android.widget.ListView) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter) SimpleTracker(com.alexvasilkov.gestures.transition.tracker.SimpleTracker) Painting(com.alexvasilkov.gestures.sample.ex.utils.Painting)

Example 3 with SimpleTracker

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));
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter) SimpleTracker(com.alexvasilkov.gestures.transition.tracker.SimpleTracker) Painting(com.alexvasilkov.gestures.sample.ex.utils.Painting)

Example 4 with SimpleTracker

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);
}
Also used : NonNull(android.support.annotation.NonNull) RecyclerView(android.support.v7.widget.RecyclerView) FromTracker(com.alexvasilkov.gestures.transition.tracker.FromTracker) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter) SimpleTracker(com.alexvasilkov.gestures.transition.tracker.SimpleTracker) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter)

Aggregations

RecyclePagerAdapter (com.alexvasilkov.gestures.commons.RecyclePagerAdapter)4 SimpleTracker (com.alexvasilkov.gestures.transition.tracker.SimpleTracker)4 RecyclerView (android.support.v7.widget.RecyclerView)3 Painting (com.alexvasilkov.gestures.sample.ex.utils.Painting)2 NonNull (android.support.annotation.NonNull)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 View (android.view.View)1 ListView (android.widget.ListView)1 FromTracker (com.alexvasilkov.gestures.transition.tracker.FromTracker)1