am 1c91433f: Merge "Set time dialog display changes AM/PM at 1 instead of 12" into honeycomb

* commit '1c91433f7c61860319fa5d524b503c2631a7f2d3':
  Set time dialog display changes AM/PM at 1 instead of 12
This commit is contained in:
Svetoslav Ganov
2011-01-31 16:15:26 -08:00
committed by Android Git Automerger

View File

@@ -132,12 +132,8 @@ public class TimePicker extends FrameLayout {
mHourSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { mHourSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
public void onValueChange(NumberPicker spinner, int oldVal, int newVal) { public void onValueChange(NumberPicker spinner, int oldVal, int newVal) {
if (!is24HourView()) { if (!is24HourView()) {
int minValue = mHourSpinner.getMinValue(); if ((oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY)
int maxValue = mHourSpinner.getMaxValue(); || (oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1)) {
// toggle AM/PM if the spinner has wrapped and not in 24
// format
if ((oldVal == maxValue && newVal == minValue)
|| (oldVal == minValue && newVal == maxValue)) {
mIsAm = !mIsAm; mIsAm = !mIsAm;
updateAmPmControl(); updateAmPmControl();
} }
@@ -163,21 +159,19 @@ public class TimePicker extends FrameLayout {
int minValue = mMinuteSpinner.getMinValue(); int minValue = mMinuteSpinner.getMinValue();
int maxValue = mMinuteSpinner.getMaxValue(); int maxValue = mMinuteSpinner.getMaxValue();
if (oldVal == maxValue && newVal == minValue) { if (oldVal == maxValue && newVal == minValue) {
int currentHour = mHourSpinner.getValue(); int newHour = mHourSpinner.getValue() + 1;
// toggle AM/PM if the spinner is about to wrap if (!is24HourView() && newHour == HOURS_IN_HALF_DAY) {
if (!is24HourView() && currentHour == mHourSpinner.getMaxValue()) {
mIsAm = !mIsAm; mIsAm = !mIsAm;
updateAmPmControl(); updateAmPmControl();
} }
mHourSpinner.setValue(currentHour + 1); mHourSpinner.setValue(newHour);
} else if (oldVal == minValue && newVal == maxValue) { } else if (oldVal == minValue && newVal == maxValue) {
int currentHour = mHourSpinner.getValue(); int newHour = mHourSpinner.getValue() - 1;
// toggle AM/PM if the spinner is about to wrap if (!is24HourView() && newHour == HOURS_IN_HALF_DAY - 1) {
if (!is24HourView() && currentHour == mHourSpinner.getMinValue()) {
mIsAm = !mIsAm; mIsAm = !mIsAm;
updateAmPmControl(); updateAmPmControl();
} }
mHourSpinner.setValue(currentHour - 1); mHourSpinner.setValue(newHour);
} }
onTimeChanged(); onTimeChanged();
} }
@@ -330,10 +324,12 @@ public class TimePicker extends FrameLayout {
*/ */
public Integer getCurrentHour() { public Integer getCurrentHour() {
int currentHour = mHourSpinner.getValue(); int currentHour = mHourSpinner.getValue();
if (is24HourView() || mIsAm) { if (is24HourView()) {
return currentHour; return currentHour;
} else if (mIsAm) {
return currentHour % HOURS_IN_HALF_DAY;
} else { } else {
return (currentHour == HOURS_IN_HALF_DAY) ? 0 : currentHour + HOURS_IN_HALF_DAY; return (currentHour % HOURS_IN_HALF_DAY) + HOURS_IN_HALF_DAY;
} }
} }
@@ -347,14 +343,16 @@ public class TimePicker extends FrameLayout {
} }
if (!is24HourView()) { if (!is24HourView()) {
// convert [0,23] ordinal to wall clock display // convert [0,23] ordinal to wall clock display
if (currentHour > HOURS_IN_HALF_DAY) { if (currentHour >= HOURS_IN_HALF_DAY) {
currentHour -= HOURS_IN_HALF_DAY;
mIsAm = false; mIsAm = false;
if (currentHour > HOURS_IN_HALF_DAY) {
currentHour = currentHour - HOURS_IN_HALF_DAY;
}
} else { } else {
mIsAm = true;
if (currentHour == 0) { if (currentHour == 0) {
currentHour = HOURS_IN_HALF_DAY; currentHour = HOURS_IN_HALF_DAY;
} }
mIsAm = true;
} }
updateAmPmControl(); updateAmPmControl();
} }