Changed to bottom sheet

This commit is contained in:
Phillip Hsu 2016-07-25 01:14:22 -07:00
parent 3936c4285d
commit 069bf39ab8
3 changed files with 37 additions and 9 deletions

View File

@ -3,18 +3,17 @@ package com.philliphsu.clock2.editalarm;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment; import android.support.design.widget.BottomSheetDialogFragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window;
import butterknife.ButterKnife; import butterknife.ButterKnife;
/** /**
* Created by Phillip Hsu on 7/16/2016. * Created by Phillip Hsu on 7/16/2016.
*/ */
public abstract class BaseTimePickerDialog extends DialogFragment { public abstract class BaseTimePickerDialog extends BottomSheetDialogFragment {
// TODO: Consider private access, and then writing package/protected API that subclasses // TODO: Consider private access, and then writing package/protected API that subclasses
// can use to interface with this field. // can use to interface with this field.
@ -50,9 +49,22 @@ public abstract class BaseTimePickerDialog extends DialogFragment {
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); // Not needed for bottom sheet dialogs
View view = inflater.inflate(contentLayout(), container, false); // getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
final View view = inflater.inflate(contentLayout(), container, false);
ButterKnife.bind(this, view); 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; return view;
} }
@ -90,6 +102,7 @@ public abstract class BaseTimePickerDialog extends DialogFragment {
// @Override // @Override
// public Dialog onCreateDialog(Bundle savedInstanceState) { // public Dialog onCreateDialog(Bundle savedInstanceState) {
// Dialog dialog = super.onCreateDialog(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 we can safely retrieve the host activity.
// View view = LayoutInflater.from(getActivity()).inflate(contentLayout(), null); // View view = LayoutInflater.from(getActivity()).inflate(contentLayout(), null);
// /** // /**
@ -98,7 +111,7 @@ public abstract class BaseTimePickerDialog extends DialogFragment {
// * @see {@link BottomSheetDialog#wrapInBottomSheet(int, View, ViewGroup.LayoutParams)} // * @see {@link BottomSheetDialog#wrapInBottomSheet(int, View, ViewGroup.LayoutParams)}
// */ // */
// dialog.setContentView(view); // dialog.setContentView(view);
// // Bind this fragment, not the internal dialog! // // Bind this fragment, not the internal dialog! (There is a bind(Dialog) API.)
// ButterKnife.bind(this, view); // ButterKnife.bind(this, view);
// final BottomSheetBehavior behavior = BottomSheetBehavior.from((View) view.getParent()); // final BottomSheetBehavior behavior = BottomSheetBehavior.from((View) view.getParent());
// // When we collapse, collapse all the way. Do not be misled by the "docs" in // // When we collapse, collapse all the way. Do not be misled by the "docs" in

View File

@ -305,8 +305,12 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
return; return;
} }
int value = Integer.parseInt(number); int value = Integer.parseInt(number);
if (mCurrentIndex == HOUR_INDEX && !mIs24HourMode && mSelectedHalfDay == HALF_DAY_2) { if (mCurrentIndex == HOUR_INDEX && !mIs24HourMode) {
value = (value % 12) + 12; if (value == 12 && mSelectedHalfDay == HALF_DAY_1) {
value = 0;
} else if (value != 12 && mSelectedHalfDay == HALF_DAY_2) {
value += 12;
}
} }
onValueSelected(mCurrentIndex, value, true); onValueSelected(mCurrentIndex, value, true);
} }

View File

@ -6,6 +6,8 @@
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<!-- TODO: This doesn't work for BottomSheetDialogs. Verify this works for other types of dialogs. -->
<item name="dialogTheme">@style/AppTheme.AppCompatDialog</item>
</style> </style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/> <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
@ -57,7 +59,11 @@
</style> </style>
<style name="Divider"> <style name="Divider">
<item name="android:background">?android:attr/listDivider</item> <!-- Won't be visible in a bottom sheet dialog... -->
<!--<item name="android:background">?android:attr/listDivider</item>-->
<!-- Extracted from the drawable pointed to by the attr. Visible in bottom sheet. -->
<item name="android:background">#1f000000</item> <!-- 12% black -->
<item name="android:tint">?android:attr/colorForeground</item>
</style> </style>
<style name="Divider.Horizontal"> <style name="Divider.Horizontal">
@ -78,4 +84,9 @@
<item name="android:focusableInTouchMode">true</item> <item name="android:focusableInTouchMode">true</item>
</style> </style>
<!-- Style for AppCompatDialog from the v7 support library -->
<style name="AppTheme.AppCompatDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">?android:attr/colorAccent</item>
</style>
</resources> </resources>