use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CalendarListViewFragment method setUpListeners.
private void setUpListeners() {
final CaldroidListener listener = new CaldroidListener() {
@Override
public void onSelectDate(Date date, View view) {
// New date selected, clear out prior
mCalendarFragment.clearSelectedDates();
mRecyclerAdapter.setSelectedDay(DateTime.forInstant(date.getTime(), TimeZone.getDefault()));
if (currentCalendarView == CalendarView.DAY_VIEW) {
mCalendarFragment.setSelectedDates(date, date);
} else if (currentCalendarView == CalendarView.WEEK_VIEW) {
DateWindow dateWindow = CanvasCalendarUtils.setSelectedWeekWindow(date, mRecyclerAdapter.isStartDayMonday());
mCalendarFragment.setSelectedDates(dateWindow.getStart(), dateWindow.getEnd());
}
mCalendarFragment.refreshView();
mRecyclerAdapter.refreshListView();
}
@Override
public void onCaldroidViewCreated() {
super.onCaldroidViewCreated();
// Removing styling for upper buttons
Button leftButton = mCalendarFragment.getLeftArrowButton();
Button rightButton = mCalendarFragment.getRightArrowButton();
TextView textView = mCalendarFragment.getMonthTitleTextView();
leftButton.setVisibility(View.GONE);
rightButton.setVisibility(View.GONE);
textView.setVisibility(View.GONE);
// Initialize post view created mCalendarFragment elements
InfiniteViewPager viewPager = mCalendarFragment.getDateViewPager();
viewPager.setPageMargin((int) ViewUtils.convertDipsToPixels(32, getContext()));
if (mRecyclerAdapter.getSelectedDay() == null) {
mRecyclerAdapter.setSelectedDay(DateTime.today(TimeZone.getDefault()));
Date today = new Date(mRecyclerAdapter.getSelectedDay().getMilliseconds(TimeZone.getDefault()));
mCalendarFragment.setSelectedDates(today, today);
}
mRecyclerAdapter.setCalendarViewCreated(true);
applyTheme();
}
@Override
public void onChangeMonth(int month, int year, boolean fromCreation) {
super.onChangeMonth(month, year, fromCreation);
if (mRecyclerAdapter != null && mRecyclerAdapter.getSelectedDay() != null && month == mRecyclerAdapter.getSelectedDay().getMonth()) {
// listener. We don't want to trigger the month change logic if the month is not changing.
return;
}
if (mMonthText != null) {
if (fromCreation || hasOrientationChanged()) {
hidePanda();
return;
}
// Update Actionbar
mMonthText.setText(new DateFormatSymbols().getMonths()[month - 1] + " " + year);
}
// First time loading the calendar will trigger this, but the API calls have already been made
if (!mRecyclerAdapter.isTodayPressed() && !fromCreation) {
// Refresh for month, unless this was triggered by "today" button
mCalendarFragment.clearSelectedDates();
DateTime today = DateTime.today(TimeZone.getDefault());
if (today.getMonth() == month && today.getYear() == year) {
mRecyclerAdapter.setSelectedDay(today);
} else {
mRecyclerAdapter.setSelectedDay(new DateTime(year, month, 1, null, null, null, null));
}
mRecyclerAdapter.refreshCalendar();
}
}
};
mCalendarFragment.setCaldroidListener(listener);
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CanvasCalendarGridAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View cellView = convertView;
// Grabs list of ExtraData objects for events
ArrayList<EventData> eventList = (ArrayList<EventData>) extraData.get(Const.EVENT_LIST);
if (convertView == null) {
cellView = inflater.inflate(R.layout.calendar_grid_textview, null);
}
TextView tv1 = (TextView) cellView.findViewById(R.id.tv1);
// Get dateTime of this cell
DateTime dateTime = this.datetimeList.get(position);
boolean noEvent = false;
boolean notSelected = false;
EventData.EventCount eventCount = EventData.EventCount.NONE;
// Customize for dates with events
if (eventList != null && eventList.size() > 0) {
EventData eventData = getExtraData(eventList, dateTime);
if (eventData != null) {
eventCount = eventData.getEventCount();
switch(eventCount) {
case MIN:
tv1.setBackgroundResource(R.drawable.calendar_min_events);
break;
case MID:
tv1.setBackgroundResource(R.drawable.calendar_mid_events);
break;
case MAX:
tv1.setBackgroundResource(R.drawable.calendar_max_events);
break;
}
} else {
noEvent = true;
}
} else {
noEvent = true;
}
// Customize for selected dates
if (selectedDates != null && selectedDates.indexOf(dateTime) != -1) {
switch(eventCount) {
case NONE:
tv1.setBackgroundResource(R.drawable.calendar_selected_event);
break;
case MIN:
tv1.setBackgroundResource(R.drawable.calendar_selected_min_events);
break;
case MID:
tv1.setBackgroundResource(R.drawable.calendar_selected_mid_events);
break;
case MAX:
tv1.setBackgroundResource(R.drawable.calendar_selected_max_events);
break;
}
} else {
notSelected = true;
}
// If a date is not selected or has no events we will reset the background resource
if (noEvent && notSelected) {
tv1.setBackgroundResource(0);
}
// select "today"
if (dateTime.equals(getToday())) {
if (!notSelected && !noEvent) {
switch(eventCount) {
case NONE:
tv1.setBackgroundResource(R.drawable.calendar_today_selected);
break;
case MIN:
tv1.setBackgroundResource(R.drawable.calendar_today_selected_min_events);
break;
case MID:
tv1.setBackgroundResource(R.drawable.calendar_today_selected_mid_events);
break;
case MAX:
tv1.setBackgroundResource(R.drawable.calendar_today_selected_max_events);
break;
}
} else if (!notSelected) {
tv1.setBackgroundResource(R.drawable.calendar_today_selected);
} else if (!noEvent) {
switch(eventCount) {
case MIN:
tv1.setBackgroundResource(R.drawable.calendar_today_min_events);
break;
case MID:
tv1.setBackgroundResource(R.drawable.calendar_today_mid_events);
break;
case MAX:
tv1.setBackgroundResource(R.drawable.calendar_today_max_events);
break;
}
} else {
tv1.setBackgroundResource(R.drawable.calendar_today);
}
}
// Set color of the dates in previous / next month
// if (dateTime.getMonth() != month) {
// tv1.setTextColor(resources
// .getColor(com.caldroid.R.color.caldroid_darker_gray));
// }
tv1.setText("" + dateTime.getDay());
return cellView;
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CaldroidFragment method setupDateGridPages.
/**
* Setup 4 pages contain date grid views. These pages are recycled to use
* memory efficient
*
* @param view
*/
private void setupDateGridPages(View view, boolean fromCreation) {
// Get current date time
DateTime currentDateTime = new DateTime(year, month, 1, 0, 0, 0, 0);
// Set to pageChangeListener
if (pageChangeListener == null && month != -1) {
// checks for rotation
pageChangeListener = new DatePageChangeListener();
}
pageChangeListener.setCurrentDateTime(currentDateTime, fromCreation);
// 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.setGridViewRes(getGridViewRes());
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.addOnPageChangeListener(pageChangeListener);
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CaldroidFragment method retrieveInitialArgs.
/**
* Retrieve initial arguments to the fragment Data can include: month, year,
* dialogTitle, showNavigationArrows,(String) disableDates, selectedDates,
* minDate, maxDate, squareTextViewCell
*/
protected void retrieveInitialArgs() {
// Get arguments
Bundle args = getArguments();
if (args != null) {
// Get month, year
month = args.getInt(MONTH, -1);
year = args.getInt(YEAR, -1);
dialogTitle = args.getString(DIALOG_TITLE);
Dialog dialog = getDialog();
if (dialog != null) {
if (dialogTitle != null) {
dialog.setTitle(dialogTitle);
} else {
// Don't display title bar if user did not supply
// dialogTitle
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
}
}
// Get start day of Week. Default calendar first column is SUNDAY
startDayOfWeek = args.getInt(START_DAY_OF_WEEK, 1);
if (startDayOfWeek > 7) {
startDayOfWeek = startDayOfWeek % 7;
}
// Should show arrow
showNavigationArrows = args.getBoolean(SHOW_NAVIGATION_ARROWS, true);
// Should enable swipe to change month
enableSwipe = args.getBoolean(ENABLE_SWIPE, true);
// Get sixWeeksInCalendar
sixWeeksInCalendar = args.getBoolean(SIX_WEEKS_IN_CALENDAR, true);
// Get squareTextViewCell, by default, use square cell in portrait mode
// and using normal cell in landscape mode
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
squareTextViewCell = args.getBoolean(SQUARE_TEXT_VIEW_CELL, true);
} else {
squareTextViewCell = args.getBoolean(SQUARE_TEXT_VIEW_CELL, false);
}
// Get clickable setting
enableClickOnDisabledDates = args.getBoolean(ENABLE_CLICK_ON_DISABLED_DATES, false);
// Get disable dates
ArrayList<String> disableDateStrings = args.getStringArrayList(DISABLE_DATES);
if (disableDateStrings != null && disableDateStrings.size() > 0) {
disableDates.clear();
for (String dateString : disableDateStrings) {
DateTime dt = CalendarHelper.getDateTimeFromString(dateString, "yyyy-MM-dd");
disableDates.add(dt);
}
}
// Get selected dates
ArrayList<String> selectedDateStrings = args.getStringArrayList(SELECTED_DATES);
if (selectedDateStrings != null && selectedDateStrings.size() > 0) {
selectedDates.clear();
for (String dateString : selectedDateStrings) {
DateTime dt = CalendarHelper.getDateTimeFromString(dateString, "yyyy-MM-dd");
selectedDates.add(dt);
}
}
// Get min date and max date
String minDateTimeString = args.getString(MIN_DATE);
if (minDateTimeString != null) {
minDateTime = CalendarHelper.getDateTimeFromString(minDateTimeString, null);
}
String maxDateTimeString = args.getString(MAX_DATE);
if (maxDateTimeString != null) {
maxDateTime = CalendarHelper.getDateTimeFromString(maxDateTimeString, null);
}
}
if (month == -1 || year == -1) {
DateTime dateTime = DateTime.today(TimeZone.getDefault());
month = dateTime.getMonth();
year = dateTime.getYear();
}
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CaldroidFragment method setBackgroundResourceForDate.
public void setBackgroundResourceForDate(int backgroundRes, Date date) {
DateTime dateTime = CalendarHelper.convertDateToDateTime(date);
backgroundForDateTimeMap.put(dateTime, Integer.valueOf(backgroundRes));
}
Aggregations