/** * This is abhorrent... * * @return * @throws NoSuchFieldException * @throws IllegalAccessException * @throws NoSuchMethodException * @throws InvocationTargetException */ @Deprecated private int getWeekCountBasedOnMode() throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { Field calendarModeField = MaterialCalendarView.class.getDeclaredField("calendarMode"); calendarModeField.setAccessible(true); CalendarMode calendarMode = (CalendarMode) calendarModeField.get(this); Field mDynamicHeightEnabledField = MaterialCalendarView.class.getDeclaredField("mDynamicHeightEnabled"); mDynamicHeightEnabledField.setAccessible(true); boolean mDynamicHeightEnabled = (boolean) mDynamicHeightEnabledField.get(this); Field adapterField = MaterialCalendarView.class.getDeclaredField("adapter"); adapterField.setAccessible(true); Object adapter = adapterField.get(this); Field pagerField = MaterialCalendarView.class.getDeclaredField("pager"); pagerField.setAccessible(true); BetterViewPager pager = (BetterViewPager) pagerField.get(this); Field weekCountField = CalendarMode.class.getDeclaredField("visibleWeeksCount"); weekCountField.setAccessible(true); int weekCount = (int) weekCountField.get(calendarMode); boolean isInMonthsMode = calendarMode.equals(CalendarMode.MONTHS); if (isInMonthsMode && mDynamicHeightEnabled && adapter != null && pager != null) { Method getItemMethod = adapter.getClass().getDeclaredMethod("getItem", CalendarDay.class); Object currentItem = getItemMethod.invoke(adapter, pager.getClass().getMethod("getCurrentItem").invoke(pager)); Calendar cal = (Calendar) currentItem.getClass().getMethod("getCalendar").invoke(currentItem); cal = (Calendar) cal.clone(); //(Calendar) adapter.getItem(pager.getCurrentItem()).getCalendar().clone(); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); //noinspection ResourceType cal.setFirstDayOfWeek(getFirstDayOfWeek()); weekCount = cal.get(Calendar.WEEK_OF_MONTH); } return weekCount + DAY_NAMES_ROW; }