Moved alt buttons and fab to dialog layout

This commit is contained in:
Phillip Hsu 2016-07-20 19:42:05 -07:00
parent 62524bc0b5
commit a07cf222b3
7 changed files with 252 additions and 211 deletions

View File

@ -1,22 +1,20 @@
package com.philliphsu.clock2.editalarm; package com.philliphsu.clock2.editalarm;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.design.widget.BottomSheetBehavior; import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialog; 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 BottomSheetDialogFragment { public abstract class BaseTimePickerDialog extends DialogFragment {
// 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.
@ -35,42 +33,42 @@ public abstract class BaseTimePickerDialog extends BottomSheetDialogFragment {
mCallback = callback; mCallback = callback;
} }
@Override // Code for BottomSheetDialogs only. To uncomment, highlight and CTRL + /
public Dialog onCreateDialog(Bundle savedInstanceState) { // @Override
Dialog dialog = super.onCreateDialog(savedInstanceState); // public Dialog onCreateDialog(Bundle savedInstanceState) {
// We're past onCreate() in the lifecycle, so we can safely retrieve the host activity. // Dialog dialog = super.onCreateDialog(savedInstanceState);
View view = LayoutInflater.from(getActivity()).inflate(contentLayout(), null); // // We're past onCreate() in the lifecycle, so we can safely retrieve the host activity.
/** // View view = LayoutInflater.from(getActivity()).inflate(contentLayout(), null);
* Adds our view to a ViewGroup that has a BottomSheetBehavior attached. The ViewGroup // /**
* itself is a child of a CoordinatorLayout. // * Adds our view to a ViewGroup that has a BottomSheetBehavior attached. The ViewGroup
* @see {@link BottomSheetDialog#wrapInBottomSheet(int, View, ViewGroup.LayoutParams)} // * itself is a child of a CoordinatorLayout.
*/ // * @see {@link BottomSheetDialog#wrapInBottomSheet(int, View, ViewGroup.LayoutParams)}
dialog.setContentView(view); // */
// Bind this fragment, not the internal dialog! // dialog.setContentView(view);
ButterKnife.bind(this, view); // // Bind this fragment, not the internal dialog!
final BottomSheetBehavior behavior = BottomSheetBehavior.from((View) view.getParent()); // ButterKnife.bind(this, view);
// When we collapse, collapse all the way. Do not be misled by the "docs" in // final BottomSheetBehavior behavior = BottomSheetBehavior.from((View) view.getParent());
// https://android-developers.blogspot.com.au/2016/02/android-support-library-232.html // // When we collapse, collapse all the way. Do not be misled by the "docs" in
// when it says: // // https://android-developers.blogspot.com.au/2016/02/android-support-library-232.html
// "STATE_COLLAPSED: ... the app:behavior_peekHeight attribute (defaults to 0)" // // when it says:
// While it is true by default, BottomSheetDialogs override this default height. // // "STATE_COLLAPSED: ... the app:behavior_peekHeight attribute (defaults to 0)"
// See http://stackoverflow.com/a/35634293/5055032 for an alternative solution involving // // While it is true by default, BottomSheetDialogs override this default height.
// defining a style that overrides the attribute. // // See http://stackoverflow.com/a/35634293/5055032 for an alternative solution involving
// TODO: If the sheet is dragged out of view, then the screen remains darkened until // // defining a style that overrides the attribute.
// a subsequent touch on the screen. Consider doing the alt. soln.? // // TODO: If the sheet is dragged out of view, then the screen remains darkened until
behavior.setPeekHeight(0); // // a subsequent touch on the screen. Consider doing the alt. soln.?
dialog.setOnShowListener(new DialogInterface.OnShowListener() { // behavior.setPeekHeight(0);
@Override // dialog.setOnShowListener(new DialogInterface.OnShowListener() {
public void onShow(DialogInterface dialog) { // @Override
// Every time we show, show at our full height. // public void onShow(DialogInterface dialog) {
behavior.setState(BottomSheetBehavior.STATE_EXPANDED); // // Every time we show, show at our full height.
} // behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}); // }
// });
//
// return dialog;
// }
return dialog;
}
/*
@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) {
@ -79,7 +77,6 @@ public abstract class BaseTimePickerDialog extends BottomSheetDialogFragment {
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
return view; return view;
} }
*/
@Override @Override
public void onDestroyView() { public void onDestroyView() {

View File

@ -2,12 +2,11 @@ package com.philliphsu.clock2.editalarm;
import android.content.Context; import android.content.Context;
import android.support.annotation.CallSuper; import android.support.annotation.CallSuper;
import android.support.annotation.LayoutRes;
import android.support.v7.widget.GridLayout; import android.support.v7.widget.GridLayout;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.TextView;
import com.philliphsu.clock2.R; import com.philliphsu.clock2.R;
@ -26,7 +25,7 @@ import butterknife.OnLongClick;
* and not the backspace button. However, we do provide an API for removing * and not the backspace button. However, we do provide an API for removing
* digits from the input. * digits from the input.
*/ */
public abstract class GridLayoutNumpad extends GridLayout implements View.OnClickListener { public abstract class GridLayoutNumpad extends GridLayout {
// TODO: change to private? // TODO: change to private?
protected static final int UNMODIFIED = -1; protected static final int UNMODIFIED = -1;
private static final int COLUMNS = 3; private static final int COLUMNS = 3;
@ -37,7 +36,7 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
@Bind({ R.id.zero, R.id.one, R.id.two, R.id.three, R.id.four, @Bind({ R.id.zero, R.id.one, R.id.two, R.id.three, R.id.four,
R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine }) R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine })
Button[] mButtons; TextView[] mButtons;
@Bind(R.id.backspace) ImageButton mBackspace; @Bind(R.id.backspace) ImageButton mBackspace;
/** /**
@ -72,12 +71,6 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
*/ */
public abstract int capacity(); public abstract int capacity();
/**
* @return the layout resource that defines the children for this numpad
*/
@LayoutRes
protected abstract int contentLayout();
public final void setOnInputChangeListener(OnInputChangeListener onInputChangeListener) { public final void setOnInputChangeListener(OnInputChangeListener onInputChangeListener) {
mOnInputChangeListener = onInputChangeListener; mOnInputChangeListener = onInputChangeListener;
} }
@ -172,7 +165,7 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
* {@link OnInputChangeListener OnInputChangeListener} * {@link OnInputChangeListener OnInputChangeListener}
* after a digit insertion. By default, the String * after a digit insertion. By default, the String
* forwarded is just the String value of the inserted digit. * forwarded is just the String value of the inserted digit.
* @see #onClick(View) * @see #onClick(TextView)
* @param newDigit the formatted String that should be displayed * @param newDigit the formatted String that should be displayed
*/ */
@CallSuper @CallSuper
@ -233,11 +226,11 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
} }
} }
// TODO: Why not @OnClick instead? @OnClick({ R.id.zero, R.id.one, R.id.two, R.id.three, R.id.four,
@Override R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine })
public final void onClick(View v) { final void onClick(TextView view) {
if (mCount < mInput.length) { if (mCount < mInput.length) {
String textNum = ((Button) v).getText().toString(); String textNum = view.getText().toString();
insertDigits(Integer.parseInt(textNum)); insertDigits(Integer.parseInt(textNum));
} }
} }
@ -245,10 +238,8 @@ public abstract class GridLayoutNumpad extends GridLayout implements View.OnClic
private void init() { private void init() {
setAlignmentMode(ALIGN_BOUNDS); setAlignmentMode(ALIGN_BOUNDS);
setColumnCount(COLUMNS); setColumnCount(COLUMNS);
View.inflate(getContext(), contentLayout(), this); View.inflate(getContext(), R.layout.content_grid_layout_numpad, this);
ButterKnife.bind(this); ButterKnife.bind(this);
for (Button b : mButtons)
b.setOnClickListener(this);
// If capacity() < 0, we let the system throw the exception. // If capacity() < 0, we let the system throw the exception.
mInput = new int[capacity()]; mInput = new int[capacity()];
Arrays.fill(mInput, UNMODIFIED); Arrays.fill(mInput, UNMODIFIED);

View File

@ -5,17 +5,13 @@ import android.support.annotation.IntDef;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.Button; import android.view.View;
import android.widget.TextView;
import com.philliphsu.clock2.R;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.text.DateFormatSymbols; import java.text.DateFormatSymbols;
import java.util.Calendar;
import butterknife.Bind;
import butterknife.OnClick;
/** /**
* Created by Phillip Hsu on 7/12/2016. * Created by Phillip Hsu on 7/12/2016.
@ -47,9 +43,9 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
private int mAmPmState = UNSPECIFIED; private int mAmPmState = UNSPECIFIED;
private final StringBuilder mFormattedInput = new StringBuilder(MAX_CHARS); private final StringBuilder mFormattedInput = new StringBuilder(MAX_CHARS);
@Bind({ R.id.leftAlt, R.id.rightAlt }) private WeakReference<TextView> mLeftAlt;
Button[] mAltButtons; private WeakReference<TextView> mRightAlt;
@Bind(R.id.fab) FloatingActionButton mFab; private WeakReference<FloatingActionButton> mFab;
/** /**
* Provides additional APIs to configure clients' display output. * Provides additional APIs to configure clients' display output.
@ -77,19 +73,18 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
return MAX_DIGITS; return MAX_DIGITS;
} }
@Override
protected int contentLayout() {
return R.layout.content_numpad_time_picker;
}
@Override @Override
protected void enable(int lowerLimitInclusive, int upperLimitExclusive) { protected void enable(int lowerLimitInclusive, int upperLimitExclusive) {
super.enable(lowerLimitInclusive, upperLimitExclusive); super.enable(lowerLimitInclusive, upperLimitExclusive);
if (lowerLimitInclusive == 0 && upperLimitExclusive == 0) { if (lowerLimitInclusive == 0 && upperLimitExclusive == 0) {
// For 12-hour clock, alt buttons need to be disabled as well before firing onInputDisabled() // For 12-hour clock, alt buttons need to be disabled as well before firing onInputDisabled()
if (!is24HourFormat() && (mAltButtons[0].isEnabled() || mAltButtons[1].isEnabled())) { if (!is24HourFormat()) {
if (mLeftAlt != null && mLeftAlt.get() != null
&& mRightAlt != null && mRightAlt.get() != null
&& (mLeftAlt.get().isEnabled() || mRightAlt.get().isEnabled())) {
return; return;
} }
}
((OnInputChangeListener) getOnInputChangeListener()).onInputDisabled(); ((OnInputChangeListener) getOnInputChangeListener()).onInputDisabled();
} }
} }
@ -236,8 +231,9 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
} }
mAmPmState = amPmState; mAmPmState = amPmState;
if (mAmPmState != HRS_24) { if (mAmPmState != HRS_24 && mLeftAlt != null && mRightAlt != null
onAltButtonClick(mAmPmState == AM ? mAltButtons[0] : mAltButtons[1]); && mLeftAlt.get() != null && mRightAlt.get() != null) {
mAltButtonClickListener.onClick(mAmPmState == AM ? mLeftAlt.get() : mRightAlt.get());
} }
} }
@ -245,38 +241,63 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
return mFormattedInput.toString(); return mFormattedInput.toString();
} }
/**
* This was only useful when the FAB was part of the numpad's layout, and the dialog
* wanted to listen to clicks on it. Now that the dialog contains the FAB, there is
* no use for this.
* @deprecated Pass in a FAB with {@link #setFab(FloatingActionButton)} instead.
*/
@Deprecated
public void setFabClickListener(OnClickListener fabClickListener) { public void setFabClickListener(OnClickListener fabClickListener) {
mFab.setOnClickListener(fabClickListener); // mFab.setOnClickListener(fabClickListener);
} }
private void init() { public void setFab(FloatingActionButton fab) {
if (is24HourFormat()) { mFab = new WeakReference<>(fab);
mAltButtons[0].setText(R.string.left_alt_24hr);
mAltButtons[1].setText(R.string.right_alt_24hr);
} else {
String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
mAltButtons[0].setText(amPmTexts[Calendar.AM]);
mAltButtons[1].setText(amPmTexts[Calendar.PM]);
}
updateNumpadStates(); updateNumpadStates();
} }
@OnClick({ R.id.leftAlt, R.id.rightAlt }) public void setAltButtons(TextView leftAlt, TextView rightAlt) {
void onAltButtonClick(Button altBtn) { mLeftAlt = new WeakReference<>(leftAlt);
if (mAltButtons[0] != altBtn && mAltButtons[1] != altBtn) mRightAlt = new WeakReference<>(rightAlt);
throw new IllegalArgumentException("Not called with one of the alt buttons"); mLeftAlt.get().setOnClickListener(mAltButtonClickListener);
mRightAlt.get().setOnClickListener(mAltButtonClickListener);
updateNumpadStates();
}
private void init() {
/* This was where we set the text on the alt buttons, when they were still part of our layout */
updateNumpadStates();
}
private final AltButtonClickListener mAltButtonClickListener = new AltButtonClickListener(this);
private static class AltButtonClickListener implements OnClickListener {
private final WeakReference<NumpadTimePicker> mPicker;
public AltButtonClickListener(NumpadTimePicker picker) {
mPicker = new WeakReference<>(picker);
}
@Override
public void onClick(View v) {
TextView altBtn = (TextView) v;
// Manually insert special characters for 12-hour clock // Manually insert special characters for 12-hour clock
if (!is24HourFormat()) { if (!mPicker.get().is24HourFormat()) {
if (count() <= 2) { if (mPicker.get().count() <= 2) {
// The colon is inserted for you // The colon is inserted for you
insertDigits(0, 0); mPicker.get().insertDigits(0, 0);
} }
// text is AM or PM, so include space before // text is AM or PM, so include space before
mFormattedInput.append(' ').append(altBtn.getText()); String ampm = altBtn.getText().toString();
mAmPmState = mAltButtons[0] == altBtn ? AM : PM; StringBuilder mFormattedInput = mPicker.get().mFormattedInput;
mFormattedInput.append(' ').append(ampm);
String am = new DateFormatSymbols().getAmPmStrings()[0];
mPicker.get().mAmPmState = ampm.equals(am) ? AM : PM;
// Digits will be shown for you on insert, but not AM/PM // Digits will be shown for you on insert, but not AM/PM
/*TOneverDO: remove super*/super.onDigitInserted(mFormattedInput.toString()); ((/*NOT REDUNDANT! TOneverDO: Remove cast*/GridLayoutNumpad)
mPicker.get()).onDigitInserted(mFormattedInput.toString());
} else { } else {
CharSequence text = altBtn.getText(); CharSequence text = altBtn.getText();
int[] digits = new int[text.length() - 1]; int[] digits = new int[text.length() - 1];
@ -289,11 +310,12 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
digits[i - 1] = Character.digit(text.charAt(i), BASE_10); digits[i - 1] = Character.digit(text.charAt(i), BASE_10);
} }
// Colon is added for you // Colon is added for you
insertDigits(digits); mPicker.get().insertDigits(digits);
mAmPmState = HRS_24; mPicker.get().mAmPmState = HRS_24;
} }
updateNumpadStates(); mPicker.get().updateNumpadStates();
}
} }
private boolean is24HourFormat() { private boolean is24HourFormat() {
@ -378,7 +400,8 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
} }
private void updateFabState() { private void updateFabState() {
mFab.setEnabled(checkTimeValid()); if (mFab != null && mFab.get() != null)
mFab.get().setEnabled(checkTimeValid());
} }
private void updateBackspaceState() { private void updateBackspaceState() {
@ -386,39 +409,41 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
} }
private void updateAltButtonStates() { private void updateAltButtonStates() {
if (mLeftAlt == null || mRightAlt == null || mLeftAlt.get() == null || mRightAlt.get() == null)
return;
if (count() == 0) { if (count() == 0) {
// No input, no access! // No input, no access!
mAltButtons[0].setEnabled(false); mLeftAlt.get().setEnabled(false);
mAltButtons[1].setEnabled(false); mRightAlt.get().setEnabled(false);
} else if (count() == 1) { } else if (count() == 1) {
// Any of 0-9 inputted, always have access in either clock. // Any of 0-9 inputted, always have access in either clock.
mAltButtons[0].setEnabled(true); mLeftAlt.get().setEnabled(true);
mAltButtons[1].setEnabled(true); mRightAlt.get().setEnabled(true);
} else if (count() == 2) { } else if (count() == 2) {
// Any 2 digits that make a valid hour for either clock are eligible for access // Any 2 digits that make a valid hour for either clock are eligible for access
int time = getInput(); int time = getInput();
boolean validTwoDigitHour = is24HourFormat() ? time <= 23 : time >= 10 && time <= 12; boolean validTwoDigitHour = is24HourFormat() ? time <= 23 : time >= 10 && time <= 12;
mAltButtons[0].setEnabled(validTwoDigitHour); mLeftAlt.get().setEnabled(validTwoDigitHour);
mAltButtons[1].setEnabled(validTwoDigitHour); mRightAlt.get().setEnabled(validTwoDigitHour);
} else if (count() == 3) { } else if (count() == 3) {
if (is24HourFormat()) { if (is24HourFormat()) {
// For the 24-hour clock, no access at all because // For the 24-hour clock, no access at all because
// two more digits (00 or 30) cannot be added to 3 digits. // two more digits (00 or 30) cannot be added to 3 digits.
mAltButtons[0].setEnabled(false); mLeftAlt.get().setEnabled(false);
mAltButtons[1].setEnabled(false); mRightAlt.get().setEnabled(false);
} else { } else {
// True for any 3 digits, if AM/PM not already entered // True for any 3 digits, if AM/PM not already entered
boolean enabled = mAmPmState == UNSPECIFIED; boolean enabled = mAmPmState == UNSPECIFIED;
mAltButtons[0].setEnabled(enabled); mLeftAlt.get().setEnabled(enabled);
mAltButtons[1].setEnabled(enabled); mRightAlt.get().setEnabled(enabled);
} }
} else if (count() == MAX_DIGITS) { } else if (count() == MAX_DIGITS) {
// If all 4 digits are filled in, the 24-hour clock has absolutely // If all 4 digits are filled in, the 24-hour clock has absolutely
// no need for the alt buttons. However, The 12-hour clock has // no need for the alt buttons. However, The 12-hour clock has
// complete need of them, if not already used. // complete need of them, if not already used.
boolean enabled = !is24HourFormat() && mAmPmState == UNSPECIFIED; boolean enabled = !is24HourFormat() && mAmPmState == UNSPECIFIED;
mAltButtons[0].setEnabled(enabled); mLeftAlt.get().setEnabled(enabled);
mAltButtons[1].setEnabled(enabled); mRightAlt.get().setEnabled(enabled);
} }
} }

View File

@ -1,14 +1,21 @@
package com.philliphsu.clock2.editalarm; package com.philliphsu.clock2.editalarm;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.text.format.DateFormat;
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.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import com.philliphsu.clock2.R; import com.philliphsu.clock2.R;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import butterknife.Bind; import butterknife.Bind;
import butterknife.OnClick;
import butterknife.OnTouch; import butterknife.OnTouch;
/** /**
@ -40,6 +47,9 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
@Bind(R.id.input_time) EditText mInputField; @Bind(R.id.input_time) EditText mInputField;
@Bind(R.id.number_grid) NumpadTimePicker mNumpad; @Bind(R.id.number_grid) NumpadTimePicker mNumpad;
@Bind(R.id.focus_grabber) View mFocusGrabber; @Bind(R.id.focus_grabber) View mFocusGrabber;
@Bind({ R.id.leftAlt, R.id.rightAlt })
Button[] mAltButtons;
@Bind(R.id.fab) FloatingActionButton mFab;
// TODO: We don't need to pass in an initial hour and minute for a new instance. // TODO: We don't need to pass in an initial hour and minute for a new instance.
// TODO: Delete is24HourMode? // TODO: Delete is24HourMode?
@ -79,18 +89,11 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState); View view = super.onCreateView(inflater, container, savedInstanceState);
// Can't do a method bind because the FAB is not part of this dialog's layout
// Also can't do the bind in the Numpad's class, because it doesn't have access to // Pass in our views so numpad can control their states for us
// the OnTimeSetListener callback contained here or the dialog's dismiss() mNumpad.setFab(mFab);
mNumpad.setFabClickListener(new View.OnClickListener() { mNumpad.setAltButtons(mAltButtons[0], mAltButtons[1]);
@Override
public void onClick(View v) {
if (!mNumpad.checkTimeValid())
return;
mCallback.onTimeSet(mNumpad, mNumpad.hourOfDay(), mNumpad.minute());
dismiss();
}
});
mNumpad.setOnInputChangeListener(this); mNumpad.setOnInputChangeListener(this);
mNumpad.insertDigits(mInputtedDigits); // TOneverDO: before mNumpad.setOnInputChangeListener(this); mNumpad.insertDigits(mInputtedDigits); // TOneverDO: before mNumpad.setOnInputChangeListener(this);
// Show the cursor immediately // Show the cursor immediately
@ -98,6 +101,15 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
// TODO: Disabled color // TODO: Disabled color
//updateInputText(""); // Primarily to disable 'OK' //updateInputText(""); // Primarily to disable 'OK'
if (DateFormat.is24HourFormat(getActivity())) {
mAltButtons[0].setText(R.string.left_alt_24hr);
mAltButtons[1].setText(R.string.right_alt_24hr);
} else {
String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
mAltButtons[0].setText(amPmTexts[Calendar.AM]);
mAltButtons[1].setText(amPmTexts[Calendar.PM]);
}
return view; return view;
} }
@ -142,6 +154,14 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
return true; return true;
} }
@OnClick(R.id.fab)
void confirmSelection() {
if (!mNumpad.checkTimeValid())
return;
mCallback.onTimeSet(mNumpad, mNumpad.hourOfDay(), mNumpad.minute());
dismiss();
}
private void updateInputText(String inputText) { private void updateInputText(String inputText) {
TimeTextUtils.setText(inputText, mInputField); TimeTextUtils.setText(inputText, mInputField);
// Move the cursor // Move the cursor

View File

@ -52,7 +52,6 @@
grid:layout_column="1" grid:layout_column="1"
android:text="0"/> android:text="0"/>
<ImageButton <ImageButton
android:id="@+id/backspace" android:id="@+id/backspace"
android:src="@drawable/ic_backspace_24dp" android:src="@drawable/ic_backspace_24dp"

View File

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<include layout="@layout/content_grid_layout_numpad"/>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_columnSpan="3">
<android.support.v7.widget.GridLayout
android:id="@+id/ampm"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:columnCount="2"
app:rowCount="1">
<Button
android:id="@+id/leftAlt"
style="@style/GridLayoutNumpadButton"
app:layout_column="0"/>
<Button
android:id="@+id/rightAlt"
style="@style/GridLayoutNumpadButton"
app:layout_column="1"/>
</android.support.v7.widget.GridLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_done_24dp"
app:layout_anchor="@id/ampm"
app:layout_anchorGravity="center"/>
</android.support.design.widget.CoordinatorLayout>
</merge>

View File

@ -1,9 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- TOneverDO: Use LinearLayout, because it doesn't obey LWM --> <android.support.design.widget.CoordinatorLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="vertical">
<!-- TOneverDO: Use LinearLayout as root container when the
dialog is a DialogFragment (or a subclass of), or else LWM
doesn't work. -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText <EditText
android:id="@+id/input_time" android:id="@+id/input_time"
@ -16,15 +23,58 @@
<View style="@style/FocusGrabber" <View style="@style/FocusGrabber"
android:id="@+id/focus_grabber"/> android:id="@+id/focus_grabber"/>
<View style="@style/Divider"/> <View style="@style/Divider"
android:id="@+id/header_divider"
android:layout_below="@id/input_time"/>
<!-- TODO: Adjust margins -->
<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="256dp"
android:layout_below="@id/header_divider"
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="20dp"
android:layout_marginEnd="@dimen/bottom_sheet_edge_margin" android:layout_marginEnd="20dp"
android:layout_marginBottom="@dimen/bottom_sheet_vertical_space"/> android:layout_marginBottom="28dp"/>
</LinearLayout> <View style="@style/Divider"
android:id="@+id/footer_divider"
android:layout_below="@id/number_grid"/>
<LinearLayout
android:id="@+id/ampm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/footer_divider">
<Button
android:id="@+id/leftAlt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?selectableItemBackground"
android:textSize="20sp"/>
<Button
android:id="@+id/rightAlt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?selectableItemBackground"
android:textSize="20sp"/>
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_done_24dp"
app:layout_anchor="@id/footer_divider"
app:layout_anchorGravity="center"/>
</android.support.design.widget.CoordinatorLayout>