|
|
|
@ -14,100 +14,118 @@
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import java.text.DateFormatSymbols;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
package net.micode.notes.ui; // 定义包名
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
|
import java.text.DateFormatSymbols; // 导入日期格式符号类
|
|
|
|
|
import java.util.Calendar; // 导入日历类
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R; // 导入资源类
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.text.format.DateFormat;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
import android.widget.NumberPicker;
|
|
|
|
|
import android.content.Context; // 导入上下文类
|
|
|
|
|
import android.text.format.DateFormat; // 导入日期格式类
|
|
|
|
|
import android.view.View; // 导入视图类
|
|
|
|
|
import android.widget.FrameLayout; // 导入框架布局类
|
|
|
|
|
import android.widget.NumberPicker; // 导入数字选择器类
|
|
|
|
|
|
|
|
|
|
public class DateTimePicker extends FrameLayout {
|
|
|
|
|
public class DateTimePicker extends FrameLayout { // 定义日期时间选择器类,继承自 FrameLayout
|
|
|
|
|
|
|
|
|
|
private static final boolean DEFAULT_ENABLE_STATE = true;
|
|
|
|
|
private static final boolean DEFAULT_ENABLE_STATE = true; // 默认启用状态为 true
|
|
|
|
|
|
|
|
|
|
private static final int HOURS_IN_HALF_DAY = 12;
|
|
|
|
|
private static final int HOURS_IN_ALL_DAY = 24;
|
|
|
|
|
private static final int DAYS_IN_ALL_WEEK = 7;
|
|
|
|
|
private static final int DATE_SPINNER_MIN_VAL = 0;
|
|
|
|
|
private static final int DATE_SPINNER_MAX_VAL = DAYS_IN_ALL_WEEK - 1;
|
|
|
|
|
private static final int HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW = 0;
|
|
|
|
|
private static final int HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW = 23;
|
|
|
|
|
private static final int HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW = 1;
|
|
|
|
|
private static final int HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW = 12;
|
|
|
|
|
private static final int MINUT_SPINNER_MIN_VAL = 0;
|
|
|
|
|
private static final int MINUT_SPINNER_MAX_VAL = 59;
|
|
|
|
|
private static final int AMPM_SPINNER_MIN_VAL = 0;
|
|
|
|
|
private static final int AMPM_SPINNER_MAX_VAL = 1;
|
|
|
|
|
private static final int HOURS_IN_HALF_DAY = 12; // 半天的小时数
|
|
|
|
|
private static final int HOURS_IN_ALL_DAY = 24; // 全天的小时数
|
|
|
|
|
private static final int DAYS_IN_ALL_WEEK = 7; // 一周的天数
|
|
|
|
|
private static final int DATE_SPINNER_MIN_VAL = 0; // 日期选择器的最小值
|
|
|
|
|
private static final int DATE_SPINNER_MAX_VAL = DAYS_IN_ALL_WEEK - 1; // 日期选择器的最大值
|
|
|
|
|
private static final int HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW = 0; // 24小时制下小时选择器的最小值
|
|
|
|
|
private static final int HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW = 23; // 24小时制下小时选择器的最大值
|
|
|
|
|
private static final int HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW = 1; // 12小时制下小时选择器的最小值
|
|
|
|
|
private static final int HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW = 12; // 12小时制下小时选择器的最大值
|
|
|
|
|
private static final int MINUT_SPINNER_MIN_VAL = 0; // 分钟选择器的最小值
|
|
|
|
|
private static final int MINUT_SPINNER_MAX_VAL = 59; // 分钟选择器的最大值
|
|
|
|
|
private static final int AMPM_SPINNER_MIN_VAL = 0; // AM/PM选择器的最小值
|
|
|
|
|
private static final int AMPM_SPINNER_MAX_VAL = 1; // AM/PM选择器的最大值
|
|
|
|
|
|
|
|
|
|
private final NumberPicker mDateSpinner;
|
|
|
|
|
private final NumberPicker mHourSpinner;
|
|
|
|
|
private final NumberPicker mMinuteSpinner;
|
|
|
|
|
private final NumberPicker mAmPmSpinner;
|
|
|
|
|
private Calendar mDate;
|
|
|
|
|
private final NumberPicker mDateSpinner; // 日期选择器
|
|
|
|
|
private final NumberPicker mHourSpinner; // 小时选择器
|
|
|
|
|
private final NumberPicker mMinuteSpinner; // 分钟选择器
|
|
|
|
|
private final NumberPicker mAmPmSpinner; // AM/PM选择器
|
|
|
|
|
private Calendar mDate; // 存储日期的日历对象
|
|
|
|
|
|
|
|
|
|
private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK];
|
|
|
|
|
private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK]; // 用于存储日期显示值的数组
|
|
|
|
|
|
|
|
|
|
private boolean mIsAm;
|
|
|
|
|
private boolean mIsAm; // 存储当前是否为 AM 的标志
|
|
|
|
|
|
|
|
|
|
private boolean mIs24HourView;
|
|
|
|
|
private boolean mIs24HourView; // 存储当前是否为24小时制的标志
|
|
|
|
|
|
|
|
|
|
private boolean mIsEnabled = DEFAULT_ENABLE_STATE;
|
|
|
|
|
private boolean mIsEnabled = DEFAULT_ENABLE_STATE; // 存储当前启用状态
|
|
|
|
|
|
|
|
|
|
private boolean mInitialising;
|
|
|
|
|
private boolean mInitialising; // 存储初始化状态的标志
|
|
|
|
|
|
|
|
|
|
private OnDateTimeChangedListener mOnDateTimeChangedListener;
|
|
|
|
|
private OnDateTimeChangedListener mOnDateTimeChangedListener; // 日期时间改变的监听器
|
|
|
|
|
|
|
|
|
|
// 日期选择器值变化的监听器
|
|
|
|
|
private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
|
|
|
|
mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal);
|
|
|
|
|
updateDateControl();
|
|
|
|
|
onDateTimeChanged();
|
|
|
|
|
mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal); // 更新日期
|
|
|
|
|
updateDateControl(); // 更新日期控制
|
|
|
|
|
onDateTimeChanged(); // 通知日期时间已更改
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 小时选择器值变化的监听器
|
|
|
|
|
private NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
|
|
|
|
boolean isDateChanged = false;
|
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
|
if (!mIs24HourView) {
|
|
|
|
|
if (!mIsAm && oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) {
|
|
|
|
|
boolean isDateChanged = false; // 标记日期是否变化
|
|
|
|
|
Calendar cal = Calendar.getInstance(); // 获取当前日期的日历对象
|
|
|
|
|
if (!mIs24HourView) { // 如果是 12 小时制
|
|
|
|
|
if (!mIsAm && oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) { // 从 PM 切换到 AM
|
|
|
|
|
cal.setTimeInMillis(mDate.getTimeInMillis());
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
|
isDateChanged = true;
|
|
|
|
|
} else if (mIsAm && oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, 1); // 日期加 1
|
|
|
|
|
isDateChanged = true; // 标记日期变化
|
|
|
|
|
} else if (mIsAm && oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) { // 从 AM 切换到 PM
|
|
|
|
|
cal.setTimeInMillis(mDate.getTimeInMillis());
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, -1);
|
|
|
|
|
isDateChanged = true;
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, -1); // 日期减 1
|
|
|
|
|
isDateChanged = true; // 标记日期变化
|
|
|
|
|
}
|
|
|
|
|
if (oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY ||
|
|
|
|
|
oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
|
|
|
|
|
mIsAm = !mIsAm;
|
|
|
|
|
updateAmPmControl();
|
|
|
|
|
mIsAm = !mIsAm; // 切换 AM/PM 状态
|
|
|
|
|
updateAmPmControl(); // 更新 AM/PM 控制
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (oldVal == HOURS_IN_ALL_DAY - 1 && newVal == 0) {
|
|
|
|
|
} else { // 如果是 24 小时制
|
|
|
|
|
if (oldVal == HOURS_IN_ALL_DAY - 1 && newVal == 0) { // 从 23 切换到 0
|
|
|
|
|
cal.setTimeInMillis(mDate.getTimeInMillis());
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
|
isDateChanged = true;
|
|
|
|
|
} else if (oldVal == 0 && newVal == HOURS_IN_ALL_DAY - 1) {
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, 1); // 日期加 1
|
|
|
|
|
isDateChanged = true; // 标记日期变化
|
|
|
|
|
} else if (oldVal == 0 && newVal == HOURS_IN_ALL_DAY - 1) { // 从 0 切换到 23
|
|
|
|
|
cal.setTimeInMillis(mDate.getTimeInMillis());
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, -1);
|
|
|
|
|
isDateChanged = true;
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, -1); // 日期减 1
|
|
|
|
|
isDateChanged = true; // 标记日期变化
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 设置小时
|
|
|
|
|
int newHour = mHourSpinner.getValue() % HOURS_IN_HALF_DAY + (mIsAm ? 0 : HOURS_IN_HALF_DAY);
|
|
|
|
|
mDate.set(Calendar.HOUR_OF_DAY, newHour);
|
|
|
|
|
onDateTimeChanged();
|
|
|
|
|
if (isDateChanged) {
|
|
|
|
|
mDate.set(Calendar.HOUR_OF_DAY, newHour); // 更新日历中的小时
|
|
|
|
|
onDateTimeChanged(); // 通知日期时间已更改
|
|
|
|
|
if (isDateChanged) { // 如果日期变化,则更新日期
|
|
|
|
|
setCurrentYear(cal.get(Calendar.YEAR));
|
|
|
|
|
setCurrentMonth(cal.get(Calendar.MONTH));
|
|
|
|
|
setCurrentDay(cal.get(Calendar.DAY_OF_MONTH));
|
|
|
|
@ -115,370 +133,387 @@ 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;
|
|
|
|
|
int minValue = mMinuteSpinner.getMinValue(); // 获取分钟选择器的最小值
|
|
|
|
|
int maxValue = mMinuteSpinner.getMaxValue(); // 获取分钟选择器的最大值
|
|
|
|
|
int offset = 0; // 记录偏移量
|
|
|
|
|
if (oldVal == maxValue && newVal == minValue) {
|
|
|
|
|
offset += 1;
|
|
|
|
|
offset += 1; // 增加偏移量
|
|
|
|
|
} else if (oldVal == minValue && newVal == maxValue) {
|
|
|
|
|
offset -= 1;
|
|
|
|
|
offset -= 1; // 减少偏移量
|
|
|
|
|
}
|
|
|
|
|
if (offset != 0) {
|
|
|
|
|
mDate.add(Calendar.HOUR_OF_DAY, offset);
|
|
|
|
|
mHourSpinner.setValue(getCurrentHour());
|
|
|
|
|
updateDateControl();
|
|
|
|
|
int newHour = getCurrentHourOfDay();
|
|
|
|
|
if (offset != 0) { // 如果偏移量不为零
|
|
|
|
|
mDate.add(Calendar.HOUR_OF_DAY, offset); // 更新小时
|
|
|
|
|
mHourSpinner.setValue(getCurrentHour()); // 更新小时选择器的值
|
|
|
|
|
updateDateControl(); // 更新日期控制
|
|
|
|
|
int newHour = getCurrentHourOfDay(); // 获取当前小时
|
|
|
|
|
// 更新 AM/PM 状态
|
|
|
|
|
if (newHour >= HOURS_IN_HALF_DAY) {
|
|
|
|
|
mIsAm = false;
|
|
|
|
|
updateAmPmControl();
|
|
|
|
|
mIsAm = false; // 设为 PM
|
|
|
|
|
updateAmPmControl(); // 更新 AM/PM 控制
|
|
|
|
|
} else {
|
|
|
|
|
mIsAm = true;
|
|
|
|
|
updateAmPmControl();
|
|
|
|
|
mIsAm = true; // 设为 AM
|
|
|
|
|
updateAmPmControl(); // 更新 AM/PM 控制
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mDate.set(Calendar.MINUTE, newVal);
|
|
|
|
|
onDateTimeChanged();
|
|
|
|
|
mDate.set(Calendar.MINUTE, newVal); // 更新日历中的分钟
|
|
|
|
|
onDateTimeChanged(); // 通知日期时间已更改
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// AM/PM 选择器值变化的监听器
|
|
|
|
|
private NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
|
|
|
|
mIsAm = !mIsAm;
|
|
|
|
|
mIsAm = !mIsAm; // 切换 AM/PM 状态
|
|
|
|
|
// 根据 AM/PM 状态更新小时
|
|
|
|
|
if (mIsAm) {
|
|
|
|
|
mDate.add(Calendar.HOUR_OF_DAY, -HOURS_IN_HALF_DAY);
|
|
|
|
|
mDate.add(Calendar.HOUR_OF_DAY, -HOURS_IN_HALF_DAY); // 如果为 AM,减去 12 小时
|
|
|
|
|
} else {
|
|
|
|
|
mDate.add(Calendar.HOUR_OF_DAY, HOURS_IN_HALF_DAY);
|
|
|
|
|
mDate.add(Calendar.HOUR_OF_DAY, HOURS_IN_HALF_DAY); // 如果为 PM,加上 12 小时
|
|
|
|
|
}
|
|
|
|
|
updateAmPmControl();
|
|
|
|
|
onDateTimeChanged();
|
|
|
|
|
updateAmPmControl(); // 更新 AM/PM 控制
|
|
|
|
|
onDateTimeChanged(); // 通知日期时间已更改
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 定义日期时间改变的监听器接口
|
|
|
|
|
public interface OnDateTimeChangedListener {
|
|
|
|
|
void onDateTimeChanged(DateTimePicker view, int year, int month,
|
|
|
|
|
int dayOfMonth, int hourOfDay, int minute);
|
|
|
|
|
int dayOfMonth, int hourOfDay, int minute); // 方法签名
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构造函数,使用当前时间作为参数
|
|
|
|
|
public DateTimePicker(Context context) {
|
|
|
|
|
this(context, System.currentTimeMillis());
|
|
|
|
|
this(context, System.currentTimeMillis()); // 调用重载构造函数
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTimePicker(Context context, long date) {
|
|
|
|
|
this(context, date, DateFormat.is24HourFormat(context));
|
|
|
|
|
this(context, date, DateFormat.is24HourFormat(context)); // 调用重载构造函数,并根据上下文判断是否为 24 小时制
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DateTimePicker(Context context, long date, boolean is24HourView) {
|
|
|
|
|
super(context);
|
|
|
|
|
mDate = Calendar.getInstance();
|
|
|
|
|
mInitialising = true;
|
|
|
|
|
mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY;
|
|
|
|
|
inflate(context, R.layout.datetime_picker, this);
|
|
|
|
|
super(context); // 调用父类构造函数
|
|
|
|
|
mDate = Calendar.getInstance(); // 初始化当前日期
|
|
|
|
|
mInitialising = true; // 标记当前处于初始化状态
|
|
|
|
|
mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY; // 根据当前小时判断是否为 AM
|
|
|
|
|
inflate(context, R.layout.datetime_picker, this); // 加载布局文件
|
|
|
|
|
|
|
|
|
|
// 初始化日期选择器
|
|
|
|
|
mDateSpinner = (NumberPicker) findViewById(R.id.date);
|
|
|
|
|
mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL);
|
|
|
|
|
mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL);
|
|
|
|
|
mDateSpinner.setOnValueChangedListener(mOnDateChangedListener);
|
|
|
|
|
mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL); // 设置最小值
|
|
|
|
|
mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL); // 设置最大值
|
|
|
|
|
mDateSpinner.setOnValueChangedListener(mOnDateChangedListener); // 设置值变化监听器
|
|
|
|
|
|
|
|
|
|
// 初始化小时选择器
|
|
|
|
|
mHourSpinner = (NumberPicker) findViewById(R.id.hour);
|
|
|
|
|
mHourSpinner.setOnValueChangedListener(mOnHourChangedListener);
|
|
|
|
|
mHourSpinner.setOnValueChangedListener(mOnHourChangedListener); // 设置值变化监听器
|
|
|
|
|
|
|
|
|
|
// 初始化分钟选择器
|
|
|
|
|
mMinuteSpinner = (NumberPicker) findViewById(R.id.minute);
|
|
|
|
|
mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL);
|
|
|
|
|
mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL);
|
|
|
|
|
mMinuteSpinner.setOnLongPressUpdateInterval(100);
|
|
|
|
|
mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener);
|
|
|
|
|
mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL); // 设置最小值
|
|
|
|
|
mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL); // 设置最大值
|
|
|
|
|
mMinuteSpinner.setOnLongPressUpdateInterval(100); // 设置长按更新间隔
|
|
|
|
|
mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener); // 设置值变化监听器
|
|
|
|
|
|
|
|
|
|
String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings();
|
|
|
|
|
// 初始化 AM/PM 选择器
|
|
|
|
|
String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings(); // 获取 AM/PM 字符串
|
|
|
|
|
mAmPmSpinner = (NumberPicker) findViewById(R.id.amPm);
|
|
|
|
|
mAmPmSpinner.setMinValue(AMPM_SPINNER_MIN_VAL);
|
|
|
|
|
mAmPmSpinner.setMaxValue(AMPM_SPINNER_MAX_VAL);
|
|
|
|
|
mAmPmSpinner.setDisplayedValues(stringsForAmPm);
|
|
|
|
|
mAmPmSpinner.setOnValueChangedListener(mOnAmPmChangedListener);
|
|
|
|
|
mAmPmSpinner.setMinValue(AMPM_SPINNER_MIN_VAL); // 设置最小值
|
|
|
|
|
mAmPmSpinner.setMaxValue(AMPM_SPINNER_MAX_VAL); // 设置最大值
|
|
|
|
|
mAmPmSpinner.setDisplayedValues(stringsForAmPm); // 设置显示值
|
|
|
|
|
mAmPmSpinner.setOnValueChangedListener(mOnAmPmChangedListener); // 设置值变化监听器
|
|
|
|
|
|
|
|
|
|
// update controls to initial state
|
|
|
|
|
updateDateControl();
|
|
|
|
|
updateHourControl();
|
|
|
|
|
updateAmPmControl();
|
|
|
|
|
// 更新控件到初始状态
|
|
|
|
|
updateDateControl(); // 更新日期选择器状态
|
|
|
|
|
updateHourControl(); // 更新小时选择器状态
|
|
|
|
|
updateAmPmControl(); // 更新 AM/PM 选择器状态
|
|
|
|
|
|
|
|
|
|
set24HourView(is24HourView);
|
|
|
|
|
set24HourView(is24HourView); // 设置是否使用 24 小时制
|
|
|
|
|
|
|
|
|
|
// set to current time
|
|
|
|
|
setCurrentDate(date);
|
|
|
|
|
// 设置为当前时间
|
|
|
|
|
setCurrentDate(date); // 设置当前日期为传入的日期
|
|
|
|
|
|
|
|
|
|
setEnabled(isEnabled());
|
|
|
|
|
setEnabled(isEnabled()); // 设置选择器的启用状态
|
|
|
|
|
|
|
|
|
|
// set the content descriptions
|
|
|
|
|
mInitialising = false;
|
|
|
|
|
// 设置内容描述
|
|
|
|
|
mInitialising = false; // 标记初始化完成
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setEnabled(boolean enabled) {
|
|
|
|
|
if (mIsEnabled == enabled) {
|
|
|
|
|
public void setEnabled(boolean enabled) { // 重写设置启用状态的方法
|
|
|
|
|
if (mIsEnabled == enabled) { // 如果当前状态与目标状态相同,则返回
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
super.setEnabled(enabled);
|
|
|
|
|
super.setEnabled(enabled); // 调用父类的设置启用方法
|
|
|
|
|
// 设置各个选择器的启用状态
|
|
|
|
|
mDateSpinner.setEnabled(enabled);
|
|
|
|
|
mMinuteSpinner.setEnabled(enabled);
|
|
|
|
|
mHourSpinner.setEnabled(enabled);
|
|
|
|
|
mAmPmSpinner.setEnabled(enabled);
|
|
|
|
|
mIsEnabled = enabled;
|
|
|
|
|
mIsEnabled = enabled; // 更新当前启用状态
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isEnabled() {
|
|
|
|
|
return mIsEnabled;
|
|
|
|
|
public boolean isEnabled() { // 重写获取启用状态的方法
|
|
|
|
|
return mIsEnabled; // 返回当前启用状态
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current date in millis
|
|
|
|
|
* 获取当前日期的毫秒值
|
|
|
|
|
*
|
|
|
|
|
* @return the current date in millis
|
|
|
|
|
* @return 当前日期的毫秒值
|
|
|
|
|
*/
|
|
|
|
|
public long getCurrentDateInTimeMillis() {
|
|
|
|
|
return mDate.getTimeInMillis();
|
|
|
|
|
return mDate.getTimeInMillis(); // 返回当前日期的毫秒表示
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the current date
|
|
|
|
|
* 设置当前日期
|
|
|
|
|
*
|
|
|
|
|
* @param date The current date in millis
|
|
|
|
|
* @param date 当前日期的毫秒值
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentDate(long date) {
|
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
|
cal.setTimeInMillis(date);
|
|
|
|
|
Calendar cal = Calendar.getInstance(); // 获取当前日期的日历对象
|
|
|
|
|
cal.setTimeInMillis(date); // 将毫秒值设置到日历中
|
|
|
|
|
// 设置当前日期的年、月、日、小时和分钟
|
|
|
|
|
setCurrentDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH),
|
|
|
|
|
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the current date
|
|
|
|
|
* 设置当前日期
|
|
|
|
|
*
|
|
|
|
|
* @param year The current year
|
|
|
|
|
* @param month The current month
|
|
|
|
|
* @param dayOfMonth The current dayOfMonth
|
|
|
|
|
* @param hourOfDay The current hourOfDay
|
|
|
|
|
* @param minute The current minute
|
|
|
|
|
* @param year 当前年份
|
|
|
|
|
* @param month 当前月份
|
|
|
|
|
* @param dayOfMonth 当前日
|
|
|
|
|
* @param hourOfDay 当前小时
|
|
|
|
|
* @param minute 当前分钟
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentDate(int year, int month,
|
|
|
|
|
int dayOfMonth, int hourOfDay, int minute) {
|
|
|
|
|
setCurrentYear(year);
|
|
|
|
|
setCurrentMonth(month);
|
|
|
|
|
setCurrentDay(dayOfMonth);
|
|
|
|
|
setCurrentHour(hourOfDay);
|
|
|
|
|
setCurrentMinute(minute);
|
|
|
|
|
setCurrentYear(year); // 设置当前年份
|
|
|
|
|
setCurrentMonth(month); // 设置当前月份
|
|
|
|
|
setCurrentDay(dayOfMonth); // 设置当前日期
|
|
|
|
|
setCurrentHour(hourOfDay); // 设置当前小时
|
|
|
|
|
setCurrentMinute(minute); // 设置当前分钟
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get current year
|
|
|
|
|
* 获取当前年份
|
|
|
|
|
*
|
|
|
|
|
* @return The current year
|
|
|
|
|
* @return 当前年份
|
|
|
|
|
*/
|
|
|
|
|
public int getCurrentYear() {
|
|
|
|
|
return mDate.get(Calendar.YEAR);
|
|
|
|
|
return mDate.get(Calendar.YEAR); // 返回当前年份
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set current year
|
|
|
|
|
* 设置当前年份
|
|
|
|
|
*
|
|
|
|
|
* @param year The current year
|
|
|
|
|
* @param year 当前年份
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentYear(int year) {
|
|
|
|
|
if (!mInitialising && year == getCurrentYear()) {
|
|
|
|
|
if (!mInitialising && year == getCurrentYear()) { // 如果不在初始化并且当前年份未变化,则返回
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mDate.set(Calendar.YEAR, year);
|
|
|
|
|
updateDateControl();
|
|
|
|
|
onDateTimeChanged();
|
|
|
|
|
mDate.set(Calendar.YEAR, year); // 更新日历中的年份
|
|
|
|
|
updateDateControl(); // 更新日期选择器控制
|
|
|
|
|
onDateTimeChanged(); // 通知日期时间已更改
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get current month in the year
|
|
|
|
|
* 获取当前月份
|
|
|
|
|
*
|
|
|
|
|
* @return The current month in the year
|
|
|
|
|
* @return 当前月份
|
|
|
|
|
*/
|
|
|
|
|
public int getCurrentMonth() {
|
|
|
|
|
return mDate.get(Calendar.MONTH);
|
|
|
|
|
return mDate.get(Calendar.MONTH); // 返回当前月份
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set current month in the year
|
|
|
|
|
* 设置当前月份
|
|
|
|
|
*
|
|
|
|
|
* @param month The month in the year
|
|
|
|
|
* @param month 当前月份
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentMonth(int month) {
|
|
|
|
|
if (!mInitialising && month == getCurrentMonth()) {
|
|
|
|
|
if (!mInitialising && month == getCurrentMonth()) { // 如果不在初始化且当前月份未变化,则返回
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mDate.set(Calendar.MONTH, month);
|
|
|
|
|
updateDateControl();
|
|
|
|
|
onDateTimeChanged();
|
|
|
|
|
mDate.set(Calendar.MONTH, month); // 更新日历中的月份
|
|
|
|
|
updateDateControl(); // 更新日期控制
|
|
|
|
|
onDateTimeChanged(); // 通知日期时间已更改
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get current day of the month
|
|
|
|
|
* 获取当前日期
|
|
|
|
|
*
|
|
|
|
|
* @return The day of the month
|
|
|
|
|
* @return 当前日期
|
|
|
|
|
*/
|
|
|
|
|
public int getCurrentDay() {
|
|
|
|
|
return mDate.get(Calendar.DAY_OF_MONTH);
|
|
|
|
|
return mDate.get(Calendar.DAY_OF_MONTH); // 返回当前日期
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set current day of the month
|
|
|
|
|
* 设置当前日期
|
|
|
|
|
*
|
|
|
|
|
* @param dayOfMonth The day of the month
|
|
|
|
|
* @param dayOfMonth 当前日期
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentDay(int dayOfMonth) {
|
|
|
|
|
if (!mInitialising && dayOfMonth == getCurrentDay()) {
|
|
|
|
|
if (!mInitialising && dayOfMonth == getCurrentDay()) { // 如果不在初始化且当前日期未变化,则返回
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
|
|
|
|
updateDateControl();
|
|
|
|
|
onDateTimeChanged();
|
|
|
|
|
mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); // 更新日历中的日期
|
|
|
|
|
updateDateControl(); // 更新日期控制
|
|
|
|
|
onDateTimeChanged(); // 通知日期时间已更改
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get current hour in 24 hour mode, in the range (0~23)
|
|
|
|
|
* @return The current hour in 24 hour mode
|
|
|
|
|
* 获取当前小时
|
|
|
|
|
*
|
|
|
|
|
* @return 以 24 小时制表示的当前小时
|
|
|
|
|
*/
|
|
|
|
|
public int getCurrentHourOfDay() {
|
|
|
|
|
return mDate.get(Calendar.HOUR_OF_DAY);
|
|
|
|
|
return mDate.get(Calendar.HOUR_OF_DAY); // 返回当前 24 小时制的小时
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getCurrentHour() {
|
|
|
|
|
if (mIs24HourView){
|
|
|
|
|
return getCurrentHourOfDay();
|
|
|
|
|
private int getCurrentHour() { // 获取当前小时
|
|
|
|
|
if (mIs24HourView){ // 如果是 24 小时制
|
|
|
|
|
return getCurrentHourOfDay(); // 返回 24 小时制的当前小时
|
|
|
|
|
} else {
|
|
|
|
|
int hour = getCurrentHourOfDay();
|
|
|
|
|
int hour = getCurrentHourOfDay(); // 获取当前小时
|
|
|
|
|
// 转换为 12 小时制
|
|
|
|
|
if (hour > HOURS_IN_HALF_DAY) {
|
|
|
|
|
return hour - HOURS_IN_HALF_DAY;
|
|
|
|
|
} else {
|
|
|
|
|
return hour == 0 ? HOURS_IN_HALF_DAY : hour;
|
|
|
|
|
return hour == 0 ? HOURS_IN_HALF_DAY : hour; // 处理 0 点的情况
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set current hour in 24 hour mode, in the range (0~23)
|
|
|
|
|
* 设置当前小时
|
|
|
|
|
*
|
|
|
|
|
* @param hourOfDay
|
|
|
|
|
* @param hourOfDay 当前小时
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentHour(int hourOfDay) {
|
|
|
|
|
if (!mInitialising && hourOfDay == getCurrentHourOfDay()) {
|
|
|
|
|
if (!mInitialising && hourOfDay == getCurrentHourOfDay()) { // 如果不在初始化且当前小时未变化,则返回
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
|
|
|
|
if (!mIs24HourView) {
|
|
|
|
|
if (hourOfDay >= HOURS_IN_HALF_DAY) {
|
|
|
|
|
mIsAm = false;
|
|
|
|
|
if (hourOfDay > HOURS_IN_HALF_DAY) {
|
|
|
|
|
hourOfDay -= HOURS_IN_HALF_DAY;
|
|
|
|
|
mDate.set(Calendar.HOUR_OF_DAY, hourOfDay); // 更新日历中的小时
|
|
|
|
|
if (!mIs24HourView) { // 如果不是 24 小时制
|
|
|
|
|
if (hourOfDay >= HOURS_IN_HALF_DAY) { // 如果属于 PM
|
|
|
|
|
mIsAm = false; // 设置为 PM
|
|
|
|
|
if (hourOfDay > HOURS_IN_HALF_DAY) { // 如果小时大于 12
|
|
|
|
|
hourOfDay -= HOURS_IN_HALF_DAY; // 转换为 12 小时制
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mIsAm = true;
|
|
|
|
|
if (hourOfDay == 0) {
|
|
|
|
|
hourOfDay = HOURS_IN_HALF_DAY;
|
|
|
|
|
} else { // 如果属于 AM
|
|
|
|
|
mIsAm = true; // 设置为 AM
|
|
|
|
|
if (hourOfDay == 0) { // 如果是 0 点
|
|
|
|
|
hourOfDay = HOURS_IN_HALF_DAY; // 转换为 12 点
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateAmPmControl();
|
|
|
|
|
updateAmPmControl(); // 更新 AM/PM 控制
|
|
|
|
|
}
|
|
|
|
|
mHourSpinner.setValue(hourOfDay);
|
|
|
|
|
onDateTimeChanged();
|
|
|
|
|
mHourSpinner.setValue(hourOfDay); // 更新小时选择器的值
|
|
|
|
|
onDateTimeChanged(); // 通知日期时间已更改
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get currentMinute
|
|
|
|
|
* 获取当前分钟
|
|
|
|
|
*
|
|
|
|
|
* @return The Current Minute
|
|
|
|
|
* @return 当前分钟
|
|
|
|
|
*/
|
|
|
|
|
public int getCurrentMinute() {
|
|
|
|
|
return mDate.get(Calendar.MINUTE);
|
|
|
|
|
return mDate.get(Calendar.MINUTE); // 返回当前分钟
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set current minute
|
|
|
|
|
* 设置当前分钟
|
|
|
|
|
*
|
|
|
|
|
* @param minute 当前分钟
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentMinute(int minute) {
|
|
|
|
|
if (!mInitialising && minute == getCurrentMinute()) {
|
|
|
|
|
if (!mInitialising && minute == getCurrentMinute()) { // 如果不在初始化且当前分钟未变化,则返回
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mMinuteSpinner.setValue(minute);
|
|
|
|
|
mDate.set(Calendar.MINUTE, minute);
|
|
|
|
|
onDateTimeChanged();
|
|
|
|
|
mMinuteSpinner.setValue(minute); // 更新分钟选择器的值
|
|
|
|
|
mDate.set(Calendar.MINUTE, minute); // 更新日历中的分钟
|
|
|
|
|
onDateTimeChanged(); // 通知日期时间已更改
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return true if this is in 24 hour view else false.
|
|
|
|
|
* @return 如果在 24 小时制下返回 true,否则返回 false。
|
|
|
|
|
*/
|
|
|
|
|
public boolean is24HourView () {
|
|
|
|
|
return mIs24HourView;
|
|
|
|
|
return mIs24HourView; // 返回当前是否在 24 小时制
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set whether in 24 hour or AM/PM mode.
|
|
|
|
|
* 设置是否使用 24 小时制或 AM/PM 模式。
|
|
|
|
|
*
|
|
|
|
|
* @param is24HourView True for 24 hour mode. False for AM/PM mode.
|
|
|
|
|
* @param is24HourView true 为 24 小时制,false 为 AM/PM 模式。
|
|
|
|
|
*/
|
|
|
|
|
public void set24HourView(boolean is24HourView) {
|
|
|
|
|
if (mIs24HourView == is24HourView) {
|
|
|
|
|
if (mIs24HourView == is24HourView) { // 如果当前状态与目标状态相同则返回
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mIs24HourView = is24HourView;
|
|
|
|
|
mAmPmSpinner.setVisibility(is24HourView ? View.GONE : View.VISIBLE);
|
|
|
|
|
int hour = getCurrentHourOfDay();
|
|
|
|
|
updateHourControl();
|
|
|
|
|
setCurrentHour(hour);
|
|
|
|
|
updateAmPmControl();
|
|
|
|
|
mIs24HourView = is24HourView; // 更新当前模式
|
|
|
|
|
mAmPmSpinner.setVisibility(is24HourView ? View.GONE : View.VISIBLE); // 根据模式设置 AM/PM 选择器的可见性
|
|
|
|
|
int hour = getCurrentHourOfDay(); // 获取当前小时
|
|
|
|
|
updateHourControl(); // 更新小时选择器状态
|
|
|
|
|
setCurrentHour(hour); // 设置当前小时
|
|
|
|
|
updateAmPmControl(); // 更新 AM/PM 控制
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateDateControl() {
|
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
|
cal.setTimeInMillis(mDate.getTimeInMillis());
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, -DAYS_IN_ALL_WEEK / 2 - 1);
|
|
|
|
|
mDateSpinner.setDisplayedValues(null);
|
|
|
|
|
for (int i = 0; i < DAYS_IN_ALL_WEEK; ++i) {
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
|
mDateDisplayValues[i] = (String) DateFormat.format("MM.dd EEEE", cal);
|
|
|
|
|
private void updateDateControl() { // 更新日期选择器状态
|
|
|
|
|
Calendar cal = Calendar.getInstance(); // 获取当前日期的日历对象
|
|
|
|
|
cal.setTimeInMillis(mDate.getTimeInMillis()); // 设置日历时间为当前选择的日期
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, -DAYS_IN_ALL_WEEK / 2 - 1); // 更新为起始值
|
|
|
|
|
mDateSpinner.setDisplayedValues(null); // 清空日期选择器的显示值
|
|
|
|
|
for (int i = 0; i < DAYS_IN_ALL_WEEK; ++i) { // 遍历一周的每一天
|
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, 1); // 遍历到下一天
|
|
|
|
|
mDateDisplayValues[i] = (String) DateFormat.format("MM.dd EEEE", cal); // 格式化日期
|
|
|
|
|
}
|
|
|
|
|
mDateSpinner.setDisplayedValues(mDateDisplayValues);
|
|
|
|
|
mDateSpinner.setValue(DAYS_IN_ALL_WEEK / 2);
|
|
|
|
|
mDateSpinner.invalidate();
|
|
|
|
|
mDateSpinner.setDisplayedValues(mDateDisplayValues); // 设置日期选择器显示的值
|
|
|
|
|
mDateSpinner.setValue(DAYS_IN_ALL_WEEK / 2); // 设置日期选择器的默认值为一周中间的值
|
|
|
|
|
mDateSpinner.invalidate(); // 刷新日期选择器
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateAmPmControl() {
|
|
|
|
|
if (mIs24HourView) {
|
|
|
|
|
mAmPmSpinner.setVisibility(View.GONE);
|
|
|
|
|
private void updateAmPmControl() { // 更新 AM/PM 选择器状态
|
|
|
|
|
if (mIs24HourView) { // 如果为 24 小时制
|
|
|
|
|
mAmPmSpinner.setVisibility(View.GONE); // 隐藏 AM/PM 选择器
|
|
|
|
|
} else {
|
|
|
|
|
int index = mIsAm ? Calendar.AM : Calendar.PM;
|
|
|
|
|
mAmPmSpinner.setValue(index);
|
|
|
|
|
mAmPmSpinner.setVisibility(View.VISIBLE);
|
|
|
|
|
int index = mIsAm ? Calendar.AM : Calendar.PM; // 根据 AM/PM 标志获取索引
|
|
|
|
|
mAmPmSpinner.setValue(index); // 设置 AM/PM 选择器的值
|
|
|
|
|
mAmPmSpinner.setVisibility(View.VISIBLE); // 显示 AM/PM 选择器
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateHourControl() {
|
|
|
|
|
if (mIs24HourView) {
|
|
|
|
|
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW);
|
|
|
|
|
mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW);
|
|
|
|
|
private void updateHourControl() { // 更新小时选择器状态
|
|
|
|
|
if (mIs24HourView) { // 如果为 24 小时制
|
|
|
|
|
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW); // 设置 24 小时制的最小值
|
|
|
|
|
mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW); // 设置 24 小时制的最大值
|
|
|
|
|
} else {
|
|
|
|
|
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW);
|
|
|
|
|
mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW);
|
|
|
|
|
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW); // 设置 12 小时制的最小值
|
|
|
|
|
mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW); // 设置 12 小时制的最大值
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the callback that indicates the 'Set' button has been pressed.
|
|
|
|
|
* @param callback the callback, if null will do nothing
|
|
|
|
|
* 设置回调函数,用于指示“设置”按钮已被按下。
|
|
|
|
|
* @param callback 回调函数,如果为 null 则不执行任何操作
|
|
|
|
|
*/
|
|
|
|
|
public void setOnDateTimeChangedListener(OnDateTimeChangedListener callback) {
|
|
|
|
|
mOnDateTimeChangedListener = callback;
|
|
|
|
|
mOnDateTimeChangedListener = callback; // 更新监听器
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onDateTimeChanged() {
|
|
|
|
|
if (mOnDateTimeChangedListener != null) {
|
|
|
|
|
mOnDateTimeChangedListener.onDateTimeChanged(this, getCurrentYear(),
|
|
|
|
|
private void onDateTimeChanged() { // 日期时间更改的处理方法
|
|
|
|
|
if (mOnDateTimeChangedListener != null) { // 如果有设置的监听器
|
|
|
|
|
mOnDateTimeChangedListener.onDateTimeChanged(this, getCurrentYear(), // 调用监听器的方法,传递当前的日期和时间
|
|
|
|
|
getCurrentMonth(), getCurrentDay(), getCurrentHourOfDay(), getCurrentMinute());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|