Commit 267ccee5 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Round top corners of BottomSheet

This CL makes the top corners of BottomSheet round shape (of radius
4dp). The round corners resides inside the top shadow and takes
the half the height.

Bug: 985644
Change-Id: Ibfc26c06a9ca4c83aa5f7304e27a91f50fba9df7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1710016
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680342}
parent 715cb38e
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="@android:color/white"/>
<corners
android:topRightRadius="@dimen/bottom_sheet_corner_radius"
android:topLeftRadius="@dimen/bottom_sheet_corner_radius" />
</shape>
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
<org.chromium.chrome.browser.widget.bottomsheet.BottomSheet <org.chromium.chrome.browser.widget.bottomsheet.BottomSheet
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bottom_sheet" android:id="@+id/bottom_sheet"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" > android:layout_height="wrap_content" >
...@@ -28,7 +27,14 @@ ...@@ -28,7 +27,14 @@
android:src="@drawable/modern_toolbar_shadow" android:src="@drawable/modern_toolbar_shadow"
android:scaleType="fitXY" android:scaleType="fitXY"
android:scaleY="-1" android:scaleY="-1"
tools:ignore="ContentDescription" /> android:importantForAccessibility="no" />
<ImageView
android:id="@+id/bottom_sheet_round_top"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_corner_radius"
android:layout_marginTop="@dimen/bottom_sheet_corner_radius"
android:src="@drawable/white_with_top_rounded_corners"
android:importantForAccessibility="no" />
<view <view
class="org.chromium.chrome.browser.widget.bottomsheet.TouchRestrictingFrameLayout" class="org.chromium.chrome.browser.widget.bottomsheet.TouchRestrictingFrameLayout"
......
...@@ -552,6 +552,7 @@ ...@@ -552,6 +552,7 @@
<!-- Bottom Sheet dimensions --> <!-- Bottom Sheet dimensions -->
<dimen name="bottom_sheet_min_full_half_distance">140dp</dimen> <dimen name="bottom_sheet_min_full_half_distance">140dp</dimen>
<dimen name="bottom_sheet_peek_height">56dp</dimen> <dimen name="bottom_sheet_peek_height">56dp</dimen>
<dimen name="bottom_sheet_corner_radius">4dp</dimen>
<!-- TextBubble dimensions --> <!-- TextBubble dimensions -->
<dimen name="text_bubble_margin">4dp</dimen> <dimen name="text_bubble_margin">4dp</dimen>
......
...@@ -149,6 +149,9 @@ public class BottomSheet ...@@ -149,6 +149,9 @@ public class BottomSheet
/** The height of the shadow that sits above the toolbar. */ /** The height of the shadow that sits above the toolbar. */
private final int mToolbarShadowHeight; private final int mToolbarShadowHeight;
/** The radius of the rounded corner at the top of the sheet. */
private final int mRoundedCornerRadius;
/** The {@link BottomSheetMetrics} used to record user actions and histograms. */ /** The {@link BottomSheetMetrics} used to record user actions and histograms. */
private final BottomSheetMetrics mMetrics; private final BottomSheetMetrics mMetrics;
...@@ -420,7 +423,8 @@ public class BottomSheet ...@@ -420,7 +423,8 @@ public class BottomSheet
getResources().getDimensionPixelSize(R.dimen.bottom_sheet_min_full_half_distance); getResources().getDimensionPixelSize(R.dimen.bottom_sheet_min_full_half_distance);
mToolbarShadowHeight = mToolbarShadowHeight =
getResources().getDimensionPixelOffset(R.dimen.toolbar_shadow_height); getResources().getDimensionPixelOffset(R.dimen.toolbar_shadow_height);
mRoundedCornerRadius =
getResources().getDimensionPixelOffset(R.dimen.bottom_sheet_corner_radius);
mMetrics = new BottomSheetMetrics(); mMetrics = new BottomSheetMetrics();
addObserver(mMetrics); addObserver(mMetrics);
...@@ -1181,7 +1185,7 @@ public class BottomSheet ...@@ -1181,7 +1185,7 @@ public class BottomSheet
@VisibleForTesting @VisibleForTesting
float getFullRatio() { float getFullRatio() {
if (mContainerHeight <= 0) return 0; if (mContainerHeight <= 0) return 0;
return (mContainerHeight + mToolbarShadowHeight) / mContainerHeight; return (mContainerHeight + mToolbarShadowHeight - mRoundedCornerRadius) / mContainerHeight;
} }
/** /**
...@@ -1397,7 +1401,8 @@ public class BottomSheet ...@@ -1397,7 +1401,8 @@ public class BottomSheet
mSheetContent.getContentView().measure( mSheetContent.getContentView().measure(
MeasureSpec.makeMeasureSpec((int) mContainerWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) mContainerWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec((int) mContainerHeight, MeasureSpec.AT_MOST)); MeasureSpec.makeMeasureSpec((int) mContainerHeight, MeasureSpec.AT_MOST));
mContentDesiredHeight = mSheetContent.getContentView().getMeasuredHeight(); mContentDesiredHeight =
mSheetContent.getContentView().getMeasuredHeight() - mRoundedCornerRadius;
} }
private float getRatioForState(int state) { private float getRatioForState(int state) {
...@@ -1595,4 +1600,9 @@ public class BottomSheet ...@@ -1595,4 +1600,9 @@ public class BottomSheet
private void invalidateContentDesiredHeight() { private void invalidateContentDesiredHeight() {
mContentDesiredHeight = HEIGHT_UNSPECIFIED; mContentDesiredHeight = HEIGHT_UNSPECIFIED;
} }
@VisibleForTesting
int getRoundedCornerRadius() {
return mRoundedCornerRadius;
}
} }
...@@ -257,7 +257,8 @@ public class BottomSheetObserverTest { ...@@ -257,7 +257,8 @@ public class BottomSheetObserverTest {
assertEquals(BottomSheet.SheetState.FULL, bottomSheet.getSheetState()); assertEquals(BottomSheet.SheetState.FULL, bottomSheet.getSheetState());
// Check the offset. // Check the offset.
assertEquals(wrappedContentHeight + bottomSheet.getToolbarShadowHeight(), assertEquals(wrappedContentHeight + bottomSheet.getToolbarShadowHeight()
- bottomSheet.getRoundedCornerRadius(),
bottomSheet.getCurrentOffsetPx(), MathUtils.EPSILON); bottomSheet.getCurrentOffsetPx(), MathUtils.EPSILON);
} }
} }
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