Search in sources :

Example 46 with DateTime

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

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

Example 48 with DateTime

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

Example 49 with DateTime

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

Example 50 with DateTime

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