/** * Select a new date. Respects the {@link SelectionMode} this CalendarPickerView is configured * with: if you are in {@link SelectionMode#SINGLE}, the previously selected date will be * un-selected. In {@link SelectionMode#MULTIPLE}, the new date will be added to the list of * selected dates. * * <p>If the selection was made (selectable date, in range), the view will scroll to the newly * selected date if it's not already visible. * * @return - whether we were able to set the date */ public boolean selectDate(Date date) { validateDate(date); MonthCellWithMonthIndex monthCellWithMonthIndex = getMonthCellWithIndexByDate(date); if (monthCellWithMonthIndex == null || !isDateSelectable(date)) { return false; } boolean wasSelected = doSelectDate(date, monthCellWithMonthIndex.cell); if (wasSelected) { scrollToSelectedMonth(monthCellWithMonthIndex.monthIndex); } return wasSelected; }
private void scrollToSelectedDates() { Integer selectedIndex = null; Integer todayIndex = null; Calendar today = Calendar.getInstance(locale); for (int c = 0; c < months.size(); c++) { MonthDescriptor month = months.get(c); if (selectedIndex == null) { for (Calendar selectedCal : selectedCals) { if (sameMonth(selectedCal, month)) { selectedIndex = c; break; } } if (selectedIndex == null && todayIndex == null && sameMonth(today, month)) { todayIndex = c; } } } if (selectedIndex != null) { scrollToSelectedMonth(selectedIndex); } else if (todayIndex != null) { scrollToSelectedMonth(todayIndex); } }