Search in sources :

Example 16 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class EventsContainerTest method testItGetsEventsForSpecificDay.

@Test
public void testItGetsEventsForSpecificDay() {
    //Sun, 07 Jun 2015 18:20:51 GMT
    //get 30 events in total
    List<Event> events = getSingleEvents(0, 30, 1433701251000L);
    for (Event event : events) {
        underTest.addEvent(event);
    }
    //Wed, 24 Aug 2016 09:21:09 GMT
    //get 30 events in total
    List<Event> events2 = getSingleEvents(0, 30, 1472030469000L);
    for (Event event : events2) {
        underTest.addEvent(event);
    }
    //Sun, 07 Jun 2015 18:20:51 GMT
    List<Event> calendarDayEvents = underTest.getEventsFor(setTimeToMidnightAndGet(Calendar.getInstance(), 1433701251000L));
    assertNotNull(calendarDayEvents);
    //Assert 6th item since it will represent Sun, 07 Jun 2015 which is the day that we queried for
    assertEquals(1, calendarDayEvents.size());
    assertEquals(events.get(6), calendarDayEvents.get(0));
}
Also used : Event(com.github.sundeepk.compactcalendarview.domain.Event) Test(org.junit.Test)

Example 17 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class CompactCalendarController method drawEvents.

void drawEvents(Canvas canvas, Calendar currentMonthToDrawCalender, int offset) {
    int currentMonth = currentMonthToDrawCalender.get(Calendar.MONTH);
    List<Events> uniqEvents = eventsContainer.getEventsForMonthAndYear(currentMonth, currentMonthToDrawCalender.get(Calendar.YEAR));
    boolean shouldDrawCurrentDayCircle = currentMonth == todayCalender.get(Calendar.MONTH);
    boolean shouldDrawSelectedDayCircle = currentMonth == currentCalender.get(Calendar.MONTH);
    int todayDayOfMonth = todayCalender.get(Calendar.DAY_OF_MONTH);
    int currentYear = todayCalender.get(Calendar.YEAR);
    int selectedDayOfMonth = currentCalender.get(Calendar.DAY_OF_MONTH);
    float indicatorOffset = bigCircleIndicatorRadius / 2;
    if (uniqEvents != null) {
        for (int i = 0; i < uniqEvents.size(); i++) {
            Events events = uniqEvents.get(i);
            long timeMillis = events.getTimeInMillis();
            eventsCalendar.setTimeInMillis(timeMillis);
            int dayOfWeek = getDayOfWeek(eventsCalendar);
            int weekNumberForMonth = eventsCalendar.get(Calendar.WEEK_OF_MONTH);
            float xPosition = widthPerDay * dayOfWeek + paddingWidth + paddingLeft + accumulatedScrollOffset.x + offset - paddingRight;
            float yPosition = weekNumberForMonth * heightPerDay + paddingHeight;
            if (((animationStatus == EXPOSE_CALENDAR_ANIMATION || animationStatus == ANIMATE_INDICATORS) && xPosition >= growFactor) || yPosition >= growFactor) {
                // only draw small event indicators if enough of the calendar is exposed
                continue;
            } else if (animationStatus == EXPAND_COLLAPSE_CALENDAR && yPosition >= growFactor) {
                // expanding animation, just draw event indicators if enough of the calendar is visible
                continue;
            } else if (animationStatus == EXPOSE_CALENDAR_ANIMATION && (eventIndicatorStyle == FILL_LARGE_INDICATOR || eventIndicatorStyle == NO_FILL_LARGE_INDICATOR)) {
                // Don't draw large indicators during expose animation, until animation is done
                continue;
            }
            List<Event> eventsList = events.getEvents();
            int dayOfMonth = eventsCalendar.get(Calendar.DAY_OF_MONTH);
            int eventYear = eventsCalendar.get(Calendar.YEAR);
            boolean isSameDayAsCurrentDay = shouldDrawCurrentDayCircle && (todayDayOfMonth == dayOfMonth) && (eventYear == currentYear);
            boolean isCurrentSelectedDay = shouldDrawSelectedDayCircle && (selectedDayOfMonth == dayOfMonth);
            if (shouldDrawIndicatorsBelowSelectedDays || (!shouldDrawIndicatorsBelowSelectedDays && !isSameDayAsCurrentDay && !isCurrentSelectedDay) || animationStatus == EXPOSE_CALENDAR_ANIMATION) {
                if (eventIndicatorStyle == FILL_LARGE_INDICATOR || eventIndicatorStyle == NO_FILL_LARGE_INDICATOR) {
                    Event event = eventsList.get(0);
                    drawEventIndicatorCircle(canvas, xPosition, yPosition, event.getColor());
                } else {
                    yPosition += indicatorOffset;
                    // this makes sure that they do no overlap
                    if (shouldDrawIndicatorsBelowSelectedDays && (isSameDayAsCurrentDay || isCurrentSelectedDay)) {
                        yPosition += indicatorOffset;
                    }
                    if (eventsList.size() >= 3) {
                        drawEventsWithPlus(canvas, xPosition, yPosition, eventsList);
                    } else if (eventsList.size() == 2) {
                        drawTwoEvents(canvas, xPosition, yPosition, eventsList);
                    } else if (eventsList.size() == 1) {
                        drawSingleEvent(canvas, xPosition, yPosition, eventsList);
                    }
                }
            }
        }
    }
}
Also used : MotionEvent(android.view.MotionEvent) Event(com.github.sundeepk.compactcalendarview.domain.Event) Paint(android.graphics.Paint)

Example 18 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class CompactCalendarController method drawEventsWithPlus.

//draw 2 eventsByMonthAndYearMap followed by plus indicator to show there are more than 2 eventsByMonthAndYearMap
private void drawEventsWithPlus(Canvas canvas, float xPosition, float yPosition, List<Event> eventsList) {
    // display more than 2 evens before displaying plus indicator, but don't draw more than 3 indicators for now
    for (int j = 0, k = -2; j < 3; j++, k += 2) {
        Event event = eventsList.get(j);
        float xStartPosition = xPosition + (xIndicatorOffset * k);
        if (j == 2) {
            dayPaint.setColor(multiEventIndicatorColor);
            dayPaint.setStrokeWidth(multiDayIndicatorStrokeWidth);
            canvas.drawLine(xStartPosition - smallIndicatorRadius, yPosition, xStartPosition + smallIndicatorRadius, yPosition, dayPaint);
            canvas.drawLine(xStartPosition, yPosition - smallIndicatorRadius, xStartPosition, yPosition + smallIndicatorRadius, dayPaint);
            dayPaint.setStrokeWidth(0);
        } else {
            drawEventIndicatorCircle(canvas, xStartPosition, yPosition, event.getColor());
        }
    }
}
Also used : MotionEvent(android.view.MotionEvent) Event(com.github.sundeepk.compactcalendarview.domain.Event) Paint(android.graphics.Paint)

Example 19 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class CompactCalendarHelper method getEvents.

public static List<Events> getEvents(int start, int days, long timeStamp) {
    Calendar currentCalender = Calendar.getInstance(Locale.getDefault());
    List<Events> events = new ArrayList<>();
    for (int i = start; i < days; i++) {
        setDateTime(timeStamp, currentCalender, i);
        List<Event> eventList = new ArrayList<>();
        eventList.add(new Event(Color.BLUE, currentCalender.getTimeInMillis()));
        Events eventsObject = new Events(currentCalender.getTimeInMillis(), eventList);
        events.add(eventsObject);
    }
    return events;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Event(com.github.sundeepk.compactcalendarview.domain.Event)

Example 20 with Event

use of com.github.sundeepk.compactcalendarview.domain.Event in project CompactCalendarView by SundeepK.

the class CompactCalendarControllerTest method testItAddsEvent.

@Test
public void testItAddsEvent() {
    Event event = getSingleEvents(0, 30, 1433701251000L).get(0);
    underTest.addEvent(event);
    verify(eventsContainer).addEvent(event);
    verifyNoMoreInteractions(eventsContainer);
}
Also used : MotionEvent(android.view.MotionEvent) Event(com.github.sundeepk.compactcalendarview.domain.Event) Test(org.junit.Test)

Aggregations

Event (com.github.sundeepk.compactcalendarview.domain.Event)23 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)8 MotionEvent (android.view.MotionEvent)5 Calendar (java.util.Calendar)5 Date (java.util.Date)3 List (java.util.List)3 Paint (android.graphics.Paint)2 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 CompactCalendarHelper.getMultipleEventsForEachDayAsMap (com.github.sundeepk.compactcalendarview.CompactCalendarHelper.getMultipleEventsForEachDayAsMap)1 CompactCalendarView (com.github.sundeepk.compactcalendarview.CompactCalendarView)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Random (java.util.Random)1 TimeZone (java.util.TimeZone)1