个人第三方控件依赖库总结

个人第三方控件依赖库总结

(2018-03-23)

  • 日期和时间选择对话框

第三方依赖库

  • datetimepicker

个人使用

datetimepicker 日期和时间的对话框

网址: https://github.com/MrFuShuai/datetimepicker

使用

添加依赖 compile ‘com.github.flavienlaurent.datetimepicker:library:0.0.2’

弹出日期时间选择对话框并设置系统日期和时间

/**
 * 
 *     author : Mr.Fu
 *     e-mail : [email protected]
 *     time   : 2018/03/23
 *     desc   : 其他设置界面 ----> 手动设置系统日期和时间
 *     version: 1.0
 * 
*/
public class OtherSettingFragment extends BaseFragment implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener { public static final String DATE_PICKER_TAG = "date_picker"; public static final String TIME_PICKER_TAG = "time_picker"; private Calendar calendar; ... ... ... private void showDatePickerDialog() { calendar = Calendar.getInstance(); DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), true); datePickerDialog.setVibrate(true); datePickerDialog.setCancelable(false); datePickerDialog.setCloseOnSingleTapDay(false); datePickerDialog.setYearRange(2018, 2037); datePickerDialog.show(getFragmentManager(), DATE_PICKER_TAG); } private void showTimePickerDialog() { calendar = Calendar.getInstance(); TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(this, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true, false); timePickerDialog.setVibrate(true); timePickerDialog.setCancelable(false); timePickerDialog.setCloseOnSingleTapMinute(false); timePickerDialog.show(getFragmentManager(), TIME_PICKER_TAG); } @Override public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) { // 设置系统日期为当前选中的日期 setSysDate(year, month, day); } private void setSysDate(int year, int month, int day) { calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); long when = calendar.getTimeInMillis(); if (when / 1000 < Integer.MAX_VALUE) { ((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).setTime(when); } } @Override public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) { // 设置系统时间为当前选中的时间 setSysTime(hourOfDay, minute); } private void setSysTime(int hourOfDay, int minute) { calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); long when = calendar.getTimeInMillis(); if(when / 1000 < Integer.MAX_VALUE){ ((AlarmManager)getContext().getSystemService(Context.ALARM_SERVICE)).setTime(when); } } }

你可能感兴趣的:(Android开发,第三方依赖库)