Merge branch 'reverted_numpad_time_picker' into timers
This commit is contained in:
commit
9493c639a8
@ -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) {
|
||||
|
||||
@ -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;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -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()];
|
||||
|
||||
@ -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 <merge />, 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);
|
||||
}
|
||||
|
||||
// /**
|
||||
|
||||
@ -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<TextView> mLeftAlt;
|
||||
private WeakReference<TextView> mRightAlt;
|
||||
private WeakReference<FloatingActionButton> 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,18 +81,19 @@ 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())) {
|
||||
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,63 +254,33 @@ 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<NumpadTimePicker> mPicker;
|
||||
|
||||
public AltButtonClickListener(NumpadTimePicker picker) {
|
||||
mPicker = new WeakReference<>(picker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TextView altBtn = (TextView) v;
|
||||
|
||||
@OnClick({ R.id.leftAlt, R.id.rightAlt })
|
||||
void onAltButtonClick(TextView altBtn) {
|
||||
// Manually insert special characters for 12-hour clock
|
||||
if (!mPicker.get().is24HourFormat()) {
|
||||
if (mPicker.get().count() <= 2) {
|
||||
if (!is24HourFormat()) {
|
||||
if (count() <= 2) {
|
||||
// The colon is inserted for you
|
||||
mPicker.get().insertDigits(0, 0);
|
||||
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;
|
||||
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());
|
||||
super/*TOneverDO: remove super*/.onDigitInserted(mFormattedInput.toString());
|
||||
} else {
|
||||
CharSequence text = altBtn.getText();
|
||||
int[] digits = new int[text.length() - 1];
|
||||
@ -308,12 +293,11 @@ public class NumpadTimePicker extends GridLayoutNumpad {
|
||||
digits[i - 1] = Character.digit(text.charAt(i), BASE_10);
|
||||
}
|
||||
// Colon is added for you
|
||||
mPicker.get().insertDigits(digits);
|
||||
mPicker.get().mAmPmState = HRS_24;
|
||||
insertDigits(digits);
|
||||
mAmPmState = HRS_24;
|
||||
}
|
||||
|
||||
mPicker.get().updateNumpadStates();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -51,10 +51,4 @@
|
||||
style="@style/GridLayoutNumpadButton"
|
||||
grid:layout_column="1"
|
||||
android:text="0"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/backspace"
|
||||
android:src="@drawable/ic_backspace_24dp"
|
||||
style="@style/GridLayoutNumpadElement"
|
||||
grid:layout_column="2"/>
|
||||
</merge>
|
||||
@ -5,7 +5,7 @@
|
||||
<ImageButton
|
||||
style="@style/GridLayoutNumpadElement"
|
||||
android:src="@drawable/ic_minus_circle_24dp"
|
||||
app:layout_column="1"/>
|
||||
app:layout_column="0"/>
|
||||
<ImageButton
|
||||
style="@style/GridLayoutNumpadElement"
|
||||
android:src="@drawable/ic_add_circle_24dp"
|
||||
|
||||
31
app/src/main/res/layout/content_numpad_time_picker.xml
Normal file
31
app/src/main/res/layout/content_numpad_time_picker.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?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"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/leftAlt"
|
||||
style="@style/GridLayoutNumpadButton"
|
||||
app:layout_column="0"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/rightAlt"
|
||||
style="@style/GridLayoutNumpadButton"
|
||||
app:layout_column="2"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_gravity="center"
|
||||
app:layout_column="1"
|
||||
android:src="@drawable/ic_done_24dp"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/backspace"
|
||||
android:src="@drawable/ic_backspace_24dp"
|
||||
style="@style/GridLayoutNumpadElement"
|
||||
app:layout_column="2"/>
|
||||
|
||||
</merge>
|
||||
@ -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"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
|
||||
@ -1,14 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
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_height="match_parent">
|
||||
|
||||
<!-- TOneverDO: Use LinearLayout as root container when the
|
||||
dialog is a DialogFragment (or a subclass of), or else LWM
|
||||
doesn't work. -->
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
@ -31,50 +26,11 @@
|
||||
<com.philliphsu.clock2.editalarm.NumpadTimePicker
|
||||
android:id="@+id/number_grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="256dp"
|
||||
android:layout_height="310dp"
|
||||
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.Horizontal"
|
||||
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>
|
||||
android:layout_marginStart="@dimen/bottom_sheet_edge_margin"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_edge_margin"
|
||||
android:paddingBottom="@dimen/bottom_sheet_edge_margin"/>
|
||||
|
||||
</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>
|
||||
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/GridLayoutNumpadButton"
|
||||
android:text="1"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"/>
|
||||
@ -25,4 +25,9 @@
|
||||
<!-- Bottom sheet specs -->
|
||||
<dimen name="bottom_sheet_edge_margin">24dp</dimen>
|
||||
<dimen name="bottom_sheet_vertical_space">16dp</dimen>
|
||||
<dimen name="anchored_fab_vertical_space">28dp</dimen>
|
||||
<!-- If the total height of the contents of a bottom sheet does not exceed this limit,
|
||||
then the sheet will show fully expanded; the contents are not stretched to match this height.
|
||||
This is large enough to accommodate most, if not all, of our layouts. -->
|
||||
<dimen name="peek_height_upper_limit">500dp</dimen>
|
||||
</resources>
|
||||
|
||||
@ -5,11 +5,15 @@
|
||||
<!-- Time picker style -->
|
||||
<string name="key_time_picker_style">key_time_picker_style</string>
|
||||
<string name="title_time_picker_style">Time picker style</string>
|
||||
<string name="number_pad">Number pad</string>
|
||||
<string name="radial_clock">Radial clock</string>
|
||||
<!-- Internally, we refer to this picker as a numpad because it's concise.
|
||||
However, "numeric keypad" is more descriptive when describing the style to users. -->
|
||||
<string name="number_pad">Numeric keypad</string>
|
||||
<!--<string name="radial_clock">Radial clock</string>-->
|
||||
<string name="grid_selector">Grid selector</string>
|
||||
<string-array name="array_time_picker_styles">
|
||||
<item>@string/number_pad</item>
|
||||
<item>@string/radial_clock</item>
|
||||
<!--<item>@string/radial_clock</item>-->
|
||||
<item>@string/grid_selector</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Silence after -->
|
||||
|
||||
@ -6,6 +6,9 @@
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<!-- TODO: This doesn't work for BottomSheetDialogs. Verify this works for other types of dialogs. -->
|
||||
<item name="dialogTheme">@style/AppCompatDialogTheme</item>
|
||||
<item name="bottomSheetDialogTheme">@style/BottomSheetDialogTheme</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||
@ -57,7 +60,11 @@
|
||||
</style>
|
||||
|
||||
<style name="Divider">
|
||||
<item name="android:background">?android:attr/listDivider</item>
|
||||
<!-- Won't be visible in a bottom sheet dialog... -->
|
||||
<!--<item name="android:background">?android:attr/listDivider</item>-->
|
||||
<!-- Extracted from the drawable pointed to by the attr. Visible in bottom sheet. -->
|
||||
<item name="android:background">#1f000000</item> <!-- 12% black -->
|
||||
<item name="android:tint">?android:attr/colorForeground</item>
|
||||
</style>
|
||||
|
||||
<style name="Divider.Horizontal">
|
||||
@ -78,4 +85,17 @@
|
||||
<item name="android:focusableInTouchMode">true</item>
|
||||
</style>
|
||||
|
||||
<!-- Style for AppCompatDialog from the v7 support library -->
|
||||
<style name="AppCompatDialogTheme" parent="Theme.AppCompat.Light.Dialog">
|
||||
<item name="colorAccent">?android:attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="BottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
|
||||
<item name="bottomSheetStyle">@style/ModalStyle</item>
|
||||
</style>
|
||||
|
||||
<style name="ModalStyle" parent="Widget.Design.BottomSheet.Modal">
|
||||
<item name="behavior_peekHeight">@dimen/peek_height_upper_limit</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user