Changed picker header

This commit is contained in:
Phillip Hsu 2016-07-19 23:11:37 -07:00
parent ae83786b3c
commit a8f3fafafa
5 changed files with 37 additions and 59 deletions

View File

@ -56,6 +56,8 @@ public abstract class BaseTimePickerDialog extends BottomSheetDialogFragment {
// While it is true by default, BottomSheetDialogs override this default height. // While it is true by default, BottomSheetDialogs override this default height.
// See http://stackoverflow.com/a/35634293/5055032 for an alternative solution involving // See http://stackoverflow.com/a/35634293/5055032 for an alternative solution involving
// defining a style that overrides the attribute. // 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.?
behavior.setPeekHeight(0); behavior.setPeekHeight(0);
dialog.setOnShowListener(new DialogInterface.OnShowListener() { dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override @Override

View File

@ -9,7 +9,6 @@ import android.widget.EditText;
import com.philliphsu.clock2.R; import com.philliphsu.clock2.R;
import butterknife.Bind; import butterknife.Bind;
import butterknife.OnClick;
import butterknife.OnTouch; import butterknife.OnTouch;
/** /**
@ -143,10 +142,12 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
return true; return true;
} }
/*
@OnClick(R.id.cancel) @OnClick(R.id.cancel)
void cancel() { void cancel() {
dismiss(); dismiss();
} }
*/
private void updateInputText(String inputText) { private void updateInputText(String inputText) {
TimeTextUtils.setText(inputText, mInputField); TimeTextUtils.setText(inputText, mInputField);

View File

@ -1,70 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- TOneverDO: Use LinearLayout, because it doesn't obey LWM --> <!-- TOneverDO: Use LinearLayout, because it doesn't obey LWM -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:orientation="vertical">
<!-- We want this to be a FrameLayout so we can make the EditText <!-- TODO: Consider TextView, because we might not want the cursor? -->
field LWM, because that solves all of our cursor issues, and so we <EditText
can put the ImageButton on top (z-level) --> android:id="@+id/input_time"
<FrameLayout
android:id="@+id/header"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/header_height" android:layout_height="wrap_content"
android:background="@color/colorPrimary" android:gravity="center"
android:layout_alignParentTop="true"> android:textSize="@dimen/time_input_text_size"
android:background="@android:color/transparent"/>
<!-- We want this to be an EditText because the cursor indicates <View style="@style/FocusGrabber"
where the user's input will go. Otherwise, when the dialog first android:id="@+id/focus_grabber"/>
opens, the user sees the header view as just an appbar that has
a single navigation icon, with no indication that the dialog
actually displays input. -->
<!-- If we were to use LWW, we would have issues with the cursor.
(1) It won't show initially, because the view is not big enough to
accommodate the cursor drawable. A hacky solution is to set the hint
to a single whitespace character.
(2) Additionally, when text is inputted, the cursor gets cut off
as it advances in position, probably because the text rendered at
the set text size is bigger than the view bounds. A satisfactory
solution has not been found. We tried adding padding to the end,
but that ended up decentralizing the view.
-->
<EditText
android:id="@+id/input_time"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="@dimen/time_input_text_size"
android:background="@android:color/transparent"
style="@style/TextAppearance.AppCompat.Inverse"/>
<!-- We need both focusable attrs for requestFocus() to succeed --> <View style="@style/Divider"/>
<View
android:id="@+id/focus_grabber"
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
<!-- TOneverDO: Before the EditText, because we need this on top -->
<ImageButton
android:id="@+id/cancel"
android:layout_width="@dimen/cancel_icon_size"
android:layout_height="@dimen/cancel_icon_size"
android:layout_gravity="center_vertical"
android:background="?selectableItemBackground"
android:src="@android:drawable/ic_menu_close_clear_cancel"/>
</FrameLayout>
<com.philliphsu.clock2.editalarm.NumpadTimePicker <com.philliphsu.clock2.editalarm.NumpadTimePicker
android:id="@+id/number_grid" android:id="@+id/number_grid"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/numpad_height" android:layout_height="@dimen/numpad_height"
android:layout_below="@id/header"
android:layout_marginTop="@dimen/bottom_sheet_vertical_space" android:layout_marginTop="@dimen/bottom_sheet_vertical_space"
android:layout_marginStart="@dimen/bottom_sheet_edge_margin" android:layout_marginStart="@dimen/bottom_sheet_edge_margin"
android:layout_marginEnd="@dimen/bottom_sheet_edge_margin" android:layout_marginEnd="@dimen/bottom_sheet_edge_margin"
android:layout_marginBottom="@dimen/bottom_sheet_vertical_space"/> android:layout_marginBottom="@dimen/bottom_sheet_vertical_space"/>
</RelativeLayout> </LinearLayout>

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Wrapped in a LL so the divider is full width.
The RelativeLayout defines padding for all children, so the
divider would be padded too. -->
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -74,10 +77,7 @@
</RelativeLayout> </RelativeLayout>
<View <View style="@style/Divider"
android:layout_width="match_parent" android:layout_marginTop="@dimen/item_margin_between_elements"/>
android:layout_height="1dp"
android:background="?android:listDivider"
android:layout_marginTop="@dimen/item_margin_between_elements"/>
</LinearLayout> </LinearLayout>

View File

@ -52,4 +52,18 @@
<item name="layout_gravity">center</item> <item name="layout_gravity">center</item>
</style> </style>
<style name="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">?android:attr/listDivider</item>
</style>
<style name="FocusGrabber">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">0dp</item>
<!-- We need both focusable attrs for requestFocus() to succeed -->
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
</style>
</resources> </resources>