Search in sources :

Example 1 with FromTracker

use of com.alexvasilkov.gestures.transition.tracker.FromTracker 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 FromTracker

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

the class ListAnyToAnyActivity 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) Objects.requireNonNull(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(androidx.annotation.NonNull) RecyclerView(androidx.recyclerview.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)

Example 3 with FromTracker

use of com.alexvasilkov.gestures.transition.tracker.FromTracker 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)

Example 4 with FromTracker

use of com.alexvasilkov.gestures.transition.tracker.FromTracker 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 FromTracker (com.alexvasilkov.gestures.transition.tracker.FromTracker)4 NonNull (android.support.annotation.NonNull)2 RecyclerView (android.support.v7.widget.RecyclerView)2 NonNull (androidx.annotation.NonNull)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 IntoTracker (com.alexvasilkov.gestures.transition.tracker.IntoTracker)2 SimpleTracker (com.alexvasilkov.gestures.transition.tracker.SimpleTracker)2