Search in sources :

Example 1 with AnchorViewState

use of com.beloo.widget.chipslayoutmanager.anchor.AnchorViewState in project ChipsLayoutManager by BelooS.

the class HorizontalScrollingController method createSmoothScroller.

@Override
public RecyclerView.SmoothScroller createSmoothScroller(@NonNull Context context, final int position, final int timeMs, final AnchorViewState anchor) {
    return new LinearSmoothScroller(context) {

        /*
             * LinearSmoothScroller, at a minimum, just need to know the vector
             * (x/y distance) to travel in order to get from the current positioning
             * to the target.
             */
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            int visiblePosition = anchor.getPosition();
            //determine scroll up or scroll down needed
            return new PointF(position > visiblePosition ? 1 : -1, 0);
        }

        @Override
        protected void onTargetFound(View targetView, RecyclerView.State state, Action action) {
            super.onTargetFound(targetView, state, action);
            int currentLeft = layoutManager.getPaddingLeft();
            int desiredLeft = layoutManager.getDecoratedLeft(targetView);
            int dx = desiredLeft - currentLeft;
            //perform fit animation to move target view at top of layoutX
            action.update(dx, 0, timeMs, new LinearInterpolator());
        }
    };
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) AnchorViewState(com.beloo.widget.chipslayoutmanager.anchor.AnchorViewState) PointF(android.graphics.PointF) LinearSmoothScroller(android.support.v7.widget.LinearSmoothScroller) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 2 with AnchorViewState

use of com.beloo.widget.chipslayoutmanager.anchor.AnchorViewState in project ChipsLayoutManager by BelooS.

the class VerticalScrollingController method createSmoothScroller.

@Override
public RecyclerView.SmoothScroller createSmoothScroller(@NonNull Context context, final int position, final int timeMs, final AnchorViewState anchor) {
    return new LinearSmoothScroller(context) {

        /*
             * LinearSmoothScroller, at a minimum, just need to know the vector
             * (x/y distance) to travel in order to get from the current positioning
             * to the target.
             */
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            int visiblePosition = anchor.getPosition();
            //determine scroll up or scroll down needed
            return new PointF(0, position > visiblePosition ? 1 : -1);
        }

        @Override
        protected void onTargetFound(View targetView, RecyclerView.State state, Action action) {
            super.onTargetFound(targetView, state, action);
            int desiredTop = lm.getPaddingTop();
            int currentTop = lm.getDecoratedTop(targetView);
            int dy = currentTop - desiredTop;
            //perform fit animation to move target view at top of layout
            action.update(0, dy, timeMs, new LinearInterpolator());
        }
    };
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) AnchorViewState(com.beloo.widget.chipslayoutmanager.anchor.AnchorViewState) PointF(android.graphics.PointF) LinearSmoothScroller(android.support.v7.widget.LinearSmoothScroller) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 3 with AnchorViewState

use of com.beloo.widget.chipslayoutmanager.anchor.AnchorViewState in project ChipsLayoutManager by BelooS.

the class ScrollingController method onContentScrolledBackward.

/**
     * invoked when content scrolled forward (return to older items)
     *
     * @param d not processed changing of x or y axis, depending on lm state
     * @return delta. Calculated changing of x or y axis, depending on lm state
     */
final int onContentScrolledBackward(int d) {
    int delta;
    AnchorViewState anchor = lm.getAnchor();
    if (anchor.getAnchorViewRect() == null) {
        return 0;
    }
    if (anchor.getPosition() != 0) {
        //in case 0 position haven't added in layout yet
        delta = d;
    } else {
        //in case top view is a first view in adapter and wouldn't be any other view above
        int startBorder = stateFactory.getStartAfterPadding();
        int viewStart = stateFactory.getStart(anchor);
        int distance;
        distance = viewStart - startBorder;
        if (distance >= 0) {
            // in case over scroll on top border
            delta = distance;
        } else {
            //in case first child showed partially
            delta = Math.max(distance, d);
        }
    }
    return delta;
}
Also used : AnchorViewState(com.beloo.widget.chipslayoutmanager.anchor.AnchorViewState)

Aggregations

AnchorViewState (com.beloo.widget.chipslayoutmanager.anchor.AnchorViewState)3 PointF (android.graphics.PointF)2 LinearSmoothScroller (android.support.v7.widget.LinearSmoothScroller)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 LinearInterpolator (android.view.animation.LinearInterpolator)2