Skip to content

Commit

Permalink
Merge pull request #62 from udaysrinath/master
Browse files Browse the repository at this point in the history
Calendar View enhancements
  • Loading branch information
Jonatan E. Salas authored Sep 25, 2018
2 parents 32cd6cf + 93d1a2e commit ea3f5cb
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 138 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ This example shows all the possible customization around Material Calendar View:
app:calendarBackgroundColor="@color/colorPrimary"
app:calendarTitleTextColor="@color/colorAccent"
app:calendarCurrentDayTextColor="@color/white"
app:calendarDayOfWeekTextColor="@android:color/white"
app:calendarDayOfWeekTextColor="@color/grey"
app:calendarDayOfMonthTextColor="@android:color/white"
app:calendarDisabledDayBackgroundColor="@color/colorPrimary"
app:calendarDisabledDayTextColor="@android:color/darker_gray"
app:calendarSelectedDayBackgroundColor="@color/colorAccent"
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@
app:calendarIsOverflowDatesVisible="true"
app:calendarBackgroundColor="@color/colorPrimary"
app:calendarTitleTextColor="@color/colorAccent"
app:calendarCurrentDayTextColor="@color/white"
app:calendarDayOfWeekTextColor="@android:color/white"
app:calendarCurrentDayTextColor="@color/colorAccent"
app:calendarSelectedDayTextColor="@color/white"
app:calendarDayOfWeekTextColor="@color/grey"
app:calendarDayOfMonthTextColor="@android:color/white"
app:calendarDisabledDayBackgroundColor="@color/colorPrimary"
app:calendarDisabledDayTextColor="@android:color/darker_gray"
app:calendarSelectedDayBackgroundColor="@color/colorAccent"
app:calendarTitleBackgroundColor="@color/colorPrimary"
app:calendarWeekBackgroundColor="@color/colorPrimary"
app:calendarCurrentDayBackgroundColor="@color/teal500"
app:calendarWeekendTextColor="@color/colorAccent"
app:calendarWeekendTextColor="@color/red"
app:calendarButtonBackgroundColor="@color/colorAccent"
app:calendarWeekendDays="saturday|sunday">
</io.blackbox_vision.materialcalendarview.view.CalendarView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ public final class CalendarView extends LinearLayout {
private int selectedDayTextColor;
private int titleTextColor;
private int dayOfWeekTextColor;
private int dayOfMonthTextColor;
private int currentDayTextColor;
private int weekendTextColor;
private int weekendDays;
Expand Down Expand Up @@ -320,7 +321,8 @@ private void takeStyles(AttributeSet attrs) {
titleBackgroundColor = a.getColor(R.styleable.MaterialCalendarView_calendarTitleBackgroundColor, white);
titleTextColor = a.getColor(R.styleable.MaterialCalendarView_calendarTitleTextColor, white);
weekBackgroundColor = a.getColor(R.styleable.MaterialCalendarView_calendarWeekBackgroundColor, white);
dayOfWeekTextColor = a.getColor(R.styleable.MaterialCalendarView_calendarDayOfWeekTextColor, black);
dayOfWeekTextColor = a.getColor(R.styleable.MaterialCalendarView_calendarDayOfWeekTextColor, dayDisableTextColor);
dayOfMonthTextColor = a.getColor(R.styleable.MaterialCalendarView_calendarDayOfMonthTextColor, black);
disabledDayBackgroundColor = a.getColor(R.styleable.MaterialCalendarView_calendarDisabledDayBackgroundColor, dayDisableBackground);
disabledDayTextColor = a.getColor(R.styleable.MaterialCalendarView_calendarDisabledDayTextColor, dayDisableTextColor);
selectedDayBackgroundColor = a.getColor(R.styleable.MaterialCalendarView_calendarSelectedDayBackgroundColor, daySelectedBackground);
Expand Down Expand Up @@ -423,7 +425,7 @@ private void drawWeekView() {
if (totalDayOfWeekend.length != 0) {
for (int weekend : totalDayOfWeekend) {
if (i == weekend) {
textView.setTextColor(weekendTextColor);
textView.setTextColor(dayOfWeekTextColor);
isCommonDay = false;
}
}
Expand Down Expand Up @@ -578,7 +580,7 @@ private void drawAdapterView() {
}

if (isCommonDay) {
textView.setTextColor(dayOfWeekTextColor);
textView.setTextColor(dayOfMonthTextColor);
}

if (day.isCurrentDay()) {
Expand Down Expand Up @@ -614,7 +616,7 @@ private void clearDayViewSelection(Date currentDate) {

DayView dayView = findViewByCalendar(calendar);
dayView.setBackgroundColor(calendarBackgroundColor);
isCommonDay = true;
isCommonDay = !CalendarUtils.isToday(calendar);

if (totalDayOfWeekend.length != 0) {
for (int weekend : totalDayOfWeekend) {
Expand All @@ -626,7 +628,9 @@ private void clearDayViewSelection(Date currentDate) {
}

if (isCommonDay) {
dayView.setTextColor(dayOfWeekTextColor);
dayView.setTextColor(dayOfMonthTextColor);
} else {
dayView.setTextColor(currentDayTextColor);
}
}
}
Expand Down Expand Up @@ -690,7 +694,7 @@ private void drawCurrentDay(@NonNull Date date) {
if (CalendarUtils.isToday(calendar)) {
final DayView dayOfMonth = findViewByCalendar(calendar);

dayOfMonth.setTextColor(currentDayTextColor);
dayOfMonth.setTextColor(dayOfMonthTextColor);

Drawable d = ContextCompat.getDrawable(getContext(), R.drawable.circular_background);
d.setColorFilter(currentDayBackgroundColor, PorterDuff.Mode.SRC_ATOP);
Expand Down Expand Up @@ -1290,6 +1294,12 @@ public CalendarView setTitleTextColor(int titleTextColor) {
return this;
}

public CalendarView setDayOfMonthTextColor(int dayOfMonthTextColor) {
this.dayOfMonthTextColor = dayOfMonthTextColor;
invalidate();
return this;
}

public CalendarView setDayOfWeekTextColor(int dayOfWeekTextColor) {
this.dayOfWeekTextColor = dayOfWeekTextColor;
invalidate();
Expand Down
21 changes: 0 additions & 21 deletions materialcalendarview/src/main/res/layout/week_view1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:gravity="center"
android:tag="dayOfMonthText1"
tools:text="1"
android:layout_centerInParent="true"/>
Expand All @@ -36,9 +33,6 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:gravity="center"
android:tag="dayOfMonthText2"
tools:text="2"
android:layout_centerInParent="true"/>
Expand All @@ -54,9 +48,6 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:gravity="center"
android:tag="dayOfMonthText3"
tools:text="3"
android:layout_centerVertical="true"
Expand All @@ -73,10 +64,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText4"
tools:text="4"/>

Expand All @@ -91,10 +79,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText5"
tools:text="5" />

Expand All @@ -109,10 +94,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText6"
tools:text="6"/>

Expand All @@ -127,10 +109,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText7"
tools:text="7"/>

Expand Down
21 changes: 0 additions & 21 deletions materialcalendarview/src/main/res/layout/week_view2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText8"
tools:text="8" />

Expand All @@ -36,10 +33,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText9"
tools:text="9" />

Expand All @@ -54,10 +48,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText10"
tools:text="10" />

Expand All @@ -72,10 +63,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText11"
tools:text="11" />

Expand All @@ -90,10 +78,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText12"
tools:text="12" />

Expand All @@ -108,10 +93,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText13"
tools:text="13" />

Expand All @@ -126,10 +108,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText14"
tools:text="14" />

Expand Down
21 changes: 0 additions & 21 deletions materialcalendarview/src/main/res/layout/week_view3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText15"
tools:text="15" />

Expand All @@ -36,10 +33,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText16"
tools:text="16" />

Expand All @@ -54,10 +48,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText17"
tools:text="17" />

Expand All @@ -72,10 +63,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText18"
tools:text="18" />

Expand All @@ -90,10 +78,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText19"
tools:text="19" />

Expand All @@ -108,10 +93,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText20"
tools:text="20" />

Expand All @@ -126,10 +108,7 @@

<io.blackbox_vision.materialcalendarview.view.DayView
style="@style/CalendarView.DayOfTheMonth"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:gravity="center"
android:tag="dayOfMonthText21"
tools:text="21" />

Expand Down
Loading

0 comments on commit ea3f5cb

Please sign in to comment.