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());
}
};
}
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());
}
};
}
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;
}
Aggregations