Search in sources :

Example 21 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project CustomViews by AndroidStudy233.

the class BackdropBottomSheetBehavior method getBottomSheetBehavior.

/**
 * Look into the CoordiantorLayout for the {@link BottomSheetBehaviorGoogleMapsLike}
 * @param coordinatorLayout with app:layout_behavior= {@link BottomSheetBehaviorGoogleMapsLike}
 */
private void getBottomSheetBehavior(@NonNull CoordinatorLayout coordinatorLayout) {
    for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
        View child = coordinatorLayout.getChildAt(i);
        if (child instanceof NestedScrollView) {
            try {
                BottomSheetBehaviorGoogleMapsLike temp = BottomSheetBehaviorGoogleMapsLike.from(child);
                mBottomSheetBehaviorRef = new WeakReference<>(temp);
                break;
            } catch (IllegalArgumentException e) {
            }
        }
    }
}
Also used : NestedScrollView(android.support.v4.widget.NestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 22 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 23 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 24 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project material-components-android by material-components.

the class BottomSheetBehaviorTest method testNestedScroll.

@Test
@MediumTest
public void testNestedScroll() throws Throwable {
    final ViewGroup bottomSheet = getBottomSheet();
    final BottomSheetBehavior behavior = getBehavior();
    final NestedScrollView scroll = new NestedScrollView(activityTestRule.getActivity());
    // Set up nested scrolling area
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            bottomSheet.addView(scroll, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            TextView view = new TextView(activityTestRule.getActivity());
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 500; ++i) {
                sb.append("It is fine today. ");
            }
            view.setText(sb);
            view.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                // Do nothing
                }
            });
            scroll.addView(view);
            assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
            // The scroll offset is 0 at first
            assertThat(scroll.getScrollY(), is(0));
        }
    });
    // Swipe from the very bottom of the bottom sheet to the top edge of the screen so that the
    // scrolling content is also scrolled
    Espresso.onView(ViewMatchers.withId(R.id.coordinator)).perform(new GeneralSwipeAction(Swipe.SLOW, new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            return new float[] { view.getWidth() / 2, view.getHeight() - 1 };
        }
    }, new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            return new float[] { view.getWidth() / 2, 1 };
        }
    }, Press.FINGER));
    registerIdlingResourceCallback();
    try {
        Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
        activityTestRule.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_EXPANDED));
                // This confirms that the nested scrolling area was scrolled continuously after
                // the bottom sheet is expanded.
                assertThat(scroll.getScrollY(), is(not(0)));
            }
        });
    } finally {
        unregisterIdlingResourceCallback();
    }
}
Also used : GeneralSwipeAction(android.support.test.espresso.action.GeneralSwipeAction) ViewGroup(android.view.ViewGroup) CoordinatesProvider(android.support.test.espresso.action.CoordinatesProvider) TextView(android.widget.TextView) NestedScrollView(android.support.v4.widget.NestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 25 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)

Aggregations

NestedScrollView (android.support.v4.widget.NestedScrollView)42 View (android.view.View)24 RecyclerView (android.support.v7.widget.RecyclerView)15 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)9 AppBarLayout (android.support.design.widget.AppBarLayout)6 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)6 Toolbar (android.support.v7.widget.Toolbar)6 AbsListView (android.widget.AbsListView)6 ImageView (android.widget.ImageView)6 ScrollView (android.widget.ScrollView)6 ViewTreeObserver (android.view.ViewTreeObserver)5 SuppressLint (android.annotation.SuppressLint)4 ViewPager (android.support.v4.view.ViewPager)4 Test (org.junit.Test)4 Activity (android.app.Activity)3 Bundle (android.os.Bundle)3 TabLayout (android.support.design.widget.TabLayout)3 PagerAdapter (android.support.v4.view.PagerAdapter)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3