Search in sources :

Example 21 with DateTime

use of hirondelle.date4j.DateTime in project instructure-android by instructure.

the class CaldroidFragment method setSelectedDates.

/**
 * Select the dates from fromDate to toDate. By default the background color
 * is holo_blue_light, and the text color is black. You can customize the
 * background by changing CaldroidFragment.selectedBackgroundDrawable, and
 * change the text color CaldroidFragment.selectedTextColor before call this
 * method. This method does not refresh view, need to call refreshView()
 *
 * @param fromDate
 * @param toDate
 */
public void setSelectedDates(Date fromDate, Date toDate) {
    // Ensure fromDate is before toDate
    if (fromDate == null || toDate == null || fromDate.after(toDate)) {
        return;
    }
    selectedDates.clear();
    DateTime fromDateTime = CalendarHelper.convertDateToDateTime(fromDate);
    DateTime toDateTime = CalendarHelper.convertDateToDateTime(toDate);
    DateTime dateTime = fromDateTime;
    while (dateTime.lt(toDateTime)) {
        selectedDates.add(dateTime);
        dateTime = dateTime.plusDays(1);
    }
    selectedDates.add(toDateTime);
}
Also used : DateTime(hirondelle.date4j.DateTime)

Example 22 with DateTime

use of hirondelle.date4j.DateTime in project instructure-android by instructure.

the class CaldroidFragment method moveToDateTime.

/**
 * Move calendar to specified dateTime, with animation
 *
 * @param dateTime
 */
public void moveToDateTime(DateTime dateTime) {
    DateTime firstOfMonth = new DateTime(year, month, 1, 0, 0, 0, 0);
    DateTime lastOfMonth = firstOfMonth.getEndOfMonth();
    // Calendar swipe left when dateTime is in the past
    if (dateTime.lt(firstOfMonth)) {
        // Get next month of dateTime. When swipe left, month will
        // decrease
        DateTime firstDayNextMonth = dateTime.plus(0, 1, 0, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
        // Refresh adapters
        pageChangeListener.setCurrentDateTime(firstDayNextMonth, false);
        int currentItem = dateViewPager.getCurrentItem();
        pageChangeListener.refreshAdapters(currentItem);
        // Swipe left
        dateViewPager.setCurrentItem(currentItem - 1);
    } else // Calendar swipe right when dateTime is in the future
    if (dateTime.gt(lastOfMonth)) {
        // Get last month of dateTime. When swipe right, the month will
        // increase
        DateTime firstDayLastMonth = dateTime.minus(0, 1, 0, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
        // Refresh adapters
        pageChangeListener.setCurrentDateTime(firstDayLastMonth, false);
        int currentItem = dateViewPager.getCurrentItem();
        pageChangeListener.refreshAdapters(currentItem);
        // Swipe right
        dateViewPager.setCurrentItem(currentItem + 1);
    }
}
Also used : DateTime(hirondelle.date4j.DateTime) SuppressLint(android.annotation.SuppressLint)

Example 23 with DateTime

use of hirondelle.date4j.DateTime in project instructure-android by instructure.

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 24 with DateTime

use of hirondelle.date4j.DateTime in project instructure-android by instructure.

the class CalendarListRecyclerAdapter method getEndDate.

private Calendar getEndDate() {
    int startDay = getStartDayOfWeek();
    Calendar cal = Calendar.getInstance();
    ArrayList<DateTime> dates = CalendarHelper.getFullWeeks(mSelectedDay.getMonth(), mSelectedDay.getYear(), startDay, false);
    DateTime endDate = dates.get(dates.size() - 1);
    cal.set(endDate.getYear(), endDate.getMonth() - 1, endDate.getDay(), endDate.getHour(), endDate.getMinute(), endDate.getSecond());
    return cal;
}
Also used : Calendar(java.util.Calendar) DateTime(hirondelle.date4j.DateTime)

Example 25 with DateTime

use of hirondelle.date4j.DateTime in project instructure-android by instructure.

the class CalendarListRecyclerAdapter method getFirstEndDate.

private Calendar getFirstEndDate() {
    int startDay = getStartDayOfWeek();
    Calendar cal = Calendar.getInstance();
    DateTime today = DateTime.forInstant(cal.getTime().getTime(), TimeZone.getDefault());
    ArrayList<DateTime> dates = CalendarHelper.getFullWeeks(today.getMonth(), today.getYear(), startDay, false);
    DateTime endDate = dates.get(dates.size() - 1);
    cal.set(endDate.getYear(), endDate.getMonth() - 1, endDate.getDay(), endDate.getHour(), endDate.getMinute(), endDate.getSecond());
    return cal;
}
Also used : Calendar(java.util.Calendar) 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