|
|
|
@ -345,63 +345,70 @@ public class DateTimePicker extends FrameLayout {
|
|
|
|
|
* @return The current month in the year
|
|
|
|
|
*/
|
|
|
|
|
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 月份(从0开始,0代表一月)
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentMonth(int month) {
|
|
|
|
|
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()) {
|
|
|
|
|
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
|
|
|
|
|
* 获取当前的小时(24小时制),范围为0~23
|
|
|
|
|
*
|
|
|
|
|
* @return 当前的小时(24小时制)
|
|
|
|
|
*/
|
|
|
|
|
public int getCurrentHourOfDay() {
|
|
|
|
|
return mDate.get(Calendar.HOUR_OF_DAY);
|
|
|
|
|
return mDate.get(Calendar.HOUR_OF_DAY); // 获取日期对象的小时字段(24小时制)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前的小时
|
|
|
|
|
*
|
|
|
|
|
* @return 当前的小时
|
|
|
|
|
*/
|
|
|
|
|
private int getCurrentHour() {
|
|
|
|
|
if (mIs24HourView){
|
|
|
|
|
return getCurrentHourOfDay();
|
|
|
|
|
} else {
|
|
|
|
|
int hour = getCurrentHourOfDay();
|
|
|
|
|
if (hour > HOURS_IN_HALF_DAY) {
|
|
|
|
|
return hour - HOURS_IN_HALF_DAY;
|
|
|
|
|
} else {
|
|
|
|
|
return hour == 0 ? HOURS_IN_HALF_DAY : hour;
|
|
|
|
|
if (mIs24HourView) { // 如果是24小时制
|
|
|
|
|
return getCurrentHourOfDay(); // 直接获取当前的小时
|
|
|
|
|
} else { // 如果是12小时制
|
|
|
|
|
int hour = getCurrentHourOfDay(); // 获取当前的小时
|
|
|
|
|
if (hour > HOURS_IN_HALF_DAY) { // 如果大于12小时
|
|
|
|
|
return hour - HOURS_IN_HALF_DAY; // 返回减去12小时的小时数
|
|
|
|
|
} else { // 如果小于等于12小时
|
|
|
|
|
return hour == 0 ? HOURS_IN_HALF_DAY : hour; // 如果小时为0,则返回12小时,否则返回当前的小时
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|