From 20db6156ca3ff618a8189fc219338d4ed0449103 Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Mon, 25 Jul 2016 02:35:12 -0700 Subject: [PATCH] Override modal bottom sheet peekHeight --- .../editalarm/BaseTimePickerDialog.java | 27 +++++++------------ .../clock2/editalarm/EditAlarmActivity.java | 12 ++++----- app/src/main/res/values/dimens.xml | 4 +++ app/src/main/res/values/styles.xml | 13 +++++++-- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/philliphsu/clock2/editalarm/BaseTimePickerDialog.java b/app/src/main/java/com/philliphsu/clock2/editalarm/BaseTimePickerDialog.java index 51ba168..a89b200 100644 --- a/app/src/main/java/com/philliphsu/clock2/editalarm/BaseTimePickerDialog.java +++ b/app/src/main/java/com/philliphsu/clock2/editalarm/BaseTimePickerDialog.java @@ -53,18 +53,6 @@ public abstract class BaseTimePickerDialog extends BottomSheetDialogFragment { // getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); final View view = inflater.inflate(contentLayout(), container, false); ButterKnife.bind(this, view); - -// // We're past onCreateDialog() in the lifecycle, so getDialog() will return something. -// getDialog().setOnShowListener(new DialogInterface.OnShowListener() { -// @Override -// public void onShow(DialogInterface dialog) { -// BottomSheetBehavior behavior = BottomSheetBehavior.from((View) view.getParent()); -// // Every time we show, show at our full height. -// // TODO: This is the cause of our anchored FAB and number grid not showing! -// behavior.setState(BottomSheetBehavior.STATE_EXPANDED); -// } -// }); - return view; } @@ -98,12 +86,13 @@ public abstract class BaseTimePickerDialog extends BottomSheetDialogFragment { // return builder.create(); // } - // Code for BottomSheetDialogs only. To uncomment, highlight and CTRL + / + // This was an unsatisfactory solution to forcing the bottom sheet to show at its + // fully expanded state. Our anchored FAB and GridLayout buttons would not be visible. // @Override // public Dialog onCreateDialog(Bundle savedInstanceState) { // Dialog dialog = super.onCreateDialog(savedInstanceState); // //dialog = new BottomSheetDialog(getActivity(), R.style.AppTheme_AppCompatDialog/*crashes our app!*/); -// // We're past onCreate() in the lifecycle, so we can safely retrieve the host activity. +// // We're past onCreate() in the lifecycle, so the activity is alive. // View view = LayoutInflater.from(getActivity()).inflate(contentLayout(), null); // /** // * Adds our view to a ViewGroup that has a BottomSheetBehavior attached. The ViewGroup @@ -114,16 +103,18 @@ public abstract class BaseTimePickerDialog extends BottomSheetDialogFragment { // // Bind this fragment, not the internal dialog! (There is a bind(Dialog) API.) // ButterKnife.bind(this, view); // final BottomSheetBehavior behavior = BottomSheetBehavior.from((View) view.getParent()); + // // When we collapse, collapse all the way. Do not be misled by the "docs" in // // https://android-developers.blogspot.com.au/2016/02/android-support-library-232.html // // when it says: // // "STATE_COLLAPSED: ... the app:behavior_peekHeight attribute (defaults to 0)" // // While it is true by default, BottomSheetDialogs override this default height. -// // See http://stackoverflow.com/a/35634293/5055032 for an alternative solution involving -// // defining a style that overrides the attribute. -// // TODO: If the sheet is dragged out of view, then the screen remains darkened until -// // a subsequent touch on the screen. Consider doing the alt. soln.? + + // This means the sheet is considered "open" even at a height of 0! This is why +// // when you swipe to hide the sheet, the screen remains darkened--indicative +// // of an open dialog. // behavior.setPeekHeight(0); + // dialog.setOnShowListener(new DialogInterface.OnShowListener() { // @Override // public void onShow(DialogInterface dialog) { diff --git a/app/src/main/java/com/philliphsu/clock2/editalarm/EditAlarmActivity.java b/app/src/main/java/com/philliphsu/clock2/editalarm/EditAlarmActivity.java index c78d53a..9e9de69 100644 --- a/app/src/main/java/com/philliphsu/clock2/editalarm/EditAlarmActivity.java +++ b/app/src/main/java/com/philliphsu/clock2/editalarm/EditAlarmActivity.java @@ -323,12 +323,12 @@ public class EditAlarmActivity extends BaseActivity implements // last inputted time. // TODO: Read preferences to see what time picker style to show. BaseTimePickerDialog dialog; -// dialog = NumberGridTimePickerDialog.newInstance( -// this, // OnTimeSetListener -// 0, // Initial hour of day -// 0, // Initial minute -// DateFormat.is24HourFormat(this)); - dialog = NumpadTimePickerDialog.newInstance(this); + dialog = NumberGridTimePickerDialog.newInstance( + this, // OnTimeSetListener + 0, // Initial hour of day + 0, // Initial minute + DateFormat.is24HourFormat(this)); +// dialog = NumpadTimePickerDialog.newInstance(this); dialog.show(getSupportFragmentManager(), TAG_TIME_PICKER); } diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 5d7761e..d0275df 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -24,4 +24,8 @@ 24dp 16dp + + 500dp diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 655baa7..72c8bcb 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -7,7 +7,8 @@ @color/colorPrimaryDark @color/colorAccent - @style/AppTheme.AppCompatDialog + @style/AppCompatDialogTheme + @style/BottomSheetDialogTheme - + + + +