Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added images/2018-03-31.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,14 +9,17 @@
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;
import android.view.MotionEvent;
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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -236,15 +240,15 @@ private void setMonthOffset(Calendar calendarWithFirstDayOfMonth, Date currentDa
calendarWithFirstDayOfMonth.set(Calendar.MILLISECOND, 0);
}

void setShouldSelectFirstDayOfMonthOnScroll(boolean shouldSelectFirstDayOfMonthOnScroll){
void setShouldSelectFirstDayOfMonthOnScroll(boolean shouldSelectFirstDayOfMonthOnScroll) {
this.shouldSelectFirstDayOfMonthOnScroll = shouldSelectFirstDayOfMonthOnScroll;
}

void setDisplayOtherMonthDays(boolean displayOtherMonthDays) {
this.displayOtherMonthDays = displayOtherMonthDays;
}

void shouldDrawIndicatorsBelowSelectedDays(boolean shouldDrawIndicatorsBelowSelectedDays){
void shouldDrawIndicatorsBelowSelectedDays(boolean shouldDrawIndicatorsBelowSelectedDays) {
this.shouldDrawIndicatorsBelowSelectedDays = shouldDrawIndicatorsBelowSelectedDays;
}

Expand All @@ -256,19 +260,19 @@ void setEventIndicatorStyle(int eventIndicatorStyle) {
this.eventIndicatorStyle = eventIndicatorStyle;
}

void setCurrentSelectedDayIndicatorStyle(int currentSelectedDayIndicatorStyle){
void setCurrentSelectedDayIndicatorStyle(int currentSelectedDayIndicatorStyle) {
this.currentSelectedDayIndicatorStyle = currentSelectedDayIndicatorStyle;
}

void setTargetHeight(int targetHeight) {
this.targetHeight = targetHeight;
}

float getScreenDensity(){
float getScreenDensity() {
return screenDensity;
}

float getDayIndicatorRadius(){
float getDayIndicatorRadius() {
return bigCircleIndicatorRadius;
}

Expand All @@ -288,7 +292,7 @@ int getTargetHeight() {
return targetHeight;
}

int getWidth(){
int getWidth() {
return width;
}

Expand All @@ -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.");
}
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -640,7 +644,7 @@ void addEvent(Event event) {
}

void addEvents(List<Event> events) {
eventsContainer.addEvents(events);
eventsContainer.addEvents(events);
}

List<Event> getCalendarEventsFor(long epochMillis) {
Expand All @@ -656,11 +660,11 @@ void removeEventsFor(long epochMillis) {
}

void removeEvent(Event event) {
eventsContainer.removeEvent(event);
eventsContainer.removeEvent(event);
}

void removeEvents(List<Event> events) {
eventsContainer.removeEvents(events);
eventsContainer.removeEvents(events);
}

void setGrowProgress(float grow) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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());
}
Expand All @@ -793,6 +799,31 @@ void drawEvents(Canvas canvas, Calendar currentMonthToDrawCalender, int offset)
}
}

private void drawEventArcs(Canvas canvas, float x, float y, List<Event> 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<Event> eventsList) {
Event event = eventsList.get(0);
drawEventIndicatorCircle(canvas, xPosition, yPosition, event.getColor());
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;

Expand Down Expand Up @@ -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));
}
Expand All @@ -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) {
Expand Down