use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CaldroidFragment method setDisableDates.
/**
* Set disableDates from ArrayList of Date
*
* @param disableDateList
*/
public void setDisableDates(ArrayList<Date> disableDateList) {
if (disableDateList == null || disableDateList.size() == 0) {
return;
}
disableDates.clear();
for (Date date : disableDateList) {
DateTime dateTime = CalendarHelper.convertDateToDateTime(date);
disableDates.add(dateTime);
}
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CaldroidFragment method setTextColorForDate.
public void setTextColorForDate(int textColorRes, Date date) {
DateTime dateTime = CalendarHelper.convertDateToDateTime(date);
textColorForDateTimeMap.put(dateTime, Integer.valueOf(textColorRes));
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CaldroidGridAdapter method populateFromCaldroidData.
/**
* Retrieve internal parameters from caldroid data
*/
@SuppressWarnings("unchecked")
private void populateFromCaldroidData() {
disableDates = (ArrayList<DateTime>) caldroidData.get(CaldroidFragment.DISABLE_DATES);
if (disableDates != null) {
disableDatesMap.clear();
for (DateTime dateTime : disableDates) {
disableDatesMap.put(dateTime, 1);
}
}
selectedDates = (ArrayList<DateTime>) caldroidData.get(CaldroidFragment.SELECTED_DATES);
if (selectedDates != null) {
selectedDatesMap.clear();
for (DateTime dateTime : selectedDates) {
selectedDatesMap.put(dateTime, 1);
}
}
minDateTime = (DateTime) caldroidData.get(CaldroidFragment._MIN_DATE_TIME);
maxDateTime = (DateTime) caldroidData.get(CaldroidFragment._MAX_DATE_TIME);
startDayOfWeek = (Integer) caldroidData.get(CaldroidFragment.START_DAY_OF_WEEK);
sixWeeksInCalendar = (Boolean) caldroidData.get(CaldroidFragment.SIX_WEEKS_IN_CALENDAR);
squareTextViewCell = (Boolean) caldroidData.get(CaldroidFragment.SQUARE_TEXT_VIEW_CELL);
this.datetimeList = CalendarHelper.getFullWeeks(this.month, this.year, startDayOfWeek, sixWeeksInCalendar);
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CaldroidGridAdapter method customizeTextView.
/**
* Customize colors of text and background based on states of the cell
* (disabled, active, selected, etc)
* <p/>
* To be used only in getView method
*
* @param position
* @param cellView
*/
protected void customizeTextView(int position, TextView cellView) {
cellView.setTextColor(Color.BLACK);
// Get the padding of cell so that it can be restored later
int topPadding = cellView.getPaddingTop();
int leftPadding = cellView.getPaddingLeft();
int bottomPadding = cellView.getPaddingBottom();
int rightPadding = cellView.getPaddingRight();
// Get dateTime of this cell
DateTime dateTime = this.datetimeList.get(position);
// Set color of the dates in previous / next month
if (dateTime.getMonth() != month) {
cellView.setTextColor(resources.getColor(R.color.caldroid_darker_gray));
}
boolean shouldResetDiabledView = false;
boolean shouldResetSelectedView = false;
// Customize for disabled dates and date outside min/max dates
if ((minDateTime != null && dateTime.lt(minDateTime)) || (maxDateTime != null && dateTime.gt(maxDateTime)) || (disableDates != null && disableDatesMap.containsKey(dateTime))) {
cellView.setTextColor(CaldroidFragment.disabledTextColor);
if (CaldroidFragment.disabledBackgroundDrawable == -1) {
cellView.setBackgroundResource(R.drawable.disable_cell);
} else {
cellView.setBackgroundResource(CaldroidFragment.disabledBackgroundDrawable);
}
if (dateTime.equals(getToday())) {
cellView.setBackgroundResource(R.drawable.red_border_gray_bg);
}
} else {
shouldResetDiabledView = true;
}
// Customize for selected dates
if (selectedDates != null && selectedDatesMap.containsKey(dateTime)) {
if (CaldroidFragment.selectedBackgroundDrawable != -1) {
cellView.setBackgroundResource(CaldroidFragment.selectedBackgroundDrawable);
} else {
cellView.setBackgroundColor(resources.getColor(R.color.caldroid_sky_blue));
}
cellView.setTextColor(CaldroidFragment.selectedTextColor);
} else {
shouldResetSelectedView = true;
}
if (shouldResetDiabledView && shouldResetSelectedView) {
// Customize for today
if (dateTime.equals(getToday())) {
cellView.setBackgroundResource(R.drawable.red_border);
} else {
cellView.setBackgroundResource(R.drawable.cell_bg);
}
}
// Set text
cellView.setText("" + dateTime.getDay());
// Set custom color if required
setCustomResources(dateTime, cellView, cellView);
// Somehow after setBackgroundResource, the padding collapse.
// This is to recover the padding
cellView.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
}
use of hirondelle.date4j.DateTime in project instructure-android by instructure.
the class CalendarHelper method getFullWeeks.
/**
* Retrieve all the dates for a given calendar month Include previous month,
* current month and next month.
*
* @param month
* @param year
* @param startDayOfWeek : calendar can start from customized date instead of Sunday
* @return
*/
public static ArrayList<DateTime> getFullWeeks(int month, int year, int startDayOfWeek, boolean sixWeeksInCalendar) {
ArrayList<DateTime> datetimeList = new ArrayList<DateTime>();
DateTime firstDateOfMonth = new DateTime(year, month, 1, 0, 0, 0, 0);
DateTime lastDateOfMonth = firstDateOfMonth.plusDays(firstDateOfMonth.getNumDaysInMonth() - 1);
// Add dates of first week from previous month
int weekdayOfFirstDate = firstDateOfMonth.getWeekDay();
// increase the weekday of FirstDate because it's in the future
if (weekdayOfFirstDate < startDayOfWeek) {
weekdayOfFirstDate += 7;
}
while (weekdayOfFirstDate > 0) {
DateTime dateTime = firstDateOfMonth.minusDays(weekdayOfFirstDate - startDayOfWeek);
if (!dateTime.lt(firstDateOfMonth)) {
break;
}
datetimeList.add(dateTime);
weekdayOfFirstDate--;
}
// Add dates of current month
for (int i = 0; i < lastDateOfMonth.getDay(); i++) {
datetimeList.add(firstDateOfMonth.plusDays(i));
}
// Add dates of last week from next month
int endDayOfWeek = startDayOfWeek - 1;
if (endDayOfWeek == 0) {
endDayOfWeek = 7;
}
if (lastDateOfMonth.getWeekDay() != endDayOfWeek) {
int i = 1;
while (true) {
DateTime nextDay = lastDateOfMonth.plusDays(i);
datetimeList.add(nextDay);
i++;
if (nextDay.getWeekDay() == endDayOfWeek) {
break;
}
}
}
// Add more weeks to fill remaining rows
if (sixWeeksInCalendar) {
int size = datetimeList.size();
int row = size / 7;
int numOfDays = (6 - row) * 7;
DateTime lastDateTime = datetimeList.get(size - 1);
for (int i = 1; i <= numOfDays; i++) {
DateTime nextDateTime = lastDateTime.plusDays(i);
datetimeList.add(nextDateTime);
}
}
return datetimeList;
}
Aggregations