Moved alt buttons and fab to dialog layout
This commit is contained in:
parent
62524bc0b5
commit
a07cf222b3
@ -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() {
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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.
|
||||||
@ -46,10 +42,10 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
|
|||||||
@AmPmState
|
@AmPmState
|
||||||
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,18 +73,17 @@ 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()) {
|
||||||
return;
|
if (mLeftAlt != null && mLeftAlt.get() != null
|
||||||
|
&& mRightAlt != null && mRightAlt.get() != null
|
||||||
|
&& (mLeftAlt.get().isEnabled() || mRightAlt.get().isEnabled())) {
|
||||||
|
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,55 +241,81 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFab(FloatingActionButton fab) {
|
||||||
|
mFab = new WeakReference<>(fab);
|
||||||
|
updateNumpadStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAltButtons(TextView leftAlt, TextView rightAlt) {
|
||||||
|
mLeftAlt = new WeakReference<>(leftAlt);
|
||||||
|
mRightAlt = new WeakReference<>(rightAlt);
|
||||||
|
mLeftAlt.get().setOnClickListener(mAltButtonClickListener);
|
||||||
|
mRightAlt.get().setOnClickListener(mAltButtonClickListener);
|
||||||
|
updateNumpadStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
if (is24HourFormat()) {
|
/* This was where we set the text on the alt buttons, when they were still part of our layout */
|
||||||
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 })
|
private final AltButtonClickListener mAltButtonClickListener = new AltButtonClickListener(this);
|
||||||
void onAltButtonClick(Button altBtn) {
|
|
||||||
if (mAltButtons[0] != altBtn && mAltButtons[1] != altBtn)
|
|
||||||
throw new IllegalArgumentException("Not called with one of the alt buttons");
|
|
||||||
|
|
||||||
// Manually insert special characters for 12-hour clock
|
private static class AltButtonClickListener implements OnClickListener {
|
||||||
if (!is24HourFormat()) {
|
private final WeakReference<NumpadTimePicker> mPicker;
|
||||||
if (count() <= 2) {
|
|
||||||
// The colon is inserted for you
|
public AltButtonClickListener(NumpadTimePicker picker) {
|
||||||
insertDigits(0, 0);
|
mPicker = new WeakReference<>(picker);
|
||||||
}
|
|
||||||
// text is AM or PM, so include space before
|
|
||||||
mFormattedInput.append(' ').append(altBtn.getText());
|
|
||||||
mAmPmState = mAltButtons[0] == altBtn ? AM : PM;
|
|
||||||
// Digits will be shown for you on insert, but not AM/PM
|
|
||||||
/*TOneverDO: remove super*/super.onDigitInserted(mFormattedInput.toString());
|
|
||||||
} else {
|
|
||||||
CharSequence text = altBtn.getText();
|
|
||||||
int[] digits = new int[text.length() - 1];
|
|
||||||
// charAt(0) is the colon, so skip i = 0.
|
|
||||||
// We are only interested in storing the digits.
|
|
||||||
for (int i = 1; i < text.length(); i++) {
|
|
||||||
// The array and the text do not have the same lengths,
|
|
||||||
// so the iterator value does not correspond to the
|
|
||||||
// array index directly
|
|
||||||
digits[i - 1] = Character.digit(text.charAt(i), BASE_10);
|
|
||||||
}
|
|
||||||
// Colon is added for you
|
|
||||||
insertDigits(digits);
|
|
||||||
mAmPmState = HRS_24;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateNumpadStates();
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
TextView altBtn = (TextView) v;
|
||||||
|
|
||||||
|
// Manually insert special characters for 12-hour clock
|
||||||
|
if (!mPicker.get().is24HourFormat()) {
|
||||||
|
if (mPicker.get().count() <= 2) {
|
||||||
|
// The colon is inserted for you
|
||||||
|
mPicker.get().insertDigits(0, 0);
|
||||||
|
}
|
||||||
|
// text is AM or PM, so include space before
|
||||||
|
String ampm = altBtn.getText().toString();
|
||||||
|
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
|
||||||
|
((/*NOT REDUNDANT! TOneverDO: Remove cast*/GridLayoutNumpad)
|
||||||
|
mPicker.get()).onDigitInserted(mFormattedInput.toString());
|
||||||
|
} else {
|
||||||
|
CharSequence text = altBtn.getText();
|
||||||
|
int[] digits = new int[text.length() - 1];
|
||||||
|
// charAt(0) is the colon, so skip i = 0.
|
||||||
|
// We are only interested in storing the digits.
|
||||||
|
for (int i = 1; i < text.length(); i++) {
|
||||||
|
// The array and the text do not have the same lengths,
|
||||||
|
// so the iterator value does not correspond to the
|
||||||
|
// array index directly
|
||||||
|
digits[i - 1] = Character.digit(text.charAt(i), BASE_10);
|
||||||
|
}
|
||||||
|
// Colon is added for you
|
||||||
|
mPicker.get().insertDigits(digits);
|
||||||
|
mPicker.get().mAmPmState = HRS_24;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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"
|
||||||
|
|||||||
@ -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>
|
|
||||||
@ -1,30 +1,80 @@
|
|||||||
<?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"
|
||||||
android:layout_width="match_parent"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:orientation="vertical">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<EditText
|
<!-- TOneverDO: Use LinearLayout as root container when the
|
||||||
android:id="@+id/input_time"
|
dialog is a DialogFragment (or a subclass of), or else LWM
|
||||||
|
doesn't work. -->
|
||||||
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/input_time"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textSize="@dimen/time_input_text_size"
|
||||||
|
android:background="@android:color/transparent"/>
|
||||||
|
|
||||||
|
<View style="@style/FocusGrabber"
|
||||||
|
android:id="@+id/focus_grabber"/>
|
||||||
|
|
||||||
|
<View style="@style/Divider"
|
||||||
|
android:id="@+id/header_divider"
|
||||||
|
android:layout_below="@id/input_time"/>
|
||||||
|
|
||||||
|
<!-- TODO: Adjust margins -->
|
||||||
|
<com.philliphsu.clock2.editalarm.NumpadTimePicker
|
||||||
|
android:id="@+id/number_grid"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="256dp"
|
||||||
|
android:layout_below="@id/header_divider"
|
||||||
|
android:layout_marginTop="@dimen/bottom_sheet_vertical_space"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:layout_marginEnd="20dp"
|
||||||
|
android:layout_marginBottom="28dp"/>
|
||||||
|
|
||||||
|
<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:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:src="@drawable/ic_done_24dp"
|
||||||
android:textSize="@dimen/time_input_text_size"
|
app:layout_anchor="@id/footer_divider"
|
||||||
android:background="@android:color/transparent"/>
|
app:layout_anchorGravity="center"/>
|
||||||
|
|
||||||
<View style="@style/FocusGrabber"
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
android:id="@+id/focus_grabber"/>
|
|
||||||
|
|
||||||
<View style="@style/Divider"/>
|
|
||||||
|
|
||||||
<com.philliphsu.clock2.editalarm.NumpadTimePicker
|
|
||||||
android:id="@+id/number_grid"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="@dimen/numpad_height"
|
|
||||||
android:layout_marginTop="@dimen/bottom_sheet_vertical_space"
|
|
||||||
android:layout_marginStart="@dimen/bottom_sheet_edge_margin"
|
|
||||||
android:layout_marginEnd="@dimen/bottom_sheet_edge_margin"
|
|
||||||
android:layout_marginBottom="@dimen/bottom_sheet_vertical_space"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
Loading…
Reference in New Issue
Block a user