private void updateDisplay(boolean announce) { if (mDayOfWeekView != null) { mDayOfWeekView.setText( mCalendar .getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()) .toUpperCase(Locale.getDefault())); } mSelectedMonthTextView.setText( mCalendar .getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault()) .toUpperCase(Locale.getDefault())); mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime())); long millis = mCalendar.getTimeInMillis(); mAnimator.setDateMillis(millis); int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR; String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags); mMonthAndDayView.setContentDescription(monthAndDayText); if (announce) { flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR; String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags); Utils.tryAccessibilityAnnounce(mAnimator, fullDateText); } }
private void setCurrentView() { long millis = mCalendar.getTimeInMillis(); ObjectAnimator pulseAnimator = Utils.getPulseAnimator(mMonthAndDayView, 0.9f, 1.05f); if (mDelayAnimation) { pulseAnimator.setStartDelay(ANIMATION_DELAY); mDelayAnimation = false; } mDayPickerView.onDateChanged(); mMonthAndDayView.setSelected(true); pulseAnimator.start(); int flags = DateUtils.FORMAT_SHOW_DATE; String dayString = DateUtils.formatDateTime(getActivity(), millis, flags); mAnimator.setContentDescription(mDayPickerDescription + ": " + dayString); Utils.tryAccessibilityAnnounce(mAnimator, mSelectDay); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); View view = inflater.inflate(R.layout.calendar_date_picker_dialog, null); mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header); mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day); mMonthAndDayView.setOnClickListener(this); mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month); mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day); int listPosition = -1; if (savedInstanceState != null) { mWeekStart = savedInstanceState.getInt(KEY_WEEK_START); mMinYear = savedInstanceState.getInt(KEY_YEAR_START); mMaxYear = savedInstanceState.getInt(KEY_YEAR_END); listPosition = savedInstanceState.getInt(KEY_LIST_POSITION); } final Activity activity = getActivity(); mDayPickerView = new SimpleDayPickerView(activity, this); Resources res = getResources(); mDayPickerDescription = res.getString(R.string.day_picker_description); mSelectDay = res.getString(R.string.select_day); mAnimator = (AccessibleDateAnimator) view.findViewById(R.id.animator); mAnimator.addView(mDayPickerView); mAnimator.setDateMillis(mCalendar.getTimeInMillis()); Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(ANIMATION_DURATION); mAnimator.setInAnimation(animation); Animation animation2 = new AlphaAnimation(1.0f, 0.0f); animation2.setDuration(ANIMATION_DURATION); mAnimator.setOutAnimation(animation2); Button mDoneButton = (Button) view.findViewById(R.id.done); mDoneButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (mCallBack != null) { mCallBack.onDateSet( CalendarDatePickerDialog.this, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)); } dismiss(); } }); updateDisplay(false); setCurrentView(); if (listPosition != -1) { mDayPickerView.postSetSelection(listPosition); } return view; }