ampm instance state saved and restored
This commit is contained in:
parent
5188b7e128
commit
07277163ae
@ -44,10 +44,10 @@ public class NumpadTimePicker extends GridLayoutNumpad {
|
||||
private static final int BASE_10 = 10;
|
||||
|
||||
// AmPmStates
|
||||
private static final int UNSPECIFIED = -1;
|
||||
private static final int AM = 0;
|
||||
private static final int PM = 1;
|
||||
private static final int HRS_24 = 2;
|
||||
static final int UNSPECIFIED = -1;
|
||||
static final int AM = 0;
|
||||
static final int PM = 1;
|
||||
static final int HRS_24 = 2;
|
||||
|
||||
@IntDef({ UNSPECIFIED, AM, PM, HRS_24 }) // Specifies the accepted constants
|
||||
@Retention(RetentionPolicy.SOURCE) // Usages do not need to be recorded in .class files
|
||||
@ -309,6 +309,34 @@ public class NumpadTimePicker extends GridLayoutNumpad {
|
||||
return mFormattedInput.toString();
|
||||
}
|
||||
|
||||
@AmPmState
|
||||
int getAmPmState() {
|
||||
return mAmPmState;
|
||||
}
|
||||
|
||||
// Because the annotation and its associated enum constants are marked private, the only real
|
||||
// use for this method is to restore state across rotation after saving the value from
|
||||
// #getAmPmState(). We can't directly pass in one of those accepted constants.
|
||||
void setAmPmState(@AmPmState int amPmState) {
|
||||
// mAmPmState = amPmState;
|
||||
switch (amPmState) {
|
||||
case AM:
|
||||
case PM:
|
||||
// mAmPmState is set for us
|
||||
onAltButtonClick(mAltButtons[amPmState]);
|
||||
break;
|
||||
case HRS_24:
|
||||
// Restoring the digits, if they make a valid time, should have already
|
||||
// restored the mAmPmState to this value for us. If they don't make a
|
||||
// valid time, then we refrain from setting it.
|
||||
break;
|
||||
case UNSPECIFIED:
|
||||
// We should already be set to this value initially, but it can't hurt?
|
||||
mAmPmState = amPmState;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mFabDisabledColorDark = ContextCompat.getColor(getContext(), R.color.fab_disabled_dark);
|
||||
mFabDisabledColorLight = ContextCompat.getColor(getContext(), R.color.fab_disabled_light);
|
||||
|
||||
@ -21,14 +21,12 @@ 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";
|
||||
private static final String KEY_IS_24_HOUR_VIEW = "is_24_hour_view";
|
||||
private static final String KEY_DIGITS_INPUTTED = "digits_inputted";
|
||||
private static final String KEY_AMPM_STATE = "ampm_state";
|
||||
private static final String KEY_THEME_DARK = "theme_dark";
|
||||
|
||||
private int mInitialHourOfDay;
|
||||
private int mInitialMinute;
|
||||
private boolean mIs24HourMode;
|
||||
private boolean mIs24HourMode; // TODO: Why do we need this?
|
||||
/**
|
||||
* The digits stored in the numpad from the last time onSaveInstanceState() was called.
|
||||
*
|
||||
@ -38,6 +36,7 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
|
||||
* depends on the dialog to save its state.
|
||||
*/
|
||||
private int[] mInputtedDigits;
|
||||
private int mAmPmState = NumpadTimePicker.UNSPECIFIED; // TOneverDO: zero initial value, b/c 0 == AM
|
||||
private boolean mThemeDark;
|
||||
|
||||
// Don't need to keep a reference to the dismiss ImageButton
|
||||
@ -67,8 +66,6 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
|
||||
public void initialize(OnTimeSetListener callback,
|
||||
int hourOfDay, int minute, boolean is24HourMode) {
|
||||
mCallback = callback;
|
||||
mInitialHourOfDay = hourOfDay;
|
||||
mInitialMinute = minute;
|
||||
mIs24HourMode = is24HourMode;
|
||||
}
|
||||
|
||||
@ -89,6 +86,8 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
|
||||
if (savedInstanceState != null) {
|
||||
mInputtedDigits = savedInstanceState.getIntArray(KEY_DIGITS_INPUTTED);
|
||||
mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
|
||||
mAmPmState = savedInstanceState.getInt(KEY_AMPM_STATE);
|
||||
mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK);
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,6 +97,7 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
mNumpad.setOnInputChangeListener(this);
|
||||
mNumpad.insertDigits(mInputtedDigits); // TOneverDO: before mNumpad.setOnInputChangeListener(this);
|
||||
mNumpad.setAmPmState(mAmPmState);
|
||||
// Show the cursor immediately
|
||||
// mInputField.requestFocus();
|
||||
//updateInputText(""); // Primarily to disable 'OK'
|
||||
@ -131,7 +131,8 @@ public class NumpadTimePickerDialog extends BaseTimePickerDialog
|
||||
if (mNumpad != null) {
|
||||
outState.putIntArray(KEY_DIGITS_INPUTTED, mNumpad.getDigits());
|
||||
outState.putBoolean(KEY_IS_24_HOUR_VIEW, mIs24HourMode);
|
||||
//outState.putBoolean(KEY_DARK_THEME, mThemeDark);
|
||||
outState.putInt(KEY_AMPM_STATE, mNumpad.getAmPmState());
|
||||
outState.putBoolean(KEY_THEME_DARK, mThemeDark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user