public void onClick(View v) { switch (v.getId()) { case R.id.datetime_picker_submit: saveSelectedDateTime(); sendRoutesRequest(mBegDateTime.toString(), mEndDateTime.toString()); case R.id.datetime_picker_cancel: case R.id.datetime_picker_close: hidePickerDialog(); break; case R.id.path_endtime: case R.id.path_begtime: mCurrButton = (Button) v; showPickerDialog(mCurrButton.getHint().toString(), mCurrButton.getText().toString()); break; } }
private void showPickerDialog(String title, String strDatetime) { if (mDialog == null) { mDialog = new PopupWindowDialog(mPathActivity); mDialog.setContentView(R.layout.datetime_picker); } View view = mDialog.getContentView(); { view.findViewById(R.id.datetime_picker_close).setOnClickListener(this); view.findViewById(R.id.datetime_picker_cancel).setOnClickListener(this); view.findViewById(R.id.datetime_picker_submit).setOnClickListener(this); } TextView lblTitle = (TextView) view.findViewById(R.id.datetime_picker_title); datetime_picker_date = (DatePicker) view.findViewById(R.id.datetime_picker_date); datetime_picker_time = (TimePicker) view.findViewById(R.id.datetime_picker_time); lblTitle.setText(title); DateTime datetime = DateTime.from(strDatetime, "yyyy-MM-dd HH:mm"); datetime_picker_date.init( datetime.getYear(), datetime.getMonth(), datetime.getDay(), null); // date.getDay() // pkrTime.setIs24HourView(true);// 24小时制 datetime_picker_time.setCurrentHour(datetime.getHours()); // 设置当前小时。 datetime_picker_time.setCurrentMinute(datetime.getMinutes()); // 当前分钟 // datetime_picker_time.setOnTimeChangedListener(null); mDialog.show(); }
private void checkInitRoutes() { Bundle bundle = getIntent().getExtras(); if (bundle == null) { toPointCenter(); ToastShow.show(this, "参数错误,没有轨迹的起始和结束时间!"); return; } try { String topName = bundle.getString(PathActivity.ARGS_TOP_NAME); String begTime = bundle.getString(PathActivity.ARGS_BEG_DATE); String endTime = bundle.getString(PathActivity.ARGS_END_DATE); mActionBar.setTitle(topName); if (begTime != null && endTime != null) { mBegDateTime = DateTime.from(begTime); mBtnBegTime.setText(mBegDateTime.toString(mDateTimeFormat)); mEndDateTime = DateTime.from(endTime); mBtnEndTime.setText(mEndDateTime.toString(mDateTimeFormat)); sendRoutesRequest(begTime, endTime); } else { { mEndDateTime = DateTime.now(); mBegDateTime = DateTime.from(mEndDateTime); // 默认当天6点开始 mBegDateTime.setHours(6); mBegDateTime.setMinutes(0); // mEndDateTime.addDay(-3);// 默认查最近三天的记录 } mBtnBegTime.setText(mBegDateTime.toString(mDateTimeFormat)); mBtnEndTime.setText(mEndDateTime.toString(mDateTimeFormat)); toCaricoCenter(); } } catch (Exception ex) { ex.printStackTrace(); // ToastShow.show(this, "Intent参数不正确!"); } }
private void saveSelectedDateTime() { // save beg date mBegDateTime.setYear(datetime_picker_date.getYear()); mBegDateTime.setMonth(datetime_picker_date.getMonth()); mBegDateTime.setDay(datetime_picker_date.getDayOfMonth()); // save end date mEndDateTime.setYear(datetime_picker_date.getYear()); mEndDateTime.setMonth(datetime_picker_date.getMonth()); mEndDateTime.setDay(datetime_picker_date.getDayOfMonth()); switch (mCurrButton.getId()) { case R.id.path_begtime: // // date // mBegDateTime.setYear(datetime_picker_date.getYear()); // mBegDateTime.setMonth(datetime_picker_date.getMonth()); // mBegDateTime.setDay(datetime_picker_date.getDayOfMonth()); // time mBegDateTime.setHours(datetime_picker_time.getCurrentHour()); mBegDateTime.setMinutes(datetime_picker_time.getCurrentMinute()); // // set // mCurrButton.setText(mBegDateTime.toString(mDateTimeFormat)); break; case R.id.path_endtime: // // date // mEndDateTime.setYear(datetime_picker_date.getYear()); // mEndDateTime.setMonth(datetime_picker_date.getMonth()); // mEndDateTime.setDay(datetime_picker_date.getDayOfMonth()); // time mEndDateTime.setHours(datetime_picker_time.getCurrentHour()); mEndDateTime.setMinutes(datetime_picker_time.getCurrentMinute()); // // set // mCurrButton.setText(mEndDateTime.toString(mDateTimeFormat)); break; } // set mBtnBegTime.setText(mBegDateTime.toString(mDateTimeFormat)); // set mBtnEndTime.setText(mEndDateTime.toString(mDateTimeFormat)); }