Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/uppercase weekdays header #241

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand All @@ -797,12 +813,21 @@ private void drawSingleEvent(Canvas canvas, float xPosition, float yPosition, Li
}

private void drawTwoEvents(Canvas canvas, float xPosition, float yPosition, List<Event> 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<Event> 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<Event> 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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<attr name="compactCalendarCurrentDayTextColor" format="color"/>
<attr name="compactCalendarCurrentSelectedDayBackgroundColor" format="color"/>
<attr name="compactCalendarCurrentSelectedDayTextColor" format="color"/>
<attr name="compactCalendarTextColor" format="color"/>
<attr name="compactCalendarTextColor" format="reference|color"/>
<attr name="compactCalendarMultiEventIndicatorColor" format="color"/>
<attr name="compactCalendarTargetHeight" format="dimension"/>
<attr name="compactCalendarEventIndicatorStyle"/>
Expand All @@ -29,5 +29,6 @@
<attr name="compactCalendarDisplayOtherMonthDays" format="boolean"/>
<attr name="compactCalendarShouldSelectFirstDayOfMonthOnScroll" format="boolean"/>
<attr name="compactCalendarOtherMonthDaysTextColor" format="color"/>
<attr name="compactCalendarUppercaseWeekDaysHeader" format="boolean"/>
</declare-styleable>
</resources>