use of hirondelle.date4j.DateTime in project Caldroid by roomorama.
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, CellView cellView) {
// 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);
cellView.resetCustomStates();
resetCustomResources(cellView);
if (dateTime.equals(getToday())) {
cellView.addCustomState(CellView.STATE_TODAY);
}
// Set color of the dates in previous / next month
if (dateTime.getMonth() != month) {
cellView.addCustomState(CellView.STATE_PREV_NEXT_MONTH);
}
// 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.addCustomState(CellView.STATE_DISABLED);
}
// Customize for selected dates
if (selectedDates != null && selectedDatesMap.containsKey(dateTime)) {
cellView.addCustomState(CellView.STATE_SELECTED);
}
cellView.refreshDrawableState();
// Set text
cellView.setText(String.valueOf(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 Caldroid by roomorama.
the class CalendarHelper method convertDateToDateTime.
/**
* Get the DateTime from Date, with hour and min is 0
*
* @param date
* @return
*/
public static DateTime convertDateToDateTime(Date date) {
// Get year, javaMonth, date
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
int javaMonth = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DATE);
// javaMonth start at 0. Need to plus 1 to get datetimeMonth
return new DateTime(year, javaMonth + 1, day, 0, 0, 0, 0);
}
use of hirondelle.date4j.DateTime in project Caldroid by roomorama.
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;
}
use of hirondelle.date4j.DateTime in project Caldroid by roomorama.
the class CaldroidFragment method clearBackgroundDrawableForDate.
public void clearBackgroundDrawableForDate(Date date) {
DateTime dateTime = CalendarHelper.convertDateToDateTime(date);
backgroundForDateTimeMap.remove(dateTime);
}
use of hirondelle.date4j.DateTime in project Caldroid by roomorama.
the class CaldroidFragment method setBackgroundDrawableForDate.
public void setBackgroundDrawableForDate(Drawable drawable, Date date) {
DateTime dateTime = CalendarHelper.convertDateToDateTime(date);
backgroundForDateTimeMap.put(dateTime, drawable);
}
Aggregations