use of hirondelle.date4j.DateTime in project Caldroid by roomorama.
the class CaldroidFragment method setBackgroundDrawableForDates.
/**
* Set backgroundForDateMap
*/
public void setBackgroundDrawableForDates(Map<Date, Drawable> backgroundForDateMap) {
if (backgroundForDateMap == null || backgroundForDateMap.size() == 0) {
return;
}
backgroundForDateTimeMap.clear();
for (Date date : backgroundForDateMap.keySet()) {
Drawable drawable = backgroundForDateMap.get(date);
DateTime dateTime = CalendarHelper.convertDateToDateTime(date);
backgroundForDateTimeMap.put(dateTime, drawable);
}
}
use of hirondelle.date4j.DateTime in project Caldroid by roomorama.
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();
CalendarHelper.setup();
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, null);
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, null);
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);
}
// Get theme
themeResource = args.getInt(THEME_RESOURCE, R.style.CaldroidDefault);
}
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 CalendarListRecyclerAdapter method countDateInEvents.
/**
* Small helper method for getExtraData(), determines how many events coincide with each date.
*
* @param d
* @return
*/
private int countDateInEvents(Date d) {
int count = 0;
DateTime dateTime = DateTime.forInstant(d.getTime(), TimeZone.getDefault());
for (ScheduleItem scheduleItem : mAllEvents) {
DateTime compareDate = DateTime.forInstant(scheduleItem.getStartAt().getTime(), TimeZone.getDefault());
if (dateTime.getMonth().equals(compareDate.getMonth()) && dateTime.getDay().equals(compareDate.getDay()) && dateTime.getYear().equals(compareDate.getYear())) {
count++;
}
}
return count;
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CalendarListRecyclerAdapter method getExtraData.
/**
* A small helper method used to create a data list for use in getView for the calendar grid
* used to determine when dates have events and how many.
*/
private void getExtraData() {
HashMap<String, Object> hashMap = mAdapterToCalendarCallback.getExtraCalendarData();
ArrayList<EventData> eventList = new ArrayList<>();
// flush mAllEvents
HashSet<ScheduleItem> hs = new HashSet<>();
hs.addAll(mAllEvents);
mAllEvents.clear();
mAllEvents.addAll(hs);
// todo optimize
for (ScheduleItem s : mAllEvents) {
Date d = s.getStartAt();
DateTime dateTime = DateTime.forInstant(d.getTime(), TimeZone.getDefault());
int dateCount = countDateInEvents(d);
if (dateCount == 1) {
// ExtraData(date, number of events)
eventList.add(new EventData(dateTime, EventData.EventCount.MIN));
} else if (dateCount >= 2 && dateCount <= 5) {
eventList.add(new EventData(dateTime, EventData.EventCount.MID));
} else {
eventList.add(new EventData(dateTime, EventData.EventCount.MAX));
}
}
hashMap.put(Const.EVENT_LIST, eventList);
mAdapterToCalendarCallback.refreshCalendarFragment();
refreshListView();
mAdapterToCalendarCallback.hidePandaLoading();
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CalendarListRecyclerAdapter method getStartDate.
private Calendar getStartDate() {
int startDay = getStartDayOfWeek();
Calendar cal = Calendar.getInstance();
ArrayList<DateTime> dates = CalendarHelper.getFullWeeks(mSelectedDay.getMonth(), mSelectedDay.getYear(), startDay, false);
DateTime startDate = dates.get(0);
cal.set(startDate.getYear(), startDate.getMonth() - 1, startDate.getDay(), startDate.getHour(), startDate.getMinute(), startDate.getSecond());
return cal;
}
Aggregations