|
|
|
@ -137,29 +137,29 @@ public class DateTimePicker extends FrameLayout {
|
|
|
|
|
private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
|
|
|
|
int minValue = mMinuteSpinner.getMinValue();
|
|
|
|
|
int maxValue = mMinuteSpinner.getMaxValue();
|
|
|
|
|
int offset = 0;
|
|
|
|
|
if (oldVal == maxValue && newVal == minValue) {
|
|
|
|
|
offset += 1;
|
|
|
|
|
} else if (oldVal == minValue && newVal == maxValue) {
|
|
|
|
|
offset -= 1;
|
|
|
|
|
int minValue = mMinuteSpinner.getMinValue(); // 获取分钟选择器的最小值
|
|
|
|
|
int maxValue = mMinuteSpinner.getMaxValue(); // 获取分钟选择器的最大值
|
|
|
|
|
int offset = 0; // 偏移量,用于处理分钟的循环
|
|
|
|
|
if (oldVal == maxValue && newVal == minValue) { // 判断是否从最大值切换到最小值
|
|
|
|
|
offset += 1; // 如果是,则偏移量加1
|
|
|
|
|
} else if (oldVal == minValue && newVal == maxValue) { // 判断是否从最小值切换到最大值
|
|
|
|
|
offset -= 1; // 如果是,则偏移量减1
|
|
|
|
|
}
|
|
|
|
|
if (offset != 0) {
|
|
|
|
|
mDate.add(Calendar.HOUR_OF_DAY, offset);
|
|
|
|
|
mHourSpinner.setValue(getCurrentHour());
|
|
|
|
|
updateDateControl();
|
|
|
|
|
int newHour = getCurrentHourOfDay();
|
|
|
|
|
if (newHour >= HOURS_IN_HALF_DAY) {
|
|
|
|
|
mIsAm = false;
|
|
|
|
|
updateAmPmControl();
|
|
|
|
|
if (offset != 0) { // 如果偏移量不为0,表示分钟发生了循环
|
|
|
|
|
mDate.add(Calendar.HOUR_OF_DAY, offset); // 更新小时的值
|
|
|
|
|
mHourSpinner.setValue(getCurrentHour()); // 更新小时选择器的值
|
|
|
|
|
updateDateControl(); // 更新日期选择器控件
|
|
|
|
|
int newHour = getCurrentHourOfDay(); // 获取当前小时
|
|
|
|
|
if (newHour >= HOURS_IN_HALF_DAY) { // 如果当前小时大于等于一半天的小时数
|
|
|
|
|
mIsAm = false; // 设置为下午
|
|
|
|
|
updateAmPmControl(); // 更新上午/下午选择器控件
|
|
|
|
|
} else {
|
|
|
|
|
mIsAm = true;
|
|
|
|
|
updateAmPmControl();
|
|
|
|
|
mIsAm = true; // 设置为上午
|
|
|
|
|
updateAmPmControl(); // 更新上午/下午选择器控件
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mDate.set(Calendar.MINUTE, newVal);
|
|
|
|
|
onDateTimeChanged();
|
|
|
|
|
mDate.set(Calendar.MINUTE, newVal); // 更新分钟的值
|
|
|
|
|
onDateTimeChanged(); // 触发日期时间变化监听器
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|