public void setEnableSwipe(boolean enableSwipe) { this.enableSwipe = enableSwipe; dateViewPager.setEnabled(enableSwipe); }
/** * Setup 4 pages contain date grid views. These pages are recycled to use memory efficient * * @param view */ private void setupDateGridPages(View view) { // Get current date time DateTime currentDateTime = new DateTime(year, month + 1, 1, 0, 0, 0, 0); // Set to pageChangeListener pageChangeListener = new DatePageChangeListener(); pageChangeListener.setCurrentDateTime(currentDateTime); // Setup adapters for the grid views // Current month CaldroidGridAdapter adapter0 = getNewDatesGridAdapter(currentDateTime.getMonth(), currentDateTime.getYear()); // Setup dateInMonthsList dateInMonthsList = adapter0.getDatetimeList(); // Next month DateTime nextDateTime = currentDateTime.plus(0, 1, 0, 0, 0, 0, 0, DateTime.DayOverflow.LastDay); CaldroidGridAdapter adapter1 = getNewDatesGridAdapter(nextDateTime.getMonth(), nextDateTime.getYear()); // Next 2 month DateTime next2DateTime = nextDateTime.plus(0, 1, 0, 0, 0, 0, 0, DateTime.DayOverflow.LastDay); CaldroidGridAdapter adapter2 = getNewDatesGridAdapter(next2DateTime.getMonth(), next2DateTime.getYear()); // Previous month DateTime prevDateTime = currentDateTime.minus(0, 1, 0, 0, 0, 0, 0, DateTime.DayOverflow.LastDay); CaldroidGridAdapter adapter3 = getNewDatesGridAdapter(prevDateTime.getMonth(), prevDateTime.getYear()); // Add to the array of adapters datePagerAdapters.add(adapter0); datePagerAdapters.add(adapter1); datePagerAdapters.add(adapter2); datePagerAdapters.add(adapter3); // Set adapters to the pageChangeListener so it can refresh the adapter // when page change pageChangeListener.setCaldroidGridAdapters(datePagerAdapters); // Setup InfiniteViewPager and InfinitePagerAdapter. The // InfinitePagerAdapter is responsible // for reuse the fragments dateViewPager = (InfiniteViewPager) view.findViewById(R.id.months_infinite_pager); // Set enable swipe dateViewPager.setEnabled(enableSwipe); // Set if viewpager wrap around particular month or all months (6 rows) dateViewPager.setSixWeeksInCalendar(sixWeeksInCalendar); // Set the numberOfDaysInMonth to dateViewPager so it can calculate the // height correctly dateViewPager.setDatesInMonth(dateInMonthsList); // MonthPagerAdapter actually provides 4 real fragments. The // InfinitePagerAdapter only recycles fragment provided by this // MonthPagerAdapter final MonthPagerAdapter pagerAdapter = new MonthPagerAdapter(getChildFragmentManager()); // Provide initial data to the fragments, before they are attached to // view. fragments = pagerAdapter.getFragments(); for (int i = 0; i < NUMBER_OF_PAGES; i++) { DateGridFragment dateGridFragment = fragments.get(i); CaldroidGridAdapter adapter = datePagerAdapters.get(i); dateGridFragment.setGridAdapter(adapter); dateGridFragment.setOnItemClickListener(getDateItemClickListener()); dateGridFragment.setOnItemLongClickListener(getDateItemLongClickListener()); } // Setup InfinitePagerAdapter to wrap around MonthPagerAdapter InfinitePagerAdapter infinitePagerAdapter = new InfinitePagerAdapter(pagerAdapter); // Use the infinitePagerAdapter to provide data for dateViewPager dateViewPager.setAdapter(infinitePagerAdapter); // Setup pageChangeListener dateViewPager.setOnPageChangeListener(pageChangeListener); }