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 df8faf4..a89b200 100644
--- a/app/src/main/java/com/philliphsu/clock2/editalarm/BaseTimePickerDialog.java
+++ b/app/src/main/java/com/philliphsu/clock2/editalarm/BaseTimePickerDialog.java
@@ -3,18 +3,17 @@ package com.philliphsu.clock2.editalarm;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
-import android.support.v4.app.DialogFragment;
+import android.support.design.widget.BottomSheetDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.view.Window;
import butterknife.ButterKnife;
/**
* 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
// can use to interface with this field.
@@ -50,8 +49,9 @@ public abstract class BaseTimePickerDialog extends DialogFragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
- getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
- View view = inflater.inflate(contentLayout(), container, false);
+ // Not needed for bottom sheet dialogs
+// getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+ final View view = inflater.inflate(contentLayout(), container, false);
ButterKnife.bind(this, view);
return view;
}
@@ -86,11 +86,13 @@ public abstract class BaseTimePickerDialog extends DialogFragment {
// 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);
-// // We're past onCreate() in the lifecycle, so we can safely retrieve the host activity.
+// //dialog = new BottomSheetDialog(getActivity(), R.style.AppTheme_AppCompatDialog/*crashes our app!*/);
+// // 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
@@ -98,19 +100,21 @@ public abstract class BaseTimePickerDialog extends DialogFragment {
// * @see {@link BottomSheetDialog#wrapInBottomSheet(int, View, ViewGroup.LayoutParams)}
// */
// 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);
// 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 1ce1577..1049d56 100644
--- a/app/src/main/java/com/philliphsu/clock2/editalarm/EditAlarmActivity.java
+++ b/app/src/main/java/com/philliphsu/clock2/editalarm/EditAlarmActivity.java
@@ -5,6 +5,7 @@ import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
+import android.preference.PreferenceManager;
import android.support.annotation.StringRes;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.LoaderManager;
@@ -321,14 +322,23 @@ public class EditAlarmActivity extends BaseActivity implements
// If we keep a reference to the dialog, we keep its previous state as well.
// So the next time we call show() on it, the input field will show the
// last inputted time.
-// NumpadTimePickerDialog.newInstance(this).show(getSupportFragmentManager(), TAG_TIME_PICKER);
- // 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));
+ BaseTimePickerDialog dialog = null;
+ String numpadStyle = getString(R.string.number_pad);
+ String gridStyle = getString(R.string.grid_selector);
+ String prefTimePickerStyle = PreferenceManager.getDefaultSharedPreferences(this).getString(
+ // key for the preference value to retrieve
+ getString(R.string.key_time_picker_style),
+ // default value
+ numpadStyle);
+ if (prefTimePickerStyle.equals(numpadStyle)) {
+ dialog = NumpadTimePickerDialog.newInstance(this);
+ } else if (prefTimePickerStyle.equals(gridStyle)) {
+ dialog = NumberGridTimePickerDialog.newInstance(
+ this, // OnTimeSetListener
+ 0, // Initial hour of day
+ 0, // Initial minute
+ DateFormat.is24HourFormat(this));
+ }
dialog.show(getSupportFragmentManager(), TAG_TIME_PICKER);
}
diff --git a/app/src/main/java/com/philliphsu/clock2/editalarm/GridLayoutNumpad.java b/app/src/main/java/com/philliphsu/clock2/editalarm/GridLayoutNumpad.java
index da09600..4fc5fb1 100644
--- a/app/src/main/java/com/philliphsu/clock2/editalarm/GridLayoutNumpad.java
+++ b/app/src/main/java/com/philliphsu/clock2/editalarm/GridLayoutNumpad.java
@@ -2,10 +2,10 @@ package com.philliphsu.clock2.editalarm;
import android.content.Context;
import android.support.annotation.CallSuper;
+import android.support.annotation.LayoutRes;
import android.support.v7.widget.GridLayout;
import android.util.AttributeSet;
import android.view.View;
-import android.widget.ImageButton;
import android.widget.TextView;
import com.philliphsu.clock2.R;
@@ -15,7 +15,6 @@ import java.util.Arrays;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
-import butterknife.OnLongClick;
/**
* Created by Phillip Hsu on 7/12/2016.
@@ -37,7 +36,6 @@ public abstract class GridLayoutNumpad extends GridLayout {
@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 })
TextView[] mButtons;
- @Bind(R.id.backspace) ImageButton mBackspace;
/**
* Informs clients how to output the digits inputted into this numpad.
@@ -71,6 +69,9 @@ public abstract class GridLayoutNumpad extends GridLayout {
*/
public abstract int capacity();
+ @LayoutRes
+ protected abstract int contentLayout();
+
public final void setOnInputChangeListener(OnInputChangeListener onInputChangeListener) {
mOnInputChangeListener = onInputChangeListener;
}
@@ -92,10 +93,6 @@ public abstract class GridLayoutNumpad extends GridLayout {
mButtons[i].setEnabled(i >= lowerLimitInclusive && i < upperLimitExclusive);
}
- protected final void setBackspaceEnabled(boolean enabled) {
- mBackspace.setEnabled(enabled);
- }
-
protected final int valueAt(int index) {
return mInput[index];
}
@@ -131,7 +128,6 @@ public abstract class GridLayoutNumpad extends GridLayout {
return currentInput;
}
- @OnClick(R.id.backspace)
public void delete() {
/*
if (mCount - 1 >= 0) {
@@ -152,7 +148,6 @@ public abstract class GridLayoutNumpad extends GridLayout {
}
}
- @OnLongClick(R.id.backspace)
public boolean clear() {
Arrays.fill(mInput, UNMODIFIED);
mCount = 0;
@@ -238,7 +233,7 @@ public abstract class GridLayoutNumpad extends GridLayout {
private void init() {
setAlignmentMode(ALIGN_BOUNDS);
setColumnCount(COLUMNS);
- View.inflate(getContext(), R.layout.content_grid_layout_numpad, this);
+ View.inflate(getContext(), contentLayout(), this);
ButterKnife.bind(this);
// If capacity() < 0, we let the system throw the exception.
mInput = new int[capacity()];
diff --git a/app/src/main/java/com/philliphsu/clock2/editalarm/NumberGridTimePickerDialog.java b/app/src/main/java/com/philliphsu/clock2/editalarm/NumberGridTimePickerDialog.java
index 11584ac..ddf3f58 100644
--- a/app/src/main/java/com/philliphsu/clock2/editalarm/NumberGridTimePickerDialog.java
+++ b/app/src/main/java/com/philliphsu/clock2/editalarm/NumberGridTimePickerDialog.java
@@ -222,7 +222,7 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
}
if (index == MINUTE_INDEX) {
- createMinutesGrid();
+ createMinuteTuners();
}
}
}
@@ -277,7 +277,7 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
onValueSelected(HOUR_INDEX, mSelectedHourOfDay, false);
}
- private void createMinutesGrid() {
+ private void createMinuteTuners() {
// https://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-by.html
// "When inflating a layout starting with a , you *must* specify a parent ViewGroup
// and you must set attachToRoot to true (see the documentation of the LayoutInflater#inflate() method)"
@@ -305,8 +305,12 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
return;
}
int value = Integer.parseInt(number);
- if (mCurrentIndex == HOUR_INDEX && !mIs24HourMode && mSelectedHalfDay == HALF_DAY_2) {
- value = (value % 12) + 12;
+ if (mCurrentIndex == HOUR_INDEX && !mIs24HourMode) {
+ if (value == 12 && mSelectedHalfDay == HALF_DAY_1) {
+ value = 0;
+ } else if (value != 12 && mSelectedHalfDay == HALF_DAY_2) {
+ value += 12;
+ }
}
onValueSelected(mCurrentIndex, value, true);
}
@@ -438,7 +442,7 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
mInitialHourOfDay = savedInstanceState.getInt(KEY_HOUR_OF_DAY);
mInitialMinute = savedInstanceState.getInt(KEY_MINUTE);
mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
- mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
+// mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
mThemeDark = savedInstanceState.getBoolean(KEY_DARK_THEME);
}
}
@@ -460,7 +464,7 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
setNumberTexts();
setClickListenersOnButtons();
if (mCurrentIndex == MINUTE_INDEX) {
- createMinutesGrid();
+ createMinuteTuners();
}
Resources res = getResources();
@@ -672,6 +676,11 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
// }
// outState.putBoolean(KEY_DARK_THEME, mThemeDark);
// }
+ outState.putInt(KEY_HOUR_OF_DAY, mSelectedHourOfDay);
+ outState.putInt(KEY_MINUTE, mSelectedMinute);
+ outState.putBoolean(KEY_IS_24_HOUR_VIEW, mIs24HourMode);
+ outState.putInt(KEY_CURRENT_ITEM_SHOWING, mCurrentIndex);
+ outState.putBoolean(KEY_DARK_THEME, mThemeDark);
}
// /**
diff --git a/app/src/main/java/com/philliphsu/clock2/editalarm/NumpadTimePicker.java b/app/src/main/java/com/philliphsu/clock2/editalarm/NumpadTimePicker.java
index e21c48c..3558e0d 100644
--- a/app/src/main/java/com/philliphsu/clock2/editalarm/NumpadTimePicker.java
+++ b/app/src/main/java/com/philliphsu/clock2/editalarm/NumpadTimePicker.java
@@ -5,13 +5,20 @@ import android.support.annotation.IntDef;
import android.support.design.widget.FloatingActionButton;
import android.text.format.DateFormat;
import android.util.AttributeSet;
-import android.view.View;
+import android.widget.Button;
+import android.widget.ImageButton;
import android.widget.TextView;
+import com.philliphsu.clock2.R;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-import java.lang.ref.WeakReference;
import java.text.DateFormatSymbols;
+import java.util.Calendar;
+
+import butterknife.Bind;
+import butterknife.OnClick;
+import butterknife.OnLongClick;
/**
* Created by Phillip Hsu on 7/12/2016.
@@ -43,9 +50,10 @@ public class NumpadTimePicker extends GridLayoutNumpad {
private int mAmPmState = UNSPECIFIED;
private final StringBuilder mFormattedInput = new StringBuilder(MAX_CHARS);
- private WeakReference mLeftAlt;
- private WeakReference mRightAlt;
- private WeakReference mFab;
+ @Bind({ R.id.leftAlt, R.id.rightAlt })
+ Button[] mAltButtons;
+ @Bind(R.id.fab) FloatingActionButton mFab;
+ @Bind(R.id.backspace) ImageButton mBackspace;
/**
* Provides additional APIs to configure clients' display output.
@@ -73,17 +81,18 @@ public class NumpadTimePicker extends GridLayoutNumpad {
return MAX_DIGITS;
}
+ @Override
+ protected int contentLayout() {
+ return R.layout.content_numpad_time_picker;
+ }
+
@Override
protected void enable(int lowerLimitInclusive, int upperLimitExclusive) {
super.enable(lowerLimitInclusive, upperLimitExclusive);
if (lowerLimitInclusive == 0 && upperLimitExclusive == 0) {
// For 12-hour clock, alt buttons need to be disabled as well before firing onInputDisabled()
- if (!is24HourFormat()) {
- if (mLeftAlt != null && mLeftAlt.get() != null
- && mRightAlt != null && mRightAlt.get() != null
- && (mLeftAlt.get().isEnabled() || mRightAlt.get().isEnabled())) {
- return;
- }
+ if (!is24HourFormat() && (mAltButtons[0].isEnabled() || mAltButtons[1].isEnabled())) {
+ return;
}
((OnInputChangeListener) getOnInputChangeListener()).onInputDisabled();
}
@@ -113,6 +122,7 @@ public class NumpadTimePicker extends GridLayoutNumpad {
}
@Override
+ @OnClick(R.id.backspace)
public void delete() {
int len = mFormattedInput.length();
if (!is24HourFormat() && mAmPmState != UNSPECIFIED) {
@@ -121,7 +131,7 @@ public class NumpadTimePicker extends GridLayoutNumpad {
mFormattedInput.delete(mFormattedInput.indexOf(" "), len);
// No digit was actually deleted, but we have to notify the
// listener to update its output.
-/*TOneverDO: remove super*/super.onDigitDeleted(mFormattedInput.toString());
+ super/*TOneverDO: remove super*/.onDigitDeleted(mFormattedInput.toString());
// We also have to manually update the numpad.
updateNumpadStates();
} else {
@@ -129,8 +139,14 @@ public class NumpadTimePicker extends GridLayoutNumpad {
}
}
+ @Override
+ @OnLongClick(R.id.backspace)
+ public boolean clear() {
+ return super.clear();
+ }
+
/** Returns the hour of day (0-23) regardless of clock system */
- public int hourOfDay() {
+ public int getHour() {
if (!checkTimeValid())
throw new IllegalStateException("Cannot call hourOfDay() until legal time inputted");
int hours = count() < 4 ? valueAt(0) : valueAt(0) * 10 + valueAt(1);
@@ -150,7 +166,7 @@ public class NumpadTimePicker extends GridLayoutNumpad {
return hours + (mAmPmState == PM ? 12 : 0);
}
- public int minute() {
+ public int getMinute() {
if (!checkTimeValid())
throw new IllegalStateException("Cannot call minute() until legal time inputted");
return count() < 4 ? valueAt(1) * 10 + valueAt(2) : valueAt(2) * 10 + valueAt(3);
@@ -229,9 +245,8 @@ public class NumpadTimePicker extends GridLayoutNumpad {
}
mAmPmState = amPmState;
- if (mAmPmState != HRS_24 && mLeftAlt != null && mRightAlt != null
- && mLeftAlt.get() != null && mRightAlt.get() != null) {
- mAltButtonClickListener.onClick(mAmPmState == AM ? mLeftAlt.get() : mRightAlt.get());
+ if (mAmPmState != HRS_24) {
+ onAltButtonClick(mAmPmState == AM ? mAltButtons[0] : mAltButtons[1]);
}
}
@@ -239,81 +254,50 @@ public class NumpadTimePicker extends GridLayoutNumpad {
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) {
-// 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() {
- /* This was where we set the text on the alt buttons, when they were still part of our layout */
+ if (DateFormat.is24HourFormat(getContext())) {
+ 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();
}
- private final AltButtonClickListener mAltButtonClickListener = new AltButtonClickListener(this);
-
- private static class AltButtonClickListener implements OnClickListener {
- private final WeakReference 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
- 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;
+ @OnClick({ R.id.leftAlt, R.id.rightAlt })
+ void onAltButtonClick(TextView altBtn) {
+ // Manually insert special characters for 12-hour clock
+ if (!is24HourFormat()) {
+ if (count() <= 2) {
+ // The colon is inserted for you
+ insertDigits(0, 0);
}
-
- mPicker.get().updateNumpadStates();
+ // text is AM or PM, so include space before
+ String ampm = altBtn.getText().toString();
+ mFormattedInput.append(' ').append(ampm);
+ String am = new DateFormatSymbols().getAmPmStrings()[0];
+ mAmPmState = ampm.equals(am) ? AM : PM;
+ // Digits will be shown for you on insert, but not AM/PM
+ super/*TOneverDO: remove 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();
}
private boolean is24HourFormat() {
@@ -398,50 +382,47 @@ public class NumpadTimePicker extends GridLayoutNumpad {
}
private void updateFabState() {
- if (mFab != null && mFab.get() != null)
- mFab.get().setEnabled(checkTimeValid());
+ mFab.setEnabled(checkTimeValid());
}
private void updateBackspaceState() {
- setBackspaceEnabled(count() > 0);
+ mBackspace.setEnabled(count() > 0);
}
private void updateAltButtonStates() {
- if (mLeftAlt == null || mRightAlt == null || mLeftAlt.get() == null || mRightAlt.get() == null)
- return;
if (count() == 0) {
// No input, no access!
- mLeftAlt.get().setEnabled(false);
- mRightAlt.get().setEnabled(false);
+ mAltButtons[0].setEnabled(false);
+ mAltButtons[1].setEnabled(false);
} else if (count() == 1) {
// Any of 0-9 inputted, always have access in either clock.
- mLeftAlt.get().setEnabled(true);
- mRightAlt.get().setEnabled(true);
+ mAltButtons[0].setEnabled(true);
+ mAltButtons[1].setEnabled(true);
} else if (count() == 2) {
// Any 2 digits that make a valid hour for either clock are eligible for access
int time = getInput();
boolean validTwoDigitHour = is24HourFormat() ? time <= 23 : time >= 10 && time <= 12;
- mLeftAlt.get().setEnabled(validTwoDigitHour);
- mRightAlt.get().setEnabled(validTwoDigitHour);
+ mAltButtons[0].setEnabled(validTwoDigitHour);
+ mAltButtons[1].setEnabled(validTwoDigitHour);
} else if (count() == 3) {
if (is24HourFormat()) {
// For the 24-hour clock, no access at all because
// two more digits (00 or 30) cannot be added to 3 digits.
- mLeftAlt.get().setEnabled(false);
- mRightAlt.get().setEnabled(false);
+ mAltButtons[0].setEnabled(false);
+ mAltButtons[1].setEnabled(false);
} else {
// True for any 3 digits, if AM/PM not already entered
boolean enabled = mAmPmState == UNSPECIFIED;
- mLeftAlt.get().setEnabled(enabled);
- mRightAlt.get().setEnabled(enabled);
+ mAltButtons[0].setEnabled(enabled);
+ mAltButtons[1].setEnabled(enabled);
}
} else if (count() == MAX_DIGITS) {
// 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
// complete need of them, if not already used.
boolean enabled = !is24HourFormat() && mAmPmState == UNSPECIFIED;
- mLeftAlt.get().setEnabled(enabled);
- mRightAlt.get().setEnabled(enabled);
+ mAltButtons[0].setEnabled(enabled);
+ mAltButtons[1].setEnabled(enabled);
}
}
diff --git a/app/src/main/java/com/philliphsu/clock2/editalarm/NumpadTimePickerDialog.java b/app/src/main/java/com/philliphsu/clock2/editalarm/NumpadTimePickerDialog.java
index 752f608..3382b2f 100644
--- a/app/src/main/java/com/philliphsu/clock2/editalarm/NumpadTimePickerDialog.java
+++ b/app/src/main/java/com/philliphsu/clock2/editalarm/NumpadTimePickerDialog.java
@@ -1,19 +1,13 @@
package com.philliphsu.clock2.editalarm;
import android.os.Bundle;
-import android.support.design.widget.FloatingActionButton;
-import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.Button;
import android.widget.EditText;
import com.philliphsu.clock2.R;
-import java.text.DateFormatSymbols;
-import java.util.Calendar;
-
import butterknife.Bind;
import butterknife.OnClick;
import butterknife.OnTouch;
@@ -24,6 +18,7 @@ import butterknife.OnTouch;
*/
public class NumpadTimePickerDialog extends BaseTimePickerDialog
implements NumpadTimePicker.OnInputChangeListener {
+ private static final String TAG = "NumpadTimePickerDialog";
private static final String KEY_HOUR_OF_DAY = "hour_of_day";
private static final String KEY_MINUTE = "minute";
@@ -47,12 +42,8 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
@Bind(R.id.input_time) EditText mInputField;
@Bind(R.id.number_grid) NumpadTimePicker mNumpad;
@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: Delete is24HourMode?
@Deprecated
public static NumpadTimePickerDialog newInstance(OnTimeSetListener callback,
int hourOfDay, int minute, boolean is24HourMode) {
@@ -61,6 +52,7 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
return ret;
}
+ // TODO: is24HourMode param
public static NumpadTimePickerDialog newInstance(OnTimeSetListener callback) {
NumpadTimePickerDialog ret = new NumpadTimePickerDialog();
ret.setOnTimeSetListener(callback);
@@ -89,27 +81,12 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
-
- // Pass in our views so numpad can control their states for us
- mNumpad.setFab(mFab);
- mNumpad.setAltButtons(mAltButtons[0], mAltButtons[1]);
-
mNumpad.setOnInputChangeListener(this);
mNumpad.insertDigits(mInputtedDigits); // TOneverDO: before mNumpad.setOnInputChangeListener(this);
// Show the cursor immediately
mInputField.requestFocus();
// TODO: Disabled color
//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;
}
@@ -154,11 +131,14 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
return true;
}
+ // The FAB is not defined directly in this dialog's layout, but rather in the layout
+ // of the NumpadTimePicker. We can always reference a child of a ViewGroup that is
+ // part of our layout.
@OnClick(R.id.fab)
void confirmSelection() {
if (!mNumpad.checkTimeValid())
return;
- mCallback.onTimeSet(mNumpad, mNumpad.hourOfDay(), mNumpad.minute());
+ mCallback.onTimeSet(mNumpad, mNumpad.getHour(), mNumpad.getMinute());
dismiss();
}
diff --git a/app/src/main/res/layout/content_grid_layout_numpad.xml b/app/src/main/res/layout/content_grid_layout_numpad.xml
index 9b87651..09506f2 100644
--- a/app/src/main/res/layout/content_grid_layout_numpad.xml
+++ b/app/src/main/res/layout/content_grid_layout_numpad.xml
@@ -51,10 +51,4 @@
style="@style/GridLayoutNumpadButton"
grid:layout_column="1"
android:text="0"/>
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/content_number_grid_minute_tuners.xml b/app/src/main/res/layout/content_number_grid_minute_tuners.xml
index 52080d0..8b5eb44 100644
--- a/app/src/main/res/layout/content_number_grid_minute_tuners.xml
+++ b/app/src/main/res/layout/content_number_grid_minute_tuners.xml
@@ -5,7 +5,7 @@
+ app:layout_column="0"/>
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_time_picker_number_grid.xml b/app/src/main/res/layout/dialog_time_picker_number_grid.xml
index 3bd978a..737e660 100644
--- a/app/src/main/res/layout/dialog_time_picker_number_grid.xml
+++ b/app/src/main/res/layout/dialog_time_picker_number_grid.xml
@@ -29,7 +29,9 @@
android:layout_height="@dimen/numpad_height"
android:layout_below="@id/time_display_background"
app:columnCount="3"
- android:layout_marginBottom="28dp"/>
+ android:layout_marginStart="@dimen/bottom_sheet_edge_margin"
+ android:layout_marginEnd="@dimen/bottom_sheet_edge_margin"
+ android:paddingBottom="@dimen/anchored_fab_vertical_space"/>
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:gravity="center"
+ android:textSize="@dimen/time_input_text_size"
+ android:background="@android:color/transparent"/>
-
\ No newline at end of file
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/element_number_grid.xml b/app/src/main/res/layout/element_number_grid.xml
deleted file mode 100644
index 2f3cfc2..0000000
--- a/app/src/main/res/layout/element_number_grid.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index f92ef9c..197c5c4 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -25,4 +25,9 @@
24dp16dp
+ 28dp
+
+ 500dp
diff --git a/app/src/main/res/values/prefs_alarms.xml b/app/src/main/res/values/prefs_alarms.xml
index 4995d0d..8e7ea73 100644
--- a/app/src/main/res/values/prefs_alarms.xml
+++ b/app/src/main/res/values/prefs_alarms.xml
@@ -5,11 +5,15 @@
key_time_picker_styleTime picker style
- Number pad
- Radial clock
+
+ Numeric keypad
+
+ Grid selector@string/number_pad
- @string/radial_clock
+
+ @string/grid_selector
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 5e1560b..72c8bcb 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -6,6 +6,9 @@
@color/colorPrimary@color/colorPrimaryDark@color/colorAccent
+
+ @style/AppCompatDialogTheme
+ @style/BottomSheetDialogTheme
@@ -57,7 +60,11 @@
+
+
+
+
+
+
+