@Override public void save() { DayValues dayValues = null; if (mListener != null) { switch (mCurrentValues.type) { case DayValues.TYPE_ONE_SHOT: Calendar calendar = Calendar.getInstance(); calendar.set(mDatePicker.getYear(), mDatePicker.getMonth(), mDatePicker.getDayOfMonth()); dayValues = new OneShotValues(calendar); break; case DayValues.TYPE_REPEAT: dayValues = new RepeatValues(mRepeatPicker.getSelectedDays(), Calendar.getInstance()); break; case DayValues.TYPE_EVERY: dayValues = new IntervalValues( mIntervalPicker.getUnit(), mIntervalPicker.getNumberValue(), Calendar.getInstance()); break; } mCurrentValues = dayValues; mListener.onSchedulerDayChange(this, dayValues); } }
private void updateViews() { switch (mCurrentValues.type) { case DayValues.TYPE_ONE_SHOT: Calendar calendar = ((OneShotValues) mCurrentValues).date; mDatePicker.init( calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), this); break; case DayValues.TYPE_REPEAT: List<Integer> days = ((RepeatValues) mCurrentValues).days; mRepeatPicker.setSelectedDays(days); break; case DayValues.TYPE_EVERY: IntervalValues values = (IntervalValues) mCurrentValues; mIntervalPicker.setUnit(values.unit); mIntervalPicker.setNumberValue(values.number); break; } mBtnOneShot.setEnabled(mCurrentValues.type != DayValues.TYPE_ONE_SHOT); mBtnRepeat.setEnabled(mCurrentValues.type != DayValues.TYPE_REPEAT); mBtnEvery.setEnabled(mCurrentValues.type != DayValues.TYPE_EVERY); mViewSwitcher.setDisplayedChild(mCurrentValues.type); mListener.onCurrentValuesTypeChanged(mCurrentValues.type); }
@Override public void onClick(View v) { if (mBtnOneShot == v) { Calendar date = Calendar.getInstance(); date.set(mDatePicker.getYear(), mDatePicker.getMonth(), mDatePicker.getDayOfMonth()); mCurrentValues = new OneShotValues(date); } else if (mBtnRepeat == v) { List<Integer> days = mRepeatPicker.getSelectedDays(); mCurrentValues = new RepeatValues(days, Calendar.getInstance()); } else if (mBtnEvery == v) { mCurrentValues = new IntervalValues( mIntervalPicker.getUnit(), mIntervalPicker.getNumberValue(), Calendar.getInstance()); } updateViews(); save(); }
@Override public void onActivityCreated(Bundle savedInstanceState) { View root = getView(); mContainer = root.findViewById(R.id.scheduler_container); mViewSwitcher = (ViewAnimator) root.findViewById(R.id.scheduler_switcher); mBtnOneShot = (Button) root.findViewById(R.id.btn_one_shot); mBtnOneShot.setOnClickListener(mBtnClickListener); mBtnRepeat = (Button) root.findViewById(R.id.btn_repeat); mBtnRepeat.setOnClickListener(mBtnClickListener); mBtnEvery = (Button) root.findViewById(R.id.btn_every); mBtnEvery.setOnClickListener(mBtnClickListener); mDatePicker = (ScrollDatePicker) root.findViewById(R.id.scheduler_date_picker); Calendar calendar = Calendar.getInstance(); mDatePicker.init( calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), this); mRepeatPicker = (RepeatPicker) root.findViewById(R.id.scheduler_repeat_picker); mRepeatPicker.setListener(this); mIntervalPicker = (IntervalPicker) root.findViewById(R.id.scheduler_every_picker); mIntervalPicker.setOnChangeListener(this); mOverlayView = root.findViewById(R.id.scheduler_overlay); mOverlayView.setOnClickListener(mOverlayClickListener); if (savedInstanceState != null) { mCurrentValues = savedInstanceState.getParcelable(STATE_CURRENT_VALUES); } else { mContainer.setAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.slide_in_bottom)); mOverlayView.animate().alpha(1.0f); mCurrentValues = getArguments().getParcelable(STATE_CURRENT_VALUES); } if (mCurrentValues == null) { mCurrentValues = new OneShotValues(Calendar.getInstance()); } // save(); this overwrites the loaded schedule ;( updateViews(); super.onActivityCreated(savedInstanceState); }