use of android.support.design.widget.CoordinatorLayout.Behavior in project material-components-android by material-components.
the class CoordinatorLayoutTest method testNestedScrollingDispatchingToBehaviorWithGoneView.
@Test
public void testNestedScrollingDispatchingToBehaviorWithGoneView() throws Throwable {
final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
final CoordinatorLayout col = activity.mCoordinatorLayout;
// Now create a GONE view and add it to the CoordinatorLayout with the spy behavior,
// along with a NestedScrollView
final ImageView imageView = new ImageView(activity);
imageView.setVisibility(View.GONE);
final CoordinatorLayout.Behavior behavior = spy(new NestedScrollingBehavior());
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
LayoutInflater.from(activity).inflate(R.layout.include_nestedscrollview, col, true);
CoordinatorLayout.LayoutParams clp = new CoordinatorLayout.LayoutParams(200, 200);
clp.setBehavior(behavior);
col.addView(imageView, clp);
}
});
// Now vertically swipe up on the NSV, causing nested scrolling to occur
onView(withId(R.id.nested_scrollview)).perform(swipeUp());
// Verify that the Behavior's onStartNestedScroll was not called
verify(behavior, never()).onStartNestedScroll(// parent
eq(col), // child
eq(imageView), // target
any(View.class), // direct child target
any(View.class), // axes
any(int.class));
// Verify that the Behavior's onNestedScrollAccepted was not called
verify(behavior, never()).onNestedScrollAccepted(// parent
eq(col), // child
eq(imageView), // target
any(View.class), // direct child target
any(View.class), // axes
any(int.class));
// Verify that the Behavior's onNestedPreScroll was not called
verify(behavior, never()).onNestedPreScroll(// parent
eq(col), // child
eq(imageView), // target
any(View.class), // dx
any(int.class), // dy
any(int.class), // consumed
any(int[].class));
// Verify that the Behavior's onNestedScroll was not called
verify(behavior, never()).onNestedScroll(// parent
eq(col), // child
eq(imageView), // target
any(View.class), // dx consumed
any(int.class), // dy consumed
any(int.class), // dx unconsumed
any(int.class), // dy unconsumed
any(int.class));
// Verify that the Behavior's onStopNestedScroll was not called
verify(behavior, never()).onStopNestedScroll(// parent
eq(col), // child
eq(imageView), // target
any(View.class));
}
use of android.support.design.widget.CoordinatorLayout.Behavior in project material-components-android by material-components.
the class CoordinatorLayoutTest method testDependentViewChanged.
@Test
public void testDependentViewChanged() throws Throwable {
final CoordinatorLayout col = activityTestRule.getActivity().mCoordinatorLayout;
// Add two views, A & B, where B depends on A
final View viewA = new View(col.getContext());
final CoordinatorLayout.LayoutParams lpA = col.generateDefaultLayoutParams();
lpA.width = 100;
lpA.height = 100;
final View viewB = new View(col.getContext());
final CoordinatorLayout.LayoutParams lpB = col.generateDefaultLayoutParams();
lpB.width = 100;
lpB.height = 100;
final CoordinatorLayout.Behavior behavior = spy(new DependentBehavior(viewA));
lpB.setBehavior(behavior);
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
col.addView(viewA, lpA);
col.addView(viewB, lpB);
}
});
getInstrumentation().waitForIdleSync();
// Reset the Behavior since onDependentViewChanged may have already been called as part of
// any layout/draw passes already
reset(behavior);
// Now offset view A
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
ViewCompat.offsetLeftAndRight(viewA, 20);
ViewCompat.offsetTopAndBottom(viewA, 20);
}
});
getInstrumentation().waitForIdleSync();
// And assert that view B's Behavior was called appropriately
verify(behavior, times(1)).onDependentViewChanged(col, viewB, viewA);
}
use of android.support.design.widget.CoordinatorLayout.Behavior in project material-components-android by material-components.
the class CoordinatorLayoutTest method testDodgeInsetViewWithEmptyBounds.
@Test
public void testDodgeInsetViewWithEmptyBounds() throws Throwable {
final CoordinatorLayout col = activityTestRule.getActivity().mCoordinatorLayout;
// Add a view with zero height/width which is set to dodge its bounds
final View view = new View(col.getContext());
final Behavior spyBehavior = spy(new DodgeBoundsBehavior());
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
final CoordinatorLayout.LayoutParams lp = col.generateDefaultLayoutParams();
lp.dodgeInsetEdges = Gravity.BOTTOM;
lp.gravity = Gravity.BOTTOM;
lp.height = 0;
lp.width = 0;
lp.setBehavior(spyBehavior);
col.addView(view, lp);
}
});
// Wait for a layout
getInstrumentation().waitForIdleSync();
// Now add an non-empty bounds inset view to the bottom of the CoordinatorLayout
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
final View dodge = new View(col.getContext());
final CoordinatorLayout.LayoutParams lp = col.generateDefaultLayoutParams();
lp.insetEdge = Gravity.BOTTOM;
lp.gravity = Gravity.BOTTOM;
lp.height = 60;
lp.width = CoordinatorLayout.LayoutParams.MATCH_PARENT;
col.addView(dodge, lp);
}
});
// Verify that the Behavior of the view with empty bounds does not have its
// getInsetDodgeRect() called
verify(spyBehavior, never()).getInsetDodgeRect(same(col), same(view), any(Rect.class));
}
use of android.support.design.widget.CoordinatorLayout.Behavior in project material-components-android by material-components.
the class CoordinatorLayoutTest method testNestedScrollingTriggeringDependentViewChanged.
@Test
public void testNestedScrollingTriggeringDependentViewChanged() throws Throwable {
final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
final CoordinatorLayout col = activity.mCoordinatorLayout;
// First a NestedScrollView to trigger nested scrolling
final View scrollView = LayoutInflater.from(activity).inflate(R.layout.include_nestedscrollview, col, false);
// Now create a View and Behavior which depend on the scrollview
final ImageView dependentView = new ImageView(activity);
final CoordinatorLayout.Behavior dependentBehavior = spy(new DependentBehavior(scrollView));
// Finally a view which accepts nested scrolling in the CoordinatorLayout
final ImageView nestedScrollAwareView = new ImageView(activity);
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
// First add the ScrollView
col.addView(scrollView);
// Now add the view which depends on the scrollview
CoordinatorLayout.LayoutParams clp = new CoordinatorLayout.LayoutParams(200, 200);
clp.setBehavior(dependentBehavior);
col.addView(dependentView, clp);
// Now add the nested scrolling aware view
clp = new CoordinatorLayout.LayoutParams(200, 200);
clp.setBehavior(new NestedScrollingBehavior());
col.addView(nestedScrollAwareView, clp);
}
});
// Wait for any layouts, and reset the Behavior so that the call counts are 0
getInstrumentation().waitForIdleSync();
reset(dependentBehavior);
// Now vertically swipe up on the NSV, causing nested scrolling to occur
onView(withId(R.id.nested_scrollview)).perform(swipeUp());
// Verify that the Behavior's onDependentViewChanged is not called due to the
// nested scroll
verify(dependentBehavior, never()).onDependentViewChanged(// parent
eq(col), // child
eq(dependentView), // axes
eq(scrollView));
}
use of android.support.design.widget.CoordinatorLayout.Behavior in project material-components-android by material-components.
the class CoordinatorLayoutTest method testDodgeInsetBeforeLayout.
@Test
public void testDodgeInsetBeforeLayout() throws Throwable {
final CoordinatorLayout col = activityTestRule.getActivity().mCoordinatorLayout;
// Add a dummy view, which will be used to trigger a hierarchy change.
final View dummy = new View(col.getContext());
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
col.addView(dummy);
}
});
// Wait for a layout.
getInstrumentation().waitForIdleSync();
final View dodge = new View(col.getContext());
final CoordinatorLayout.LayoutParams lpDodge = col.generateDefaultLayoutParams();
lpDodge.dodgeInsetEdges = Gravity.BOTTOM;
lpDodge.setBehavior(new Behavior() {
@Override
public boolean getInsetDodgeRect(CoordinatorLayout parent, View child, Rect rect) {
// Any non-empty rect is fine here.
rect.set(0, 0, 10, 10);
return true;
}
});
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
col.addView(dodge, lpDodge);
// Ensure the new view is in the list of children.
int heightSpec = MeasureSpec.makeMeasureSpec(col.getHeight(), MeasureSpec.EXACTLY);
int widthSpec = MeasureSpec.makeMeasureSpec(col.getWidth(), MeasureSpec.EXACTLY);
col.measure(widthSpec, heightSpec);
// Force a hierarchy change.
col.removeView(dummy);
}
});
// Wait for a layout.
getInstrumentation().waitForIdleSync();
}
Aggregations