com.android.datetimepicker.Utils Java Examples
The following examples show how to use
com.android.datetimepicker.Utils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TimePickerDialog.java From narrate-android with Apache License 2.0 | 6 votes |
/** * Called by the picker for updating the header display. */ @Override public void onValueSelected(int pickerIndex, int newValue, boolean autoAdvance) { if (pickerIndex == HOUR_INDEX) { setHour(newValue, false); String announcement = String.format("%d", newValue); if (mAllowAutoAdvance && autoAdvance) { setCurrentItemShowing(MINUTE_INDEX, true, true, false); announcement += ". " + mSelectMinutes; } else { mTimePicker.setContentDescription(mHourPickerDescription + ": " + newValue); } Utils.tryAccessibilityAnnounce(mTimePicker, announcement); } else if (pickerIndex == MINUTE_INDEX){ setMinute(newValue); mTimePicker.setContentDescription(mMinutePickerDescription + ": " + newValue); } else if (pickerIndex == AMPM_INDEX) { updateAmPmDisplay(newValue); } else if (pickerIndex == ENABLE_PICKER_INDEX) { if (!isTypedTimeFullyLegal()) { mTypedTimes.clear(); } finishKbMode(true); } }
Example #2
Source File: TimePickerDialog.java From StyleableDateTimePicker with MIT License | 6 votes |
private void setHour(int value, boolean announce) { String format; if (mIs24HourMode) { format = "%02d"; } else { format = "%d"; value = value % 12; if (value == 0) { value = 12; } } CharSequence text = String.format(format, value); mHourView.setText(text); mHourSpaceView.setText(text); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, text); } }
Example #3
Source File: TimePickerDialog.java From StyleableDateTimePicker with MIT License | 6 votes |
/** * Called by the picker for updating the header display. */ @Override public void onValueSelected(int pickerIndex, int newValue, boolean autoAdvance) { if (pickerIndex == HOUR_INDEX) { setHour(newValue, false); String announcement = String.format("%d", newValue); if (mAllowAutoAdvance && autoAdvance) { setCurrentItemShowing(MINUTE_INDEX, true, true, false); announcement += ". " + mSelectMinutes; } else { mTimePicker.setContentDescription(mHourPickerDescription + ": " + newValue); } Utils.tryAccessibilityAnnounce(mTimePicker, announcement); } else if (pickerIndex == MINUTE_INDEX){ setMinute(newValue); mTimePicker.setContentDescription(mMinutePickerDescription + ": " + newValue); } else if (pickerIndex == AMPM_INDEX) { updateAmPmDisplay(newValue); } else if (pickerIndex == ENABLE_PICKER_INDEX) { if (!isTypedTimeFullyLegal()) { mTypedTimes.clear(); } finishKbMode(true); } }
Example #4
Source File: DatePickerDialog.java From StyleableDateTimePicker with MIT License | 6 votes |
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())); mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime())); // Accessibility. 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); } }
Example #5
Source File: DatePickerDialog.java From narrate-android with Apache License 2.0 | 6 votes |
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())); mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime())); // Accessibility. 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); } }
Example #6
Source File: TimePickerDialog.java From cathode with Apache License 2.0 | 6 votes |
/** * Called by the picker for updating the header display. */ @Override public void onValueSelected(int pickerIndex, int newValue, boolean autoAdvance) { if (pickerIndex == HOUR_INDEX) { setHour(newValue, false); String announcement = String.format("%d", newValue); if (mAllowAutoAdvance && autoAdvance) { setCurrentItemShowing(MINUTE_INDEX, true, true, false); announcement += ". " + mSelectMinutes; } else { mTimePicker.setContentDescription(mHourPickerDescription + ": " + newValue); } Utils.tryAccessibilityAnnounce(mTimePicker, announcement); } else if (pickerIndex == MINUTE_INDEX) { setMinute(newValue); mTimePicker.setContentDescription(mMinutePickerDescription + ": " + newValue); } else if (pickerIndex == AMPM_INDEX) { updateAmPmDisplay(newValue); } else if (pickerIndex == ENABLE_PICKER_INDEX) { if (!isTypedTimeFullyLegal()) { mTypedTimes.clear(); } finishKbMode(true); } }
Example #7
Source File: TimePickerDialog.java From cathode with Apache License 2.0 | 6 votes |
private void setHour(int value, boolean announce) { String format; if (mIs24HourMode) { format = "%02d"; } else { format = "%d"; value = value % 12; if (value == 0) { value = 12; } } CharSequence text = String.format(format, value); mHourView.setText(text); mHourSpaceView.setText(text); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, text); } }
Example #8
Source File: TimePickerDialog.java From cathode with Apache License 2.0 | 6 votes |
private boolean addKeyIfLegal(int keyCode) { // If we're in 24hour mode, we'll need to check if the input is full. If in AM/PM mode, // we'll need to see if AM/PM have been typed. if ((mIs24HourMode && mTypedTimes.size() == 4) || (!mIs24HourMode && isTypedTimeFullyLegal())) { return false; } mTypedTimes.add(keyCode); if (!isTypedTimeLegalSoFar()) { deleteLastTypedKey(); return false; } int val = getValFromKeyCode(keyCode); Utils.tryAccessibilityAnnounce(mTimePicker, String.format("%d", val)); // Automatically fill in 0's if AM or PM was legally entered. if (isTypedTimeFullyLegal()) { if (!mIs24HourMode && mTypedTimes.size() <= 3) { mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); } mDoneButton.setEnabled(true); } return true; }
Example #9
Source File: DatePickerDialog.java From cathode with Apache License 2.0 | 6 votes |
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())); mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime())); // Accessibility. 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); } }
Example #10
Source File: TimePickerDialog.java From narrate-android with Apache License 2.0 | 6 votes |
private void setHour(int value, boolean announce) { String format; if (mIs24HourMode) { format = "%02d"; } else { format = "%d"; value = value % 12; if (value == 0) { value = 12; } } CharSequence text = String.format(format, value); mHourView.setText(text); mHourSpaceView.setText(text); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, text); } }
Example #11
Source File: TimePickerDialog.java From cathode with Apache License 2.0 | 5 votes |
private void setMinute(int value) { if (value == 60) { value = 0; } CharSequence text = String.format(Locale.getDefault(), "%02d", value); Utils.tryAccessibilityAnnounce(mTimePicker, text); mMinuteView.setText(text); mMinuteSpaceView.setText(text); }
Example #12
Source File: TimePickerDialog.java From cathode with Apache License 2.0 | 5 votes |
private void setCurrentItemShowing(int index, boolean animateCircle, boolean delayLabelAnimate, boolean announce) { mTimePicker.setCurrentItemShowing(index, animateCircle); TextView labelToAnimate; if (index == HOUR_INDEX) { int hours = mTimePicker.getHours(); if (!mIs24HourMode) { hours = hours % 12; } mTimePicker.setContentDescription(mHourPickerDescription + ": " + hours); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectHours); } labelToAnimate = mHourView; } else { int minutes = mTimePicker.getMinutes(); mTimePicker.setContentDescription(mMinutePickerDescription + ": " + minutes); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectMinutes); } labelToAnimate = mMinuteView; } int hourColor = (index == HOUR_INDEX) ? mSelectedColor : mUnselectedColor; int minuteColor = (index == MINUTE_INDEX) ? mSelectedColor : mUnselectedColor; mHourView.setTextColor(hourColor); mMinuteView.setTextColor(minuteColor); ObjectAnimator pulseAnimator = Utils.getPulseAnimator(labelToAnimate, 0.85f, 1.1f); if (delayLabelAnimate) { pulseAnimator.setStartDelay(PULSE_ANIMATOR_DELAY); } pulseAnimator.start(); }
Example #13
Source File: TimePickerDialog.java From cathode with Apache License 2.0 | 5 votes |
private void updateAmPmDisplay(int amOrPm) { if (amOrPm == AM) { mAmPmTextView.setText(mAmText); Utils.tryAccessibilityAnnounce(mTimePicker, mAmText); mAmPmHitspace.setContentDescription(mAmText); } else if (amOrPm == PM) { mAmPmTextView.setText(mPmText); Utils.tryAccessibilityAnnounce(mTimePicker, mPmText); mAmPmHitspace.setContentDescription(mPmText); } else { mAmPmTextView.setText(mDoublePlaceholderText); } }
Example #14
Source File: DatePickerDialog.java From StyleableDateTimePicker with MIT License | 5 votes |
private void adjustDayInMonthIfNeeded(int month, int year) { int day = mCalendar.get(Calendar.DAY_OF_MONTH); int daysInMonth = Utils.getDaysInMonth(month, year); if (day > daysInMonth) { mCalendar.set(Calendar.DAY_OF_MONTH, daysInMonth); } }
Example #15
Source File: TimePickerDialog.java From narrate-android with Apache License 2.0 | 5 votes |
private void updateAmPmDisplay(int amOrPm) { if (amOrPm == AM) { mAmPmTextView.setText(mAmText); Utils.tryAccessibilityAnnounce(mTimePicker, mAmText); mAmPmHitspace.setContentDescription(mAmText); } else if (amOrPm == PM){ mAmPmTextView.setText(mPmText); Utils.tryAccessibilityAnnounce(mTimePicker, mPmText); mAmPmHitspace.setContentDescription(mPmText); } else { mAmPmTextView.setText(mDoublePlaceholderText); } }
Example #16
Source File: TimePickerDialog.java From StyleableDateTimePicker with MIT License | 5 votes |
private boolean addKeyIfLegal(int keyCode) { // If we're in 24hour mode, we'll need to check if the input is full. If in AM/PM mode, // we'll need to see if AM/PM have been typed. if ((mIs24HourMode && mTypedTimes.size() == 4) || (!mIs24HourMode && isTypedTimeFullyLegal())) { return false; } mTypedTimes.add(keyCode); if (!isTypedTimeLegalSoFar()) { deleteLastTypedKey(); return false; } int val = getValFromKeyCode(keyCode); Utils.tryAccessibilityAnnounce(mTimePicker, String.format("%d", val)); // Automatically fill in 0's if AM or PM was legally entered. if (isTypedTimeFullyLegal()) { if (!mIs24HourMode && mTypedTimes.size() <= 3) { mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); } mDoneButton.setEnabled(true); } return true; }
Example #17
Source File: DatePickerDialog.java From cathode with Apache License 2.0 | 5 votes |
private void adjustDayInMonthIfNeeded(int month, int year) { int day = mCalendar.get(Calendar.DAY_OF_MONTH); int daysInMonth = Utils.getDaysInMonth(month, year); if (day > daysInMonth) { mCalendar.set(Calendar.DAY_OF_MONTH, daysInMonth); } }
Example #18
Source File: TimePickerDialog.java From StyleableDateTimePicker with MIT License | 5 votes |
private void setCurrentItemShowing(int index, boolean animateCircle, boolean delayLabelAnimate, boolean announce) { mTimePicker.setCurrentItemShowing(index, animateCircle); TextView labelToAnimate; if (index == HOUR_INDEX) { int hours = mTimePicker.getHours(); if (!mIs24HourMode) { hours = hours % 12; } mTimePicker.setContentDescription(mHourPickerDescription + ": " + hours); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectHours); } labelToAnimate = mHourView; } else { int minutes = mTimePicker.getMinutes(); mTimePicker.setContentDescription(mMinutePickerDescription + ": " + minutes); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectMinutes); } labelToAnimate = mMinuteView; } mHourView.setSelected(index == HOUR_INDEX); mMinuteView.setSelected(index == MINUTE_INDEX); ObjectAnimator pulseAnimator = Utils.getPulseAnimator(labelToAnimate, 0.85f, 1.1f); if (delayLabelAnimate) { pulseAnimator.setStartDelay(PULSE_ANIMATOR_DELAY); } pulseAnimator.start(); }
Example #19
Source File: TimePickerDialog.java From narrate-android with Apache License 2.0 | 5 votes |
private void setMinute(int value) { if (value == 60) { value = 0; } CharSequence text = String.format(Locale.getDefault(), "%02d", value); Utils.tryAccessibilityAnnounce(mTimePicker, text); mMinuteView.setText(text); mMinuteSpaceView.setText(text); }
Example #20
Source File: TimePickerDialog.java From StyleableDateTimePicker with MIT License | 5 votes |
private void updateAmPmDisplay(int amOrPm) { if (amOrPm == AM) { mAmPmTextView.setText(mAmText); Utils.tryAccessibilityAnnounce(mTimePicker, mAmText); mAmPmHitspace.setContentDescription(mAmText); } else if (amOrPm == PM){ mAmPmTextView.setText(mPmText); Utils.tryAccessibilityAnnounce(mTimePicker, mPmText); mAmPmHitspace.setContentDescription(mPmText); } else { mAmPmTextView.setText(mDoublePlaceholderText); } }
Example #21
Source File: TimePickerDialog.java From narrate-android with Apache License 2.0 | 5 votes |
private void setCurrentItemShowing(int index, boolean animateCircle, boolean delayLabelAnimate, boolean announce) { mTimePicker.setCurrentItemShowing(index, animateCircle); TextView labelToAnimate; if (index == HOUR_INDEX) { int hours = mTimePicker.getHours(); if (!mIs24HourMode) { hours = hours % 12; } mTimePicker.setContentDescription(mHourPickerDescription + ": " + hours); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectHours); } labelToAnimate = mHourView; } else { int minutes = mTimePicker.getMinutes(); mTimePicker.setContentDescription(mMinutePickerDescription + ": " + minutes); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectMinutes); } labelToAnimate = mMinuteView; } int hourColor = (index == HOUR_INDEX)? mSelectedColor : mUnselectedColor; int minuteColor = (index == MINUTE_INDEX)? mSelectedColor : mUnselectedColor; mHourView.setTextColor(hourColor); mMinuteView.setTextColor(minuteColor); ObjectAnimator pulseAnimator = Utils.getPulseAnimator(labelToAnimate, 0.85f, 1.1f); if (delayLabelAnimate) { pulseAnimator.setStartDelay(PULSE_ANIMATOR_DELAY); } pulseAnimator.start(); }
Example #22
Source File: CalendarFragment.java From narrate-android with Apache License 2.0 | 5 votes |
private void updateHeaderText() { if ( mLandscape ) { if ( mToolbarTextView != null ) mToolbarTextView.setText(mDateFormat.format(mCalendar.getTime())); } else { String month = mCalendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()); int year = mCalendar.get(Calendar.YEAR); // month & year text mMonthYearHeaderView.setText(String.format("%s %d", month, year)); // week day name text mDayOfWeekHeaderView.setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault())); // day number text boolean dayNumNeedsUpdating = !mDayHeaderView.getText().toString().equals(String.format("%02d", mCalendar.get(Calendar.DAY_OF_MONTH))); if (dayNumNeedsUpdating) { mDayHeaderView.setText(String.format("%02d", mCalendar.get(Calendar.DAY_OF_MONTH))); ObjectAnimator pulseAnimator = Utils.getPulseAnimator(mDayHeaderView, 0.9f, 1.05f); pulseAnimator.start(); } } }
Example #23
Source File: CalendarFragment.java From narrate-android with Apache License 2.0 | 5 votes |
private void adjustDayInMonthIfNeeded(int month, int year) { int day = mCalendar.get(Calendar.DAY_OF_MONTH); int daysInMonth = Utils.getDaysInMonth(month, year); if (day > daysInMonth) { mCalendar.set(Calendar.DAY_OF_MONTH, daysInMonth); } }
Example #24
Source File: DatePickerDialog.java From narrate-android with Apache License 2.0 | 5 votes |
private void adjustDayInMonthIfNeeded(int month, int year) { int day = mCalendar.get(Calendar.DAY_OF_MONTH); int daysInMonth = Utils.getDaysInMonth(month, year); if (day > daysInMonth) { mCalendar.set(Calendar.DAY_OF_MONTH, daysInMonth); } }
Example #25
Source File: TimePickerDialog.java From StyleableDateTimePicker with MIT License | 5 votes |
private void setMinute(int value) { if (value == 60) { value = 0; } CharSequence text = String.format(Locale.getDefault(), "%02d", value); Utils.tryAccessibilityAnnounce(mTimePicker, text); mMinuteView.setText(text); mMinuteSpaceView.setText(text); }
Example #26
Source File: TimePickerDialog.java From narrate-android with Apache License 2.0 | 5 votes |
private boolean addKeyIfLegal(int keyCode) { // If we're in 24hour mode, we'll need to check if the input is full. If in AM/PM mode, // we'll need to see if AM/PM have been typed. if ((mIs24HourMode && mTypedTimes.size() == 4) || (!mIs24HourMode && isTypedTimeFullyLegal())) { return false; } mTypedTimes.add(keyCode); if (!isTypedTimeLegalSoFar()) { deleteLastTypedKey(); return false; } int val = getValFromKeyCode(keyCode); Utils.tryAccessibilityAnnounce(mTimePicker, String.format("%d", val)); // Automatically fill in 0's if AM or PM was legally entered. if (isTypedTimeFullyLegal()) { if (!mIs24HourMode && mTypedTimes.size() <= 3) { mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0); } mDoneButton.setEnabled(true); } return true; }
Example #27
Source File: DatePickerDialog.java From narrate-android with Apache License 2.0 | 4 votes |
private void setCurrentView(final int viewIndex) { long millis = mCalendar.getTimeInMillis(); switch (viewIndex) { case MONTH_AND_DAY_VIEW: ObjectAnimator pulseAnimator = Utils.getPulseAnimator(mMonthAndDayView, 0.9f, 1.05f); if (mDelayAnimation) { pulseAnimator.setStartDelay(ANIMATION_DELAY); mDelayAnimation = false; } mDayPickerView.onDateChanged(); if (mCurrentView != viewIndex) { mMonthAndDayView.setSelected(true); mYearView.setSelected(false); mAnimator.setDisplayedChild(MONTH_AND_DAY_VIEW); mCurrentView = viewIndex; } pulseAnimator.start(); int flags = DateUtils.FORMAT_SHOW_DATE; String dayString = DateUtils.formatDateTime(getActivity(), millis, flags); mAnimator.setContentDescription(mDayPickerDescription+": "+dayString); Utils.tryAccessibilityAnnounce(mAnimator, mSelectDay); break; case YEAR_VIEW: pulseAnimator = Utils.getPulseAnimator(mYearView, 0.85f, 1.1f); if (mDelayAnimation) { pulseAnimator.setStartDelay(ANIMATION_DELAY); mDelayAnimation = false; } mYearPickerView.onDateChanged(); if (mCurrentView != viewIndex) { mMonthAndDayView.setSelected(false); mYearView.setSelected(true); mAnimator.setDisplayedChild(YEAR_VIEW); mCurrentView = viewIndex; } pulseAnimator.start(); CharSequence yearString = YEAR_FORMAT.format(millis); mAnimator.setContentDescription(mYearPickerDescription+": "+yearString); Utils.tryAccessibilityAnnounce(mAnimator, mSelectYear); break; } }
Example #28
Source File: DatePickerDialog.java From cathode with Apache License 2.0 | 4 votes |
private void setCurrentView(final int viewIndex) { long millis = mCalendar.getTimeInMillis(); switch (viewIndex) { case MONTH_AND_DAY_VIEW: ObjectAnimator pulseAnimator = Utils.getPulseAnimator(mMonthAndDayView, 0.9f, 1.05f); if (mDelayAnimation) { pulseAnimator.setStartDelay(ANIMATION_DELAY); mDelayAnimation = false; } mDayPickerView.onDateChanged(); if (mCurrentView != viewIndex) { mMonthAndDayView.setSelected(true); mYearView.setSelected(false); mAnimator.setDisplayedChild(MONTH_AND_DAY_VIEW); mCurrentView = viewIndex; } pulseAnimator.start(); int flags = DateUtils.FORMAT_SHOW_DATE; String dayString = DateUtils.formatDateTime(getActivity(), millis, flags); mAnimator.setContentDescription(mDayPickerDescription + ": " + dayString); Utils.tryAccessibilityAnnounce(mAnimator, mSelectDay); break; case YEAR_VIEW: pulseAnimator = Utils.getPulseAnimator(mYearView, 0.85f, 1.1f); if (mDelayAnimation) { pulseAnimator.setStartDelay(ANIMATION_DELAY); mDelayAnimation = false; } mYearPickerView.onDateChanged(); if (mCurrentView != viewIndex) { mMonthAndDayView.setSelected(false); mYearView.setSelected(true); mAnimator.setDisplayedChild(YEAR_VIEW); mCurrentView = viewIndex; } pulseAnimator.start(); CharSequence yearString = YEAR_FORMAT.format(millis); mAnimator.setContentDescription(mYearPickerDescription + ": " + yearString); Utils.tryAccessibilityAnnounce(mAnimator, mSelectYear); break; } }
Example #29
Source File: MonthView.java From cathode with Apache License 2.0 | 4 votes |
/** * Sets all the parameters for displaying this week. The only required * parameter is the week number. Other parameters have a default value and * will only update if a new value is included, except for focus month, * which will always default to no focus month if no value is passed in. See * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters. * * @param params A map of the new parameters, see * {@link #VIEW_PARAMS_HEIGHT} */ public void setMonthParams(HashMap<String, Integer> params) { if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) { throw new InvalidParameterException("You must specify month and year for this view"); } setTag(params); // We keep the current value for any params not present if (params.containsKey(VIEW_PARAMS_HEIGHT)) { mRowHeight = params.get(VIEW_PARAMS_HEIGHT); if (mRowHeight < MIN_HEIGHT) { mRowHeight = MIN_HEIGHT; } } if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) { mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY); } // Allocate space for caching the day numbers and focus values mMonth = params.get(VIEW_PARAMS_MONTH); mYear = params.get(VIEW_PARAMS_YEAR); // Figure out what day today is final Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); mHasToday = false; mToday = -1; mCalendar.set(Calendar.MONTH, mMonth); mCalendar.set(Calendar.YEAR, mYear); mCalendar.set(Calendar.DAY_OF_MONTH, 1); mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK); if (params.containsKey(VIEW_PARAMS_WEEK_START)) { mWeekStart = params.get(VIEW_PARAMS_WEEK_START); } else { mWeekStart = mCalendar.getFirstDayOfWeek(); } mNumCells = Utils.getDaysInMonth(mMonth, mYear); for (int i = 0; i < mNumCells; i++) { final int day = i + 1; if (sameDay(day, today)) { mHasToday = true; mToday = day; } } mNumRows = calculateNumRows(); // Invalidate cached accessibility information. mTouchHelper.invalidateRoot(); }
Example #30
Source File: TimePickerDialog.java From narrate-android with Apache License 2.0 | 4 votes |
/** * For keyboard mode, processes key events. * @param keyCode the pressed key. * @return true if the key was successfully processed, false otherwise. */ private boolean processKeyUp(int keyCode) { if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) { dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_TAB) { if(mInKbMode) { if (isTypedTimeFullyLegal()) { finishKbMode(true); } return true; } } else if (keyCode == KeyEvent.KEYCODE_ENTER) { if (mInKbMode) { if (!isTypedTimeFullyLegal()) { return true; } finishKbMode(false); } if (mCallback != null) { mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes()); } dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_DEL) { if (mInKbMode) { if (!mTypedTimes.isEmpty()) { int deleted = deleteLastTypedKey(); String deletedKeyStr; if (deleted == getAmOrPmKeyCode(AM)) { deletedKeyStr = mAmText; } else if (deleted == getAmOrPmKeyCode(PM)) { deletedKeyStr = mPmText; } else { deletedKeyStr = String.format("%d", getValFromKeyCode(deleted)); } Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr)); updateDisplay(true); } } } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5 || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9 || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) { if (!mInKbMode) { if (mTimePicker == null) { // Something's wrong, because time picker should definitely not be null. Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null."); return true; } mTypedTimes.clear(); tryStartingKbMode(keyCode); return true; } // We're already in keyboard mode. if (addKeyIfLegal(keyCode)) { updateDisplay(false); } return true; } return false; }