diff --git a/images/2018-03-31.png b/images/2018-03-31.png new file mode 100644 index 00000000..4f476550 Binary files /dev/null and b/images/2018-03-31.png differ diff --git a/library/src/main/java/com/github/sundeepk/compactcalendarview/CompactCalendarController.java b/library/src/main/java/com/github/sundeepk/compactcalendarview/CompactCalendarController.java index 96d60353..a24dff02 100755 --- a/library/src/main/java/com/github/sundeepk/compactcalendarview/CompactCalendarController.java +++ b/library/src/main/java/com/github/sundeepk/compactcalendarview/CompactCalendarController.java @@ -1,5 +1,6 @@ package com.github.sundeepk.compactcalendarview; +import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; @@ -8,6 +9,7 @@ import android.graphics.PointF; import android.graphics.Rect; import android.graphics.Typeface; +import android.os.Build; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.TypedValue; @@ -15,7 +17,9 @@ import android.view.VelocityTracker; import android.view.ViewConfiguration; import android.widget.OverScroller; + import com.github.sundeepk.compactcalendarview.domain.Event; + import java.util.Calendar; import java.util.Date; import java.util.List; @@ -217,7 +221,7 @@ private void initScreenDensityRelatedValues(Context context) { densityAdjustedSnapVelocity = (int) (screenDensity * SNAP_VELOCITY_DIP_PER_SECOND); maximumVelocity = configuration.getScaledMaximumFlingVelocity(); - final DisplayMetrics dm = context.getResources().getDisplayMetrics() ; + final DisplayMetrics dm = context.getResources().getDisplayMetrics(); multiDayIndicatorStrokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, dm); } } @@ -236,7 +240,7 @@ private void setMonthOffset(Calendar calendarWithFirstDayOfMonth, Date currentDa calendarWithFirstDayOfMonth.set(Calendar.MILLISECOND, 0); } - void setShouldSelectFirstDayOfMonthOnScroll(boolean shouldSelectFirstDayOfMonthOnScroll){ + void setShouldSelectFirstDayOfMonthOnScroll(boolean shouldSelectFirstDayOfMonthOnScroll) { this.shouldSelectFirstDayOfMonthOnScroll = shouldSelectFirstDayOfMonthOnScroll; } @@ -244,7 +248,7 @@ void setDisplayOtherMonthDays(boolean displayOtherMonthDays) { this.displayOtherMonthDays = displayOtherMonthDays; } - void shouldDrawIndicatorsBelowSelectedDays(boolean shouldDrawIndicatorsBelowSelectedDays){ + void shouldDrawIndicatorsBelowSelectedDays(boolean shouldDrawIndicatorsBelowSelectedDays) { this.shouldDrawIndicatorsBelowSelectedDays = shouldDrawIndicatorsBelowSelectedDays; } @@ -256,7 +260,7 @@ void setEventIndicatorStyle(int eventIndicatorStyle) { this.eventIndicatorStyle = eventIndicatorStyle; } - void setCurrentSelectedDayIndicatorStyle(int currentSelectedDayIndicatorStyle){ + void setCurrentSelectedDayIndicatorStyle(int currentSelectedDayIndicatorStyle) { this.currentSelectedDayIndicatorStyle = currentSelectedDayIndicatorStyle; } @@ -264,11 +268,11 @@ void setTargetHeight(int targetHeight) { this.targetHeight = targetHeight; } - float getScreenDensity(){ + float getScreenDensity() { return screenDensity; } - float getDayIndicatorRadius(){ + float getDayIndicatorRadius() { return bigCircleIndicatorRadius; } @@ -288,7 +292,7 @@ int getTargetHeight() { return targetHeight; } - int getWidth(){ + int getWidth() { return width; } @@ -300,7 +304,7 @@ void removeAllEvents() { eventsContainer.removeAllEvents(); } - void setFirstDayOfWeek(int day){ + void setFirstDayOfWeek(int day) { if (day < 1 || day > 7) { throw new IllegalArgumentException("Day must be an int between 1 and 7 or DAY_OF_WEEK from Java Calendar class. For more information please see Calendar.DAY_OF_WEEK."); } @@ -336,7 +340,7 @@ void setCurrentDayTextColor(int currentDayTextColor) { void showNextMonth() { monthsScrolledSoFar = monthsScrolledSoFar - 1; accumulatedScrollOffset.x = monthsScrolledSoFar * width; - if(shouldSelectFirstDayOfMonthOnScroll){ + if (shouldSelectFirstDayOfMonthOnScroll) { setCalenderToFirstDayOfMonth(calendarWithFirstDayOfMonth, currentCalender.getTime(), 0, 1); setCurrentDate(calendarWithFirstDayOfMonth.getTime()); } @@ -346,7 +350,7 @@ void showNextMonth() { void showPreviousMonth() { monthsScrolledSoFar = monthsScrolledSoFar + 1; accumulatedScrollOffset.x = monthsScrolledSoFar * width; - if(shouldSelectFirstDayOfMonthOnScroll){ + if (shouldSelectFirstDayOfMonthOnScroll) { setCalenderToFirstDayOfMonth(calendarWithFirstDayOfMonth, currentCalender.getTime(), 0, -1); setCurrentDate(calendarWithFirstDayOfMonth.getTime()); } @@ -405,7 +409,7 @@ void onMeasure(int width, int height, int paddingRight, int paddingLeft) { private float getInterpolatedBigCircleIndicator() { float x0 = textSizeRect.height(); float x1 = heightPerDay; // take into account indicator offset - float x = (x1 + textSizeRect.height()) / 2f; // pick a point which is almost half way through heightPerDay and textSizeRect + float x = (x1 + textSizeRect.height()) / 2f; // pick a point which is almost half way through heightPerDay and textSizeRect double y1 = 0.5 * Math.sqrt((x1 * x1) + (x1 * x1)); double y0 = 0.5 * Math.sqrt((x0 * x0) + (x0 * x0)); @@ -640,7 +644,7 @@ void addEvent(Event event) { } void addEvents(List events) { - eventsContainer.addEvents(events); + eventsContainer.addEvents(events); } List getCalendarEventsFor(long epochMillis) { @@ -656,11 +660,11 @@ void removeEventsFor(long epochMillis) { } void removeEvent(Event event) { - eventsContainer.removeEvent(event); + eventsContainer.removeEvent(event); } void removeEvents(List events) { - eventsContainer.removeEvents(events); + eventsContainer.removeEvents(events); } void setGrowProgress(float grow) { @@ -749,10 +753,10 @@ void drawEvents(Canvas canvas, Calendar currentMonthToDrawCalender, int offset) 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) { + 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){ + } 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)) { @@ -768,7 +772,9 @@ void drawEvents(Canvas canvas, Calendar currentMonthToDrawCalender, int offset) if (shouldDrawIndicatorsBelowSelectedDays || (!shouldDrawIndicatorsBelowSelectedDays && !isSameDayAsCurrentDay && !isCurrentSelectedDay) || animationStatus == EXPOSE_CALENDAR_ANIMATION) { if (eventIndicatorStyle == FILL_LARGE_INDICATOR || eventIndicatorStyle == NO_FILL_LARGE_INDICATOR) { - if(!eventsList.isEmpty()){ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && eventIndicatorStyle == NO_FILL_LARGE_INDICATOR) { + drawEventArcs(canvas, xPosition, yPosition, eventsList); + } else if(!eventsList.isEmpty()) { Event event = eventsList.get(0); drawEventIndicatorCircle(canvas, xPosition, yPosition, event.getColor()); } @@ -793,6 +799,31 @@ void drawEvents(Canvas canvas, Calendar currentMonthToDrawCalender, int offset) } } + private void drawEventArcs(Canvas canvas, float x, float y, List events) { + float incAngel = 360 / events.size(); + float angelOffset = -90f; + + dayPaint.setStrokeWidth(2 * screenDensity); + dayPaint.setStyle(Paint.Style.STROKE); + + for (int i = 0; i < events.size(); i++) { + dayPaint.setColor(events.get(i).getColor()); + + if (animationStatus == ANIMATE_INDICATORS) { + float maxRadius = 1 * bigCircleIndicatorRadius * 1.4f; + drawArc(canvas, incAngel * i + angelOffset, incAngel, growfactorIndicator > maxRadius ? maxRadius : growfactorIndicator, x, y - (textHeight / 6)); + } else { + drawArc(canvas, incAngel * i + angelOffset, incAngel, 1 * bigCircleIndicatorRadius, x, y - (textHeight / 6)); + } + } + } + + @SuppressLint("NewApi") + private void drawArc(Canvas canvas, float startAngle, float sweepAngle, float radius, float x, float y) { + canvas.drawArc(x - radius, y - radius, x + radius, y + radius, startAngle, sweepAngle, false, dayPaint); + } + + private void drawSingleEvent(Canvas canvas, float xPosition, float yPosition, List eventsList) { Event event = eventsList.get(0); drawEventIndicatorCircle(canvas, xPosition, yPosition, event.getColor()); @@ -829,7 +860,7 @@ private void drawEventsWithPlus(Canvas canvas, float xPosition, float yPosition, // it returns 0-6 where 0 is Sunday instead of 1 int getDayOfWeek(Calendar calendar) { int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - firstDayOfWeekToDraw; - dayOfWeek = dayOfWeek < 0 ? 7 + dayOfWeek: dayOfWeek; + dayOfWeek = dayOfWeek < 0 ? 7 + dayOfWeek : dayOfWeek; return dayOfWeek; } @@ -842,7 +873,7 @@ void drawMonth(Canvas canvas, Calendar monthToDrawCalender, int offset) { boolean isSameMonthAsToday = monthToDrawCalender.get(Calendar.MONTH) == todayCalender.get(Calendar.MONTH); boolean isSameYearAsToday = monthToDrawCalender.get(Calendar.YEAR) == todayCalender.get(Calendar.YEAR); boolean isSameMonthAsCurrentCalendar = monthToDrawCalender.get(Calendar.MONTH) == currentCalender.get(Calendar.MONTH) && - monthToDrawCalender.get(Calendar.YEAR) == currentCalender.get(Calendar.YEAR); + monthToDrawCalender.get(Calendar.YEAR) == currentCalender.get(Calendar.YEAR); int todayDayOfMonth = todayCalender.get(Calendar.DAY_OF_MONTH); boolean isAnimatingWithExpose = animationStatus == EXPOSE_CALENDAR_ANIMATION; @@ -934,7 +965,7 @@ private void drawCircle(Canvas canvas, float x, float y, int color, float circle dayPaint.setColor(color); if (animationStatus == ANIMATE_INDICATORS) { float maxRadius = circleScale * bigCircleIndicatorRadius * 1.4f; - drawCircle(canvas, growfactorIndicator > maxRadius ? maxRadius: growfactorIndicator, x, y - (textHeight / 6)); + drawCircle(canvas, growfactorIndicator > maxRadius ? maxRadius : growfactorIndicator, x, y - (textHeight / 6)); } else { drawCircle(canvas, circleScale * bigCircleIndicatorRadius, x, y - (textHeight / 6)); } @@ -945,7 +976,7 @@ private void drawEventIndicatorCircle(Canvas canvas, float x, float y, int color if (eventIndicatorStyle == SMALL_INDICATOR) { dayPaint.setStyle(Paint.Style.FILL); drawCircle(canvas, smallIndicatorRadius, x, y); - } else if (eventIndicatorStyle == NO_FILL_LARGE_INDICATOR){ + } else if (eventIndicatorStyle == NO_FILL_LARGE_INDICATOR) { dayPaint.setStyle(Paint.Style.STROKE); drawDayCircleIndicator(NO_FILL_LARGE_INDICATOR, canvas, x, y, color); } else if (eventIndicatorStyle == FILL_LARGE_INDICATOR) {