From d0724dd5909dfd3b7908ced4a90e4fad9d9c04c7 Mon Sep 17 00:00:00 2001 From: ricknout Date: Thu, 11 Apr 2019 16:11:26 -0400 Subject: [PATCH] Add halfExpandedOffset to BottomSheet catalog demo GIT_ORIGIN_REV_ID=da446b5182eaf192d75c81b552f30e95373c5598 PiperOrigin-RevId: 243127218 --- .../BottomSheetMainDemoFragment.java | 21 +++++++++++++++++++ .../bottomsheet/res/values/strings.xml | 3 +++ 2 files changed, 24 insertions(+) diff --git a/catalog/java/io/material/catalog/bottomsheet/BottomSheetMainDemoFragment.java b/catalog/java/io/material/catalog/bottomsheet/BottomSheetMainDemoFragment.java index 400e59037..296cb680f 100644 --- a/catalog/java/io/material/catalog/bottomsheet/BottomSheetMainDemoFragment.java +++ b/catalog/java/io/material/catalog/bottomsheet/BottomSheetMainDemoFragment.java @@ -34,6 +34,7 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.FrameLayout; import android.widget.Switch; import android.widget.TextView; import io.material.catalog.feature.DemoFragment; @@ -75,13 +76,21 @@ public class BottomSheetMainDemoFragment extends DemoFragment { View bottomSheetChildView = view.findViewById(R.id.bottom_drawer); ViewGroup.LayoutParams params = bottomSheetChildView.getLayoutParams(); + BottomSheetBehavior bottomSheetBehavior = + BottomSheetBehavior.from(bottomSheetChildView); View modalBottomSheetChildView = bottomSheetDialog.findViewById(R.id.bottom_drawer_2); ViewGroup.LayoutParams layoutParams = modalBottomSheetChildView.getLayoutParams(); + BottomSheetBehavior modalBottomSheetBehavior = + bottomSheetDialog.getBehavior(); + boolean fitToContents = true; + float halfExpandedRatio = 0.5f; if (params != null && layoutParams != null) { if (isChecked) { params.height = windowHeight; layoutParams.height = windowHeight; + fitToContents = false; + halfExpandedRatio = 0.7f; } else { params.height = (windowHeight * 3 / 5); @@ -89,6 +98,10 @@ public class BottomSheetMainDemoFragment extends DemoFragment { } bottomSheetChildView.setLayoutParams(params); modalBottomSheetChildView.setLayoutParams(layoutParams); + bottomSheetBehavior.setFitToContents(fitToContents); + modalBottomSheetBehavior.setFitToContents(fitToContents); + bottomSheetBehavior.setHalfExpandedRatio(halfExpandedRatio); + modalBottomSheetBehavior.setHalfExpandedRatio(halfExpandedRatio); } } }); @@ -126,6 +139,14 @@ public class BottomSheetMainDemoFragment extends DemoFragment { case BottomSheetBehavior.STATE_COLLAPSED: text.setText(R.string.cat_bottomsheet_state_collapsed); break; + case BottomSheetBehavior.STATE_HALF_EXPANDED: + BottomSheetBehavior bottomSheetBehavior = + BottomSheetBehavior.from(bottomSheet); + text.setText( + getString( + R.string.cat_bottomsheet_state_half_expanded, + bottomSheetBehavior.getHalfExpandedRatio())); + break; default: break; } diff --git a/catalog/java/io/material/catalog/bottomsheet/res/values/strings.xml b/catalog/java/io/material/catalog/bottomsheet/res/values/strings.xml index 97522c84e..81a3deb64 100644 --- a/catalog/java/io/material/catalog/bottomsheet/res/values/strings.xml +++ b/catalog/java/io/material/catalog/bottomsheet/res/values/strings.xml @@ -34,6 +34,9 @@ STATE_EXPANDED + + STATE_HALF_EXPANDED\nhalfExpandedRatio = %.2f + Persistent Bottomsheet