/** * Move calendar to specified dateTime, with animation * * @param dateTime */ public void moveToDateTime(DateTime dateTime) { DateTime firstOfMonth = new DateTime(year, month, 1, 0, 0, 0, 0); DateTime lastOfMonth = firstOfMonth.getEndOfMonth(); // To create a swipe effect // Do nothing if the dateTime is in current month // Calendar swipe left when dateTime is in the past if (dateTime.lt(firstOfMonth)) { // Get next month of dateTime. When swipe left, month will // decrease DateTime firstDayNextMonth = dateTime.plus(0, 1, 0, 0, 0, 0, 0, DateTime.DayOverflow.LastDay); // Refresh adapters pageChangeListener.setCurrentDateTime(firstDayNextMonth); int currentItem = dateViewPager.getCurrentItem(); pageChangeListener.refreshAdapters(currentItem); // Swipe left dateViewPager.setCurrentItem(currentItem - 1); } // Calendar swipe right when dateTime is in the future else if (dateTime.gt(lastOfMonth)) { // Get last month of dateTime. When swipe right, the month will // increase DateTime firstDayLastMonth = dateTime.minus(0, 1, 0, 0, 0, 0, 0, DateTime.DayOverflow.LastDay); // Refresh adapters pageChangeListener.setCurrentDateTime(firstDayLastMonth); int currentItem = dateViewPager.getCurrentItem(); pageChangeListener.refreshAdapters(currentItem); // Swipe right dateViewPager.setCurrentItem(currentItem + 1); } }
/** Get current virtual position of the month being viewed */ public int getCurrentVirtualPosition() { int currentPage = dateViewPager.getCurrentItem(); return pageChangeListener.getCurrent(currentPage); }