Search in sources :

Example 11 with NestedScrollView

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);
}
Also used : ShadowNestedScrollView(io.github.hidroh.materialistic.test.shadow.ShadowNestedScrollView) NestedScrollView(android.support.v4.widget.NestedScrollView) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 12 with NestedScrollView

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();
}
Also used : NestedScrollView(android.support.v4.widget.NestedScrollView) ShadowNestedScrollView(io.github.hidroh.materialistic.test.shadow.ShadowNestedScrollView) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 13 with NestedScrollView

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();
    }
}
Also used : Rect(android.graphics.Rect) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 14 with NestedScrollView

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);
    }
}
Also used : NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 15 with NestedScrollView

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;
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ViewGroup(android.view.ViewGroup) ObservableRecyclerView(me.henrytao.smoothappbarlayout.base.ObservableRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ObservableNestedScrollView(me.henrytao.smoothappbarlayout.base.ObservableNestedScrollView) NestedScrollView(android.support.v4.widget.NestedScrollView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ObservableRecyclerView(me.henrytao.smoothappbarlayout.base.ObservableRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ObservableNestedScrollView(me.henrytao.smoothappbarlayout.base.ObservableNestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) Stack(java.util.Stack)

Aggregations

NestedScrollView (android.support.v4.widget.NestedScrollView)20 View (android.view.View)8 RecyclerView (android.support.v7.widget.RecyclerView)6 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)5 ViewGroup (android.view.ViewGroup)5 ViewTreeObserver (android.view.ViewTreeObserver)4 TextView (android.widget.TextView)4 AppBarLayout (android.support.design.widget.AppBarLayout)3 TabLayout (android.support.design.widget.TabLayout)3 PagerAdapter (android.support.v4.view.PagerAdapter)3 ViewPager (android.support.v4.view.ViewPager)3 Toolbar (android.support.v7.widget.Toolbar)3 Menu (android.view.Menu)3 MenuItem (android.view.MenuItem)3 ImageView (android.widget.ImageView)3 Test (org.junit.Test)3 Activity (android.app.Activity)2 Bundle (android.os.Bundle)2 Nullable (android.support.annotation.Nullable)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2