Search in sources :

Example 6 with DateTime

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);
}
Also used : DateTime(hirondelle.date4j.DateTime)

Example 7 with DateTime

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);
}
Also used : Calendar(java.util.Calendar) DateTime(hirondelle.date4j.DateTime)

Example 8 with DateTime

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;
}
Also used : ArrayList(java.util.ArrayList) DateTime(hirondelle.date4j.DateTime)

Example 9 with DateTime

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);
}
Also used : DateTime(hirondelle.date4j.DateTime)

Example 10 with 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);
}
Also used : DateTime(hirondelle.date4j.DateTime)

Aggregations

DateTime (hirondelle.date4j.DateTime)52 Date (java.util.Date)17 SuppressLint (android.annotation.SuppressLint)8 ArrayList (java.util.ArrayList)6 Calendar (java.util.Calendar)6 DateWindow (com.instructure.candroid.model.DateWindow)4 Test (org.junit.Test)4 View (android.view.View)3 TextView (android.widget.TextView)3 DiscussionTopicHeader (com.instructure.canvasapi2.models.DiscussionTopicHeader)3 Dialog (android.app.Dialog)2 Drawable (android.graphics.drawable.Drawable)2 Bundle (android.os.Bundle)2 LayoutInflater (android.view.LayoutInflater)2 InfinitePagerAdapter (com.antonyt.infiniteviewpager.InfinitePagerAdapter)2 EventData (com.instructure.candroid.model.EventData)2 ScheduleItem (com.instructure.canvasapi2.models.ScheduleItem)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Resources (android.content.res.Resources)1 Button (android.widget.Button)1