Commit 8931c9e6 authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

Allow the bottom sheet to be dragged down from the toolbar

This patch adds an explicit function to the SwipeableBottomSheet that
determines if a touch event is inside of the sheet's toolbar. This
eliminates the hack that existed previously that made too many
assumptions about the height of the toolbar.

Bug: 834795
Change-Id: Id195e72718ff2d37deb2891fd6264300d517352a
Reviewed-on: https://chromium-review.googlesource.com/1036224
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555873}
parent 6975e7cc
......@@ -41,7 +41,7 @@
<View
android:id="@+id/bottom_sheet_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="@dimen/bottom_control_container_peek_height"
android:background="@color/modern_primary_color" />
</view>
......
......@@ -153,6 +153,9 @@ public class BottomSheet extends FrameLayout
/** The visible rect for the screen taking the keyboard into account. */
private final Rect mVisibleViewportRect = new Rect();
/** An out-array for use with getLocationInWindow to prevent constant allocations. */
private final int[] mCachedLocation = new int[2];
/** The minimum distance between half and full states to allow the half state. */
private final float mMinHalfFullDistance;
......@@ -717,6 +720,15 @@ public class BottomSheet extends FrameLayout
return (swipeToDismissEnabled() ? getHiddenRatio() : getPeekRatio()) * mContainerHeight;
}
@Override
public boolean isTouchEventInToolbar(MotionEvent event) {
mToolbarHolder.getLocationInWindow(mCachedLocation);
// This check only tests for collision for the Y component since the sheet is the full width
// of the screen. We only care if the touch event is above the bottom of the toolbar since
// we won't receive an event if the touch is outside the sheet.
return mCachedLocation[1] + mToolbarHolder.getHeight() > event.getRawY();
}
/**
* @return Whether flinging down hard enough will close the sheet.
*/
......@@ -737,11 +749,6 @@ public class BottomSheet extends FrameLayout
return getFullRatio() * mContainerHeight;
}
@Override
public float getContainerHeightPx() {
return mContainerHeight;
}
/**
* Show content in the bottom sheet's content area.
* @param content The {@link BottomSheetContent} to show, or null if no content should be shown.
......
......@@ -71,10 +71,10 @@ public class BottomSheetSwipeDetector extends GestureDetector.SimpleOnGestureLis
float getMaxOffsetPx();
/**
* Gets the height of the container that the sheet exists in.
* @return The height of the sheet's container.
* @param event The motion event to test.
* @return Whether the provided motion event is inside the toolbar.
*/
float getContainerHeightPx();
boolean isTouchEventInToolbar(MotionEvent event);
/**
* Check if a particular gesture or touch event should move the bottom sheet when in peeking
......@@ -123,7 +123,7 @@ public class BottomSheetSwipeDetector extends GestureDetector.SimpleOnGestureLis
mSheetDelegate.getCurrentOffsetPx(), mSheetDelegate.getMaxOffsetPx());
// Allow the bottom sheet's content to be scrolled up without dragging the sheet down.
if (!isTouchEventInToolbar(e2) && isSheetInMaxPosition
if (!mSheetDelegate.isTouchEventInToolbar(e2) && isSheetInMaxPosition
&& !mSheetDelegate.isContentScrolledToTop()) {
return false;
}
......@@ -253,17 +253,6 @@ public class BottomSheetSwipeDetector extends GestureDetector.SimpleOnGestureLis
return rawEvent;
}
/**
* Determines if a touch event is inside the toolbar. This assumes the toolbar is the full
* width of the screen and that the toolbar is at the top of the bottom sheet.
* @param e The motion event to test.
* @return True if the event occurred in the toolbar region.
*/
private boolean isTouchEventInToolbar(MotionEvent e) {
return mSheetDelegate.getContainerHeightPx() - e.getRawY()
> mSheetDelegate.getCurrentOffsetPx() - mSheetDelegate.getMinOffsetPx();
}
/**
* Gets the distance of a fling based on the velocity and the base animation time. This formula
* assumes the deceleration curve is quadratic (t^2), hence the displacement formula should be:
......
......@@ -91,8 +91,10 @@ public final class BottomSheetSwipeDetectorTest {
}
@Override
public float getContainerHeightPx() {
return mMaxOffset;
public boolean isTouchEventInToolbar(MotionEvent event) {
// This will be implementation specific in practice. This checks that the motion event
// occured above the bottom of the toolbar.
return event.getRawY() < (mMaxOffset - mCurrentSheetOffset) + mMinOffset;
}
@Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment