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