Search in sources :

Example 1 with IntoTracker

use of com.alexvasilkov.gestures.transition.tracker.IntoTracker in project GestureViews by alexvasilkov.

the class ListAnyToAllActivity 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 all images from across all list items in a pager.
    // We will use combination {list item position, image position} to precisely identify each
    // image and its position in the list. We will also need to map images positions inside
    // the pager to there list positions and vice versa, see data preparations above.
    final FromTracker<Position> listTracker = new FromTracker<Position>() {

        @Override
        public View getViewById(@NonNull Position pos) {
            // We should return image view of particular image inside corresponding list item
            RecyclerView.ViewHolder holder = list.findViewHolderForLayoutPosition(pos.itemPos);
            return holder == null ? null : ListAdapter.getImageView(holder, pos.imagePos);
        }

        @Override
        public int getPositionById(@NonNull Position pos) {
            // We should return position of corresponding list item
            return pos.itemPos;
        }
    };
    final IntoTracker<Position> pagerTracker = new IntoTracker<Position>() {

        @Override
        public Position getIdByPosition(int position) {
            // We should return list position for corresponding pager position
            return positions.get(position);
        }

        @Override
        public int getPositionById(@NonNull Position pos) {
            // We should return pager position for corresponding list position
            return positions.indexOf(pos);
        }

        @Override
        public View getViewById(@NonNull Position pos) {
            // We should return image view for a given pager position
            int pagerPos = getPositionById(pos);
            PagerAdapter adapter = (PagerAdapter) Objects.requireNonNull(pager.getAdapter());
            RecyclePagerAdapter.ViewHolder holder = adapter.getViewHolder(pagerPos);
            return holder == null ? null : PagerAdapter.getImageView(holder);
        }
    };
    return animator = GestureTransitions.from(list, listTracker).into(pager, pagerTracker);
}
Also used : NonNull(androidx.annotation.NonNull) RecyclerView(androidx.recyclerview.widget.RecyclerView) IntoTracker(com.alexvasilkov.gestures.transition.tracker.IntoTracker) FromTracker(com.alexvasilkov.gestures.transition.tracker.FromTracker) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter)

Example 2 with IntoTracker

use of com.alexvasilkov.gestures.transition.tracker.IntoTracker in project GestureViews by alexvasilkov.

the class ComplexListV1Activity 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 all images from across all list items in a pager.
    // We will use combination {list item position, image position} to precisely identify each
    // image and its position in the list. We will also need to map images positions inside
    // the pager to there list positions and vice versa, see data preparations above.
    final FromTracker<Position> listTracker = new FromTracker<Position>() {

        @Override
        public View getViewById(@NonNull Position pos) {
            // We should return image view of particular image inside corresponding list item
            RecyclerView.ViewHolder holder = list.findViewHolderForLayoutPosition(pos.itemPos);
            return holder == null ? null : ListAdapter.getImageView(holder, pos.imagePos);
        }

        @Override
        public int getPositionById(@NonNull Position pos) {
            // We should return position of corresponding list item
            return pos.itemPos;
        }
    };
    final IntoTracker<Position> pagerTracker = new IntoTracker<Position>() {

        @Override
        public Position getIdByPosition(int position) {
            // We should return list position for corresponding pager position
            return positions.get(position);
        }

        @Override
        public int getPositionById(@NonNull Position pos) {
            // We should return pager position for corresponding list position
            return positions.indexOf(pos);
        }

        @Override
        public View getViewById(@NonNull Position pos) {
            // We should return image view for a given pager position
            int pagerPos = getPositionById(pos);
            PagerAdapter adapter = (PagerAdapter) pager.getAdapter();
            RecyclePagerAdapter.ViewHolder holder = adapter.getViewHolder(pagerPos);
            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) IntoTracker(com.alexvasilkov.gestures.transition.tracker.IntoTracker) FromTracker(com.alexvasilkov.gestures.transition.tracker.FromTracker) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter) RecyclePagerAdapter(com.alexvasilkov.gestures.commons.RecyclePagerAdapter)

Aggregations

RecyclePagerAdapter (com.alexvasilkov.gestures.commons.RecyclePagerAdapter)2 FromTracker (com.alexvasilkov.gestures.transition.tracker.FromTracker)2 IntoTracker (com.alexvasilkov.gestures.transition.tracker.IntoTracker)2 NonNull (android.support.annotation.NonNull)1 RecyclerView (android.support.v7.widget.RecyclerView)1 NonNull (androidx.annotation.NonNull)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1