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 9a22199c..aad116ea 100755 --- a/library/src/main/java/com/github/sundeepk/compactcalendarview/CompactCalendarController.java +++ b/library/src/main/java/com/github/sundeepk/compactcalendarview/CompactCalendarController.java @@ -1,6 +1,7 @@ package com.github.sundeepk.compactcalendarview; import android.content.Context; +import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; @@ -78,6 +79,7 @@ class CompactCalendarController { private boolean shouldDrawIndicatorsBelowSelectedDays = false; private boolean displayOtherMonthDays = false; private boolean shouldSelectFirstDayOfMonthOnScroll = true; + private boolean shouldUppercaseWeekDaysHeader = false; private CompactCalendarViewListener listener; private VelocityTracker velocityTracker = null; @@ -142,8 +144,19 @@ private void loadAttributes(AttributeSet attrs, Context context) { if (attrs != null && context != null) { TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CompactCalendarView, 0, 0); try { + + int id = typedArray.getResourceId(R.styleable.CompactCalendarView_compactCalendarTextColor, -1); + if (id != -1) { + TypedArray app = context.getTheme().obtainStyledAttributes(id, new int[]{ android.R.attr.textColor, android.R.attr.typeface, android.R.attr.textStyle}); + if (app != null){ + calenderTextColor = app.getColor(0, 0); + app.recycle(); + } + } else { + calenderTextColor = typedArray.getColor(R.styleable.CompactCalendarView_compactCalendarTextColor, calenderTextColor); + } + currentDayBackgroundColor = typedArray.getColor(R.styleable.CompactCalendarView_compactCalendarCurrentDayBackgroundColor, currentDayBackgroundColor); - calenderTextColor = typedArray.getColor(R.styleable.CompactCalendarView_compactCalendarTextColor, calenderTextColor); currentDayTextColor = typedArray.getColor(R.styleable.CompactCalendarView_compactCalendarCurrentDayTextColor, calenderTextColor); otherMonthDaysTextColor = typedArray.getColor(R.styleable.CompactCalendarView_compactCalendarOtherMonthDaysTextColor, otherMonthDaysTextColor); currentSelectedDayBackgroundColor = typedArray.getColor(R.styleable.CompactCalendarView_compactCalendarCurrentSelectedDayBackgroundColor, currentSelectedDayBackgroundColor); @@ -159,6 +172,7 @@ private void loadAttributes(AttributeSet attrs, Context context) { currentSelectedDayIndicatorStyle = typedArray.getInt(R.styleable.CompactCalendarView_compactCalendarCurrentSelectedDayIndicatorStyle, FILL_LARGE_INDICATOR); displayOtherMonthDays = typedArray.getBoolean(R.styleable.CompactCalendarView_compactCalendarDisplayOtherMonthDays, displayOtherMonthDays); shouldSelectFirstDayOfMonthOnScroll = typedArray.getBoolean(R.styleable.CompactCalendarView_compactCalendarShouldSelectFirstDayOfMonthOnScroll, shouldSelectFirstDayOfMonthOnScroll); + shouldUppercaseWeekDaysHeader = typedArray.getBoolean(R.styleable.CompactCalendarView_compactCalendarUppercaseWeekDaysHeader, shouldUppercaseWeekDaysHeader); } finally { typedArray.recycle(); } @@ -778,8 +792,10 @@ void drawEvents(Canvas canvas, Calendar currentMonthToDrawCalender, int offset) yPosition += indicatorOffset; } - if (eventsList.size() >= 3) { + if (eventsList.size() >= 4) { drawEventsWithPlus(canvas, xPosition, yPosition, eventsList); + } else if (eventsList.size() == 3) { + drawThreeEvents(canvas, xPosition, yPosition, eventsList); } else if (eventsList.size() == 2) { drawTwoEvents(canvas, xPosition, yPosition, eventsList); } else if (eventsList.size() == 1) { @@ -797,12 +813,21 @@ private void drawSingleEvent(Canvas canvas, float xPosition, float yPosition, Li } private void drawTwoEvents(Canvas canvas, float xPosition, float yPosition, List eventsList) { - //draw fist event just left of center + //draw first event just left of center drawEventIndicatorCircle(canvas, xPosition + (xIndicatorOffset * -1), yPosition, eventsList.get(0).getColor()); //draw second event just right of center drawEventIndicatorCircle(canvas, xPosition + (xIndicatorOffset * 1), yPosition, eventsList.get(1).getColor()); } + private void drawThreeEvents(Canvas canvas, float xPosition, float yPosition, List eventsList) { + //draw first event just left of center + drawEventIndicatorCircle(canvas, xPosition + (xIndicatorOffset * -2), yPosition, eventsList.get(0).getColor()); + //draw second event centered + drawEventIndicatorCircle(canvas, xPosition, yPosition, eventsList.get(1).getColor()); + //draw third event just right of center + drawEventIndicatorCircle(canvas, xPosition + (xIndicatorOffset * 2), yPosition, eventsList.get(2).getColor()); + } + //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 eventsList) { // k = size() - 1, but since we don't want to draw more than 2 indicators, we just stop after 2 iterations so we can just hard k = -2 instead @@ -873,7 +898,7 @@ void drawMonth(Canvas canvas, Calendar monthToDrawCalender, int offset) { dayPaint.setTypeface(Typeface.DEFAULT_BOLD); dayPaint.setStyle(Paint.Style.FILL); dayPaint.setColor(calenderTextColor); - canvas.drawText(dayColumnNames[dayColumn], xPosition, paddingHeight, dayPaint); + canvas.drawText(shouldUppercaseWeekDaysHeader ? dayColumnNames[dayColumn].toUpperCase() : dayColumnNames[dayColumn], xPosition, paddingHeight, dayPaint); dayPaint.setTypeface(Typeface.DEFAULT); } } else { diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index be80746e..0fceadf6 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -20,7 +20,7 @@ - + @@ -29,5 +29,6 @@ +