use of android.support.v4.widget.NestedScrollView in project materialistic by hidroh.
the class WebFragmentTest method testScrollToTop.
@Config(shadows = ShadowNestedScrollView.class)
@Test
public void testScrollToTop() {
NestedScrollView scrollView = (NestedScrollView) activity.findViewById(R.id.nested_scroll_view);
scrollView.smoothScrollTo(0, 1);
assertThat(customShadowOf(scrollView).getSmoothScrollY()).isEqualTo(1);
activity.fragment.scrollToTop();
assertThat(customShadowOf(scrollView).getSmoothScrollY()).isEqualTo(0);
}
use of android.support.v4.widget.NestedScrollView in project materialistic by hidroh.
the class ReadabilityFragmentTest method testScrollToTop.
@Config(shadows = ShadowNestedScrollView.class)
@Test
public void testScrollToTop() {
NestedScrollView scrollView = (NestedScrollView) activity.findViewById(R.id.nested_scroll_view);
scrollView.smoothScrollTo(0, 1);
assertThat(customShadowOf(scrollView).getSmoothScrollY()).isEqualTo(1);
fragment.scrollToTop();
assertThat(customShadowOf(scrollView).getSmoothScrollY()).isEqualTo(0);
controller.pause().stop().destroy();
}
use of android.support.v4.widget.NestedScrollView in project android-advancedrecyclerview by h6ah4i.
the class RecyclerViewDragDropManager method handleScrollOnDraggingInternalWithNestedScrollView.
private void handleScrollOnDraggingInternalWithNestedScrollView(RecyclerView rv, boolean horizontal) {
NestedScrollView nestedScrollView = mNestedScrollView;
int nestedScrollViewScrollOffsetX = nestedScrollView.getScrollX();
int nestedScrollViewScrollOffsetY = nestedScrollView.getScrollY();
Rect rect = new Rect();
rect.left = rect.right = getLastTouchX();
rect.top = rect.bottom = getLastTouchY();
offsetDescendantRectToAncestorCoords(mRecyclerView, nestedScrollView, rect);
int nestedScrollViewTouchX = rect.left - nestedScrollViewScrollOffsetX;
int nestedScrollViewTouchY = rect.top - nestedScrollViewScrollOffsetY;
final int edge = (horizontal) ? nestedScrollView.getWidth() : nestedScrollView.getHeight();
final float invEdge = (1.0f / edge);
final float normalizedTouchPos = (horizontal ? nestedScrollViewTouchX : nestedScrollViewTouchY) * invEdge;
final float threshold = SCROLL_THRESHOLD;
final float invThreshold = (1.0f / threshold);
final float centerOffset = normalizedTouchPos - 0.5f;
final float absCenterOffset = Math.abs(centerOffset);
final float acceleration = Math.max(0.0f, threshold - (0.5f - absCenterOffset)) * invThreshold;
final int mask = mScrollDirMask;
int scrollAmount = (int) Math.signum(centerOffset) * (int) (SCROLL_AMOUNT_COEFF * mDragEdgeScrollSpeed * mDisplayDensity * acceleration + 0.5f);
// apply mask
if (scrollAmount > 0) {
if ((mask & (horizontal ? SCROLL_DIR_RIGHT : SCROLL_DIR_DOWN)) == 0) {
scrollAmount = 0;
}
} else if (scrollAmount < 0) {
if ((mask & (horizontal ? SCROLL_DIR_LEFT : SCROLL_DIR_UP)) == 0) {
scrollAmount = 0;
}
}
// scroll
if (scrollAmount != 0) {
safeEndAnimationsIfRequired(rv);
if (horizontal) {
nestedScrollView.scrollBy(scrollAmount, 0);
} else {
nestedScrollView.scrollBy(0, scrollAmount);
}
}
final boolean updated = mDraggingItemDecorator.update(getLastTouchX(), getLastTouchY(), false);
if (updated) {
if (mSwapTargetItemOperator != null) {
mSwapTargetItemOperator.update(mDraggingItemDecorator.getDraggingItemTranslationX(), mDraggingItemDecorator.getDraggingItemTranslationY());
}
// check swapping
checkItemSwapping(rv);
onItemMoveDistanceUpdated();
}
}
use of android.support.v4.widget.NestedScrollView in project android-advancedrecyclerview by h6ah4i.
the class RecyclerViewDragDropManager method startDragging.
@SuppressWarnings("unchecked")
private void startDragging(RecyclerView rv, MotionEvent e, RecyclerView.ViewHolder holder, ItemDraggableRange range, AdapterPath path, int wrappedItemPosition, Object composedAdapterTag) {
safeEndAnimation(rv, holder);
mHandler.cancelLongPressDetection();
mDraggingItemInfo = new DraggingItemInfo(rv, holder, mLastTouchX, mLastTouchY);
mDraggingItemViewHolder = holder;
// XXX if setIsRecyclable() is used, another view holder objects will be created
// which has the same ID with currently dragging item... Not works as expected.
// holder.setIsRecyclable(false);
mDraggableRange = range;
mRootDraggableRange = convertToRootAdapterRange(path, mDraggableRange);
NestedScrollView nestedScrollView = findAncestorNestedScrollView(mRecyclerView);
if (nestedScrollView != null && !mRecyclerView.isNestedScrollingEnabled()) {
mNestedScrollView = nestedScrollView;
} else {
mNestedScrollView = null;
}
mOrigOverScrollMode = rv.getOverScrollMode();
rv.setOverScrollMode(View.OVER_SCROLL_NEVER);
mLastTouchX = (int) (e.getX() + 0.5f);
mLastTouchY = (int) (e.getY() + 0.5f);
mNestedScrollViewScrollX = (mNestedScrollView != null) ? mNestedScrollView.getScrollX() : 0;
mNestedScrollViewScrollY = (mNestedScrollView != null) ? mNestedScrollView.getScrollY() : 0;
// disable auto scrolling until user moves the item
mDragStartTouchY = mDragMinTouchY = mDragMaxTouchY = mLastTouchY;
mDragStartTouchX = mDragMinTouchX = mDragMaxTouchX = mLastTouchX;
mScrollDirMask = SCROLL_DIR_NONE;
mCurrentItemMoveMode = mItemMoveMode;
mComposedAdapterTag = composedAdapterTag;
mRecyclerView.getParent().requestDisallowInterceptTouchEvent(true);
startScrollOnDraggingProcess();
// raise onDragItemStarted() event
mWrapperAdapter.onDragItemStarted(mDraggingItemInfo, holder, mDraggableRange, wrappedItemPosition, mCurrentItemMoveMode);
// setup decorators
mWrapperAdapter.onBindViewHolder(holder, wrappedItemPosition);
mDraggingItemDecorator = new DraggingItemDecorator(mRecyclerView, holder, mRootDraggableRange);
mDraggingItemDecorator.setShadowDrawable(mShadowDrawable);
mDraggingItemDecorator.setupDraggingItemEffects(mDraggingItemEffectsInfo);
mDraggingItemDecorator.start(mDraggingItemInfo, mLastTouchX, mLastTouchY);
final int layoutType = CustomRecyclerViewUtils.getLayoutType(mRecyclerView);
if (supportsViewTranslation() && !mCheckCanDrop && CustomRecyclerViewUtils.isLinearLayout(layoutType)) {
mSwapTargetItemOperator = new SwapTargetItemOperator(mRecyclerView, holder, mDraggingItemInfo);
mSwapTargetItemOperator.setSwapTargetTranslationInterpolator(mSwapTargetTranslationInterpolator);
mSwapTargetItemOperator.start();
mSwapTargetItemOperator.update(mDraggingItemDecorator.getDraggingItemTranslationX(), mDraggingItemDecorator.getDraggingItemTranslationY());
}
if (mEdgeEffectDecorator != null) {
mEdgeEffectDecorator.reorderToTop();
}
if (mItemDragEventListener != null) {
mItemDragEventListener.onItemDragStarted(mWrapperAdapter.getDraggingItemInitialPosition());
mItemDragEventListener.onItemDragMoveDistanceUpdated(0, 0);
}
}
use of android.support.v4.widget.NestedScrollView in project smooth-app-bar-layout by henrytao-me.
the class BaseBehavior method getSupportedScrollTarget.
private View getSupportedScrollTarget(View target) {
if (target instanceof SwipeRefreshLayout && ((SwipeRefreshLayout) target).getChildCount() > 0) {
SwipeRefreshLayout parent = (SwipeRefreshLayout) target;
View child;
int n = parent.getChildCount();
for (int i = 0; i < n; i++) {
child = parent.getChildAt(i);
if (child instanceof NestedScrollView || child instanceof RecyclerView) {
return child;
}
}
return ((SwipeRefreshLayout) target).getChildAt(0);
} else if (target instanceof CoordinatorLayout) {
Stack<View> stack = new Stack<>();
stack.add(target);
while (stack.size() > 0) {
View view = stack.pop();
if (view instanceof NestedScrollView || view instanceof RecyclerView) {
return view;
}
if (view instanceof ViewGroup) {
int n = ((ViewGroup) view).getChildCount();
for (int i = 0; i < n; i++) {
stack.add(((ViewGroup) view).getChildAt(i));
}
}
}
}
return target;
}
Aggregations