|  |  |  | @ -1,19 +1,3 @@ | 
			
		
	
		
			
				
					|  |  |  |  | /* | 
			
		
	
		
			
				
					|  |  |  |  |  * 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. | 
			
		
	
		
			
				
					|  |  |  |  |  */ | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | package net.micode.notes.ui; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import java.text.DateFormatSymbols; | 
			
		
	
	
		
			
				
					|  |  |  | @ -21,7 +5,6 @@ import java.util.Calendar; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import net.micode.notes.R; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import android.content.Context; | 
			
		
	
		
			
				
					|  |  |  |  | import android.text.format.DateFormat; | 
			
		
	
		
			
				
					|  |  |  |  | import android.view.View; | 
			
		
	
	
		
			
				
					|  |  |  | @ -30,6 +13,7 @@ import android.widget.NumberPicker; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 默认启用状态
 | 
			
		
	
		
			
				
					|  |  |  |  |     private static final boolean DEFAULT_ENABLE_STATE = true; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private static final int HOURS_IN_HALF_DAY = 12; | 
			
		
	
	
		
			
				
					|  |  |  | @ -46,39 +30,44 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |     private static final int AMPM_SPINNER_MIN_VAL = 0; | 
			
		
	
		
			
				
					|  |  |  |  |     private static final int AMPM_SPINNER_MAX_VAL = 1; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 日期选择器、小时选择器、分钟选择器和上午/下午选择器
 | 
			
		
	
		
			
				
					|  |  |  |  |     private final NumberPicker mDateSpinner; | 
			
		
	
		
			
				
					|  |  |  |  |     private final NumberPicker mHourSpinner; | 
			
		
	
		
			
				
					|  |  |  |  |     private final NumberPicker mMinuteSpinner; | 
			
		
	
		
			
				
					|  |  |  |  |     private final NumberPicker mAmPmSpinner; | 
			
		
	
		
			
				
					|  |  |  |  |     private Calendar mDate; | 
			
		
	
		
			
				
					|  |  |  |  |     private Calendar mDate;  // 日历对象
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK]; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private boolean mIsAm; | 
			
		
	
		
			
				
					|  |  |  |  |     private boolean mIsAm;  // 是否是上午
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     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) { | 
			
		
	
		
			
				
					|  |  |  |  |                 // 非24小时制
 | 
			
		
	
		
			
				
					|  |  |  |  |                 if (!mIsAm && oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) { | 
			
		
	
		
			
				
					|  |  |  |  |                     cal.setTimeInMillis(mDate.getTimeInMillis()); | 
			
		
	
		
			
				
					|  |  |  |  |                     cal.add(Calendar.DAY_OF_YEAR, 1); | 
			
		
	
	
		
			
				
					|  |  |  | @ -90,10 +79,11 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |                 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;  // 上午/下午切换
 | 
			
		
	
		
			
				
					|  |  |  |  |                     updateAmPmControl();  // 更新上午/下午控件
 | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                 // 24小时制
 | 
			
		
	
		
			
				
					|  |  |  |  |                 if (oldVal == HOURS_IN_ALL_DAY - 1 && newVal == 0) { | 
			
		
	
		
			
				
					|  |  |  |  |                     cal.setTimeInMillis(mDate.getTimeInMillis()); | 
			
		
	
		
			
				
					|  |  |  |  |                     cal.add(Calendar.DAY_OF_YEAR, 1); | 
			
		
	
	
		
			
				
					|  |  |  | @ -106,7 +96,7 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             int newHour = mHourSpinner.getValue() % HOURS_IN_HALF_DAY + (mIsAm ? 0 : HOURS_IN_HALF_DAY); | 
			
		
	
		
			
				
					|  |  |  |  |             mDate.set(Calendar.HOUR_OF_DAY, newHour); | 
			
		
	
		
			
				
					|  |  |  |  |             onDateTimeChanged(); | 
			
		
	
		
			
				
					|  |  |  |  |             onDateTimeChanged();  // 日期时间改变回调
 | 
			
		
	
		
			
				
					|  |  |  |  |             if (isDateChanged) { | 
			
		
	
		
			
				
					|  |  |  |  |                 setCurrentYear(cal.get(Calendar.YEAR)); | 
			
		
	
		
			
				
					|  |  |  |  |                 setCurrentMonth(cal.get(Calendar.MONTH)); | 
			
		
	
	
		
			
				
					|  |  |  | @ -115,6 +105,7 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 分钟改变监听器
 | 
			
		
	
		
			
				
					|  |  |  |  |     private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() { | 
			
		
	
		
			
				
					|  |  |  |  |         @Override | 
			
		
	
		
			
				
					|  |  |  |  |         public void onValueChange(NumberPicker picker, int oldVal, int newVal) { | 
			
		
	
	
		
			
				
					|  |  |  | @ -140,51 +131,60 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             mDate.set(Calendar.MINUTE, newVal); | 
			
		
	
		
			
				
					|  |  |  |  |             onDateTimeChanged(); | 
			
		
	
		
			
				
					|  |  |  |  |             onDateTimeChanged();  // 日期时间改变回调
 | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 上午/下午改变监听器
 | 
			
		
	
		
			
				
					|  |  |  |  |     private NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() { | 
			
		
	
		
			
				
					|  |  |  |  |         @Override | 
			
		
	
		
			
				
					|  |  |  |  |         public void onValueChange(NumberPicker picker, int oldVal, int newVal) { | 
			
		
	
		
			
				
					|  |  |  |  |             mIsAm = !mIsAm; | 
			
		
	
		
			
				
					|  |  |  |  |             mIsAm = !mIsAm;  // 切换上午/下午
 | 
			
		
	
		
			
				
					|  |  |  |  |             if (mIsAm) { | 
			
		
	
		
			
				
					|  |  |  |  |                 mDate.add(Calendar.HOUR_OF_DAY, -HOURS_IN_HALF_DAY); | 
			
		
	
		
			
				
					|  |  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                 mDate.add(Calendar.HOUR_OF_DAY, HOURS_IN_HALF_DAY); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             updateAmPmControl(); | 
			
		
	
		
			
				
					|  |  |  |  |             onDateTimeChanged(); | 
			
		
	
		
			
				
					|  |  |  |  |             updateAmPmControl();  // 更新上午/下午控件
 | 
			
		
	
		
			
				
					|  |  |  |  |             onDateTimeChanged();  // 日期时间改变回调
 | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 日期时间改变监听器接口
 | 
			
		
	
		
			
				
					|  |  |  |  |     public interface OnDateTimeChangedListener { | 
			
		
	
		
			
				
					|  |  |  |  |         void onDateTimeChanged(DateTimePicker view, int year, int month, | 
			
		
	
		
			
				
					|  |  |  |  |                                int dayOfMonth, int hourOfDay, int minute); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 构造函数
 | 
			
		
	
		
			
				
					|  |  |  |  |     public DateTimePicker(Context context) { | 
			
		
	
		
			
				
					|  |  |  |  |         this(context, System.currentTimeMillis()); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 带参数的构造函数
 | 
			
		
	
		
			
				
					|  |  |  |  |     public DateTimePicker(Context context, long date) { | 
			
		
	
		
			
				
					|  |  |  |  |         this(context, date, DateFormat.is24HourFormat(context)); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 带参数的构造函数
 | 
			
		
	
		
			
				
					|  |  |  |  |     public DateTimePicker(Context context, long date, boolean is24HourView) { | 
			
		
	
		
			
				
					|  |  |  |  |         super(context); | 
			
		
	
		
			
				
					|  |  |  |  |         mDate = Calendar.getInstance(); | 
			
		
	
		
			
				
					|  |  |  |  |         mDate = Calendar.getInstance();  // 初始化日历对象
 | 
			
		
	
		
			
				
					|  |  |  |  |         mInitialising = true; | 
			
		
	
		
			
				
					|  |  |  |  |         mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY; | 
			
		
	
		
			
				
					|  |  |  |  |         inflate(context, R.layout.datetime_picker, this); | 
			
		
	
		
			
				
					|  |  |  |  |         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); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 初始化小时选择器
 | 
			
		
	
		
			
				
					|  |  |  |  |         mHourSpinner = (NumberPicker) findViewById(R.id.hour); | 
			
		
	
		
			
				
					|  |  |  |  |         mHourSpinner.setOnValueChangedListener(mOnHourChangedListener); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 初始化分钟选择器
 | 
			
		
	
		
			
				
					|  |  |  |  |         mMinuteSpinner =  (NumberPicker) findViewById(R.id.minute); | 
			
		
	
		
			
				
					|  |  |  |  |         mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL); | 
			
		
	
		
			
				
					|  |  |  |  |         mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL); | 
			
		
	
	
		
			
				
					|  |  |  | @ -192,28 +192,30 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 初始化上午/下午选择器
 | 
			
		
	
		
			
				
					|  |  |  |  |         mAmPmSpinner = (NumberPicker) findViewById(R.id.amPm); | 
			
		
	
		
			
				
					|  |  |  |  |         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(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         set24HourView(is24HourView); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // set to current time
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 设置为当前时间
 | 
			
		
	
		
			
				
					|  |  |  |  |         setCurrentDate(date); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         setEnabled(isEnabled()); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // set the content descriptions
 | 
			
		
	
		
			
				
					|  |  |  |  |         mInitialising = false; | 
			
		
	
		
			
				
					|  |  |  |  |         mInitialising = false;  // 初始化完成
 | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 设置是否启用
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public void setEnabled(boolean enabled) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (mIsEnabled == enabled) { | 
			
		
	
	
		
			
				
					|  |  |  | @ -227,24 +229,25 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         mIsEnabled = enabled; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 获取是否启用
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public boolean isEnabled() { | 
			
		
	
		
			
				
					|  |  |  |  |         return mIsEnabled; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Get the current date in millis | 
			
		
	
		
			
				
					|  |  |  |  |      * 获取当前日期的毫秒表示 | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @return the current date in millis | 
			
		
	
		
			
				
					|  |  |  |  |      * @return 当前日期的毫秒表示 | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     public long getCurrentDateInTimeMillis() { | 
			
		
	
		
			
				
					|  |  |  |  |         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(); | 
			
		
	
	
		
			
				
					|  |  |  | @ -254,13 +257,13 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * 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) { | 
			
		
	
	
		
			
				
					|  |  |  | @ -271,20 +274,12 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         setCurrentMinute(minute); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Get current year | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @return The current year | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     // 获取当前年份
 | 
			
		
	
		
			
				
					|  |  |  |  |     public int getCurrentYear() { | 
			
		
	
		
			
				
					|  |  |  |  |         return mDate.get(Calendar.YEAR); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Set current year | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @param year The current year | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     // 设置当前年份
 | 
			
		
	
		
			
				
					|  |  |  |  |     public void setCurrentYear(int year) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (!mInitialising && year == getCurrentYear()) { | 
			
		
	
		
			
				
					|  |  |  |  |             return; | 
			
		
	
	
		
			
				
					|  |  |  | @ -294,20 +289,12 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         onDateTimeChanged(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Get current month in the year | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @return The current month in the year | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     // 获取当前月份
 | 
			
		
	
		
			
				
					|  |  |  |  |     public int getCurrentMonth() { | 
			
		
	
		
			
				
					|  |  |  |  |         return mDate.get(Calendar.MONTH); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Set current month in the year | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @param month The month in the year | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     // 设置当前月份
 | 
			
		
	
		
			
				
					|  |  |  |  |     public void setCurrentMonth(int month) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (!mInitialising && month == getCurrentMonth()) { | 
			
		
	
		
			
				
					|  |  |  |  |             return; | 
			
		
	
	
		
			
				
					|  |  |  | @ -317,20 +304,12 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         onDateTimeChanged(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Get current day of the month | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @return The day of the month | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     // 获取当前日期
 | 
			
		
	
		
			
				
					|  |  |  |  |     public int getCurrentDay() { | 
			
		
	
		
			
				
					|  |  |  |  |         return mDate.get(Calendar.DAY_OF_MONTH); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Set current day of the month | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @param dayOfMonth The day of the month | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     // 设置当前日期
 | 
			
		
	
		
			
				
					|  |  |  |  |     public void setCurrentDay(int dayOfMonth) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (!mInitialising && dayOfMonth == getCurrentDay()) { | 
			
		
	
		
			
				
					|  |  |  |  |             return; | 
			
		
	
	
		
			
				
					|  |  |  | @ -340,14 +319,12 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         onDateTimeChanged(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Get current hour in 24 hour mode, in the range (0~23) | 
			
		
	
		
			
				
					|  |  |  |  |      * @return The current hour in 24 hour mode | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     // 获取24小时模式下的当前小时
 | 
			
		
	
		
			
				
					|  |  |  |  |     public int getCurrentHourOfDay() { | 
			
		
	
		
			
				
					|  |  |  |  |         return mDate.get(Calendar.HOUR_OF_DAY); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 获取当前小时
 | 
			
		
	
		
			
				
					|  |  |  |  |     private int getCurrentHour() { | 
			
		
	
		
			
				
					|  |  |  |  |         if (mIs24HourView){ | 
			
		
	
		
			
				
					|  |  |  |  |             return getCurrentHourOfDay(); | 
			
		
	
	
		
			
				
					|  |  |  | @ -361,11 +338,7 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Set current hour in 24 hour mode, in the range (0~23) | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @param hourOfDay | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     // 设置当前小时
 | 
			
		
	
		
			
				
					|  |  |  |  |     public void setCurrentHour(int hourOfDay) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (!mInitialising && hourOfDay == getCurrentHourOfDay()) { | 
			
		
	
		
			
				
					|  |  |  |  |             return; | 
			
		
	
	
		
			
				
					|  |  |  | @ -389,18 +362,12 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         onDateTimeChanged(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Get currentMinute | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @return The Current Minute | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     // 获取当前分钟
 | 
			
		
	
		
			
				
					|  |  |  |  |     public int getCurrentMinute() { | 
			
		
	
		
			
				
					|  |  |  |  |         return mDate.get(Calendar.MINUTE); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Set current minute | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     // 设置当前分钟
 | 
			
		
	
		
			
				
					|  |  |  |  |     public void setCurrentMinute(int minute) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (!mInitialising && minute == getCurrentMinute()) { | 
			
		
	
		
			
				
					|  |  |  |  |             return; | 
			
		
	
	
		
			
				
					|  |  |  | @ -411,16 +378,18 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * @return true if this is in 24 hour view else false. | 
			
		
	
		
			
				
					|  |  |  |  |      * 是否是24小时制 | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @return 如果是24小时制返回true,否则返回false | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     public boolean is24HourView () { | 
			
		
	
		
			
				
					|  |  |  |  |         return mIs24HourView; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * Set whether in 24 hour or AM/PM mode. | 
			
		
	
		
			
				
					|  |  |  |  |      * 设置是否是24小时制或上午/下午模式 | 
			
		
	
		
			
				
					|  |  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |  |      * @param is24HourView True for 24 hour mode. False for AM/PM mode. | 
			
		
	
		
			
				
					|  |  |  |  |      * @param is24HourView true 表示24小时制,false 表示上午/下午模式 | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     public void set24HourView(boolean is24HourView) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (mIs24HourView == is24HourView) { | 
			
		
	
	
		
			
				
					|  |  |  | @ -434,6 +403,7 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         updateAmPmControl(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 更新日期控件
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void updateDateControl() { | 
			
		
	
		
			
				
					|  |  |  |  |         Calendar cal = Calendar.getInstance(); | 
			
		
	
		
			
				
					|  |  |  |  |         cal.setTimeInMillis(mDate.getTimeInMillis()); | 
			
		
	
	
		
			
				
					|  |  |  | @ -448,6 +418,7 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         mDateSpinner.invalidate(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 更新上午/下午控件
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void updateAmPmControl() { | 
			
		
	
		
			
				
					|  |  |  |  |         if (mIs24HourView) { | 
			
		
	
		
			
				
					|  |  |  |  |             mAmPmSpinner.setVisibility(View.GONE); | 
			
		
	
	
		
			
				
					|  |  |  | @ -458,6 +429,7 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 更新小时控件
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void updateHourControl() { | 
			
		
	
		
			
				
					|  |  |  |  |         if (mIs24HourView) { | 
			
		
	
		
			
				
					|  |  |  |  |             mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW); | 
			
		
	
	
		
			
				
					|  |  |  | @ -469,13 +441,15 @@ public class DateTimePicker extends FrameLayout { | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * 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; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 日期时间改变回调
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void onDateTimeChanged() { | 
			
		
	
		
			
				
					|  |  |  |  |         if (mOnDateTimeChangedListener != null) { | 
			
		
	
		
			
				
					|  |  |  |  |             mOnDateTimeChangedListener.onDateTimeChanged(this, getCurrentYear(), | 
			
		
	
	
		
			
				
					|  |  |  | 
 |