From 77b261700263e10d896a44a9f1263e5cee28973c Mon Sep 17 00:00:00 2001 From: Uday Srinath Date: Wed, 5 Sep 2018 14:11:15 -0700 Subject: [PATCH 1/3] Added attribute to distinguish text color for dayOfWeek from dayOfMonth on calendarView --- README.md | 3 ++- app/src/main/res/layout/activity_main.xml | 3 ++- .../materialcalendarview/view/CalendarView.java | 16 ++++++++++++---- .../src/main/res/values/attrs.xml | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6c5f3c1..efd5b05 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index bba02dc..7f38dd7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -49,7 +49,8 @@ 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" diff --git a/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java b/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java index 2e85433..9a2c2c8 100644 --- a/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java +++ b/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java @@ -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; @@ -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); @@ -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; } } @@ -578,7 +580,7 @@ private void drawAdapterView() { } if (isCommonDay) { - textView.setTextColor(dayOfWeekTextColor); + textView.setTextColor(dayOfMonthTextColor); } if (day.isCurrentDay()) { @@ -626,7 +628,7 @@ private void clearDayViewSelection(Date currentDate) { } if (isCommonDay) { - dayView.setTextColor(dayOfWeekTextColor); + dayView.setTextColor(dayOfMonthTextColor); } } } @@ -1290,6 +1292,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(); diff --git a/materialcalendarview/src/main/res/values/attrs.xml b/materialcalendarview/src/main/res/values/attrs.xml index f634e26..ca74a6e 100644 --- a/materialcalendarview/src/main/res/values/attrs.xml +++ b/materialcalendarview/src/main/res/values/attrs.xml @@ -13,6 +13,7 @@ + From 49c27c2082ef7cfc80bb40a80001baffa92cc7c9 Mon Sep 17 00:00:00 2001 From: Uday Srinath Date: Wed, 5 Sep 2018 17:24:32 -0700 Subject: [PATCH 2/3] Fixed alignment for dayOfWeek and dayOfMonth, cleanup layouts, moved to styles --- .../src/main/res/layout/week_view1.xml | 21 ------------------- .../src/main/res/layout/week_view2.xml | 21 ------------------- .../src/main/res/layout/week_view3.xml | 21 ------------------- .../src/main/res/layout/week_view4.xml | 21 ------------------- .../src/main/res/layout/week_view5.xml | 21 ------------------- .../src/main/res/layout/week_view6.xml | 21 ------------------- .../src/main/res/values/styles.xml | 7 +++++-- 7 files changed, 5 insertions(+), 128 deletions(-) diff --git a/materialcalendarview/src/main/res/layout/week_view1.xml b/materialcalendarview/src/main/res/layout/week_view1.xml index 43788d7..5473fe3 100644 --- a/materialcalendarview/src/main/res/layout/week_view1.xml +++ b/materialcalendarview/src/main/res/layout/week_view1.xml @@ -18,9 +18,6 @@ @@ -36,9 +33,6 @@ @@ -54,9 +48,6 @@ @@ -91,10 +79,7 @@ @@ -109,10 +94,7 @@ @@ -127,10 +109,7 @@ diff --git a/materialcalendarview/src/main/res/layout/week_view2.xml b/materialcalendarview/src/main/res/layout/week_view2.xml index 7e77bfe..8812d58 100644 --- a/materialcalendarview/src/main/res/layout/week_view2.xml +++ b/materialcalendarview/src/main/res/layout/week_view2.xml @@ -18,10 +18,7 @@ @@ -36,10 +33,7 @@ @@ -54,10 +48,7 @@ @@ -72,10 +63,7 @@ @@ -90,10 +78,7 @@ @@ -108,10 +93,7 @@ @@ -126,10 +108,7 @@ diff --git a/materialcalendarview/src/main/res/layout/week_view3.xml b/materialcalendarview/src/main/res/layout/week_view3.xml index 9d04a9c..5418739 100644 --- a/materialcalendarview/src/main/res/layout/week_view3.xml +++ b/materialcalendarview/src/main/res/layout/week_view3.xml @@ -18,10 +18,7 @@ @@ -36,10 +33,7 @@ @@ -54,10 +48,7 @@ @@ -72,10 +63,7 @@ @@ -90,10 +78,7 @@ @@ -108,10 +93,7 @@ @@ -126,10 +108,7 @@ diff --git a/materialcalendarview/src/main/res/layout/week_view4.xml b/materialcalendarview/src/main/res/layout/week_view4.xml index 6c2968c..cf3406c 100644 --- a/materialcalendarview/src/main/res/layout/week_view4.xml +++ b/materialcalendarview/src/main/res/layout/week_view4.xml @@ -18,10 +18,7 @@ @@ -36,10 +33,7 @@ @@ -54,10 +48,7 @@ @@ -72,10 +63,7 @@ @@ -90,10 +78,7 @@ @@ -108,10 +93,7 @@ @@ -126,10 +108,7 @@ diff --git a/materialcalendarview/src/main/res/layout/week_view5.xml b/materialcalendarview/src/main/res/layout/week_view5.xml index fad4efc..ebf6da5 100644 --- a/materialcalendarview/src/main/res/layout/week_view5.xml +++ b/materialcalendarview/src/main/res/layout/week_view5.xml @@ -18,10 +18,7 @@ @@ -36,10 +33,7 @@ @@ -54,10 +48,7 @@ @@ -72,10 +63,7 @@ @@ -90,10 +78,7 @@ @@ -108,10 +93,7 @@ @@ -126,10 +108,7 @@ diff --git a/materialcalendarview/src/main/res/layout/week_view6.xml b/materialcalendarview/src/main/res/layout/week_view6.xml index 41d80de..1778501 100644 --- a/materialcalendarview/src/main/res/layout/week_view6.xml +++ b/materialcalendarview/src/main/res/layout/week_view6.xml @@ -18,10 +18,7 @@ @@ -36,10 +33,7 @@ @@ -54,10 +48,7 @@ @@ -72,10 +63,7 @@ @@ -90,10 +78,7 @@ @@ -108,10 +93,7 @@ @@ -126,10 +108,7 @@ diff --git a/materialcalendarview/src/main/res/values/styles.xml b/materialcalendarview/src/main/res/values/styles.xml index 552a9e2..8eecb78 100644 --- a/materialcalendarview/src/main/res/values/styles.xml +++ b/materialcalendarview/src/main/res/values/styles.xml @@ -17,7 +17,7 @@ @@ -25,6 +25,9 @@ - \ No newline at end of file + From 93d1a2eabcf8252aa79ee9f826d75eb1ad7079a9 Mon Sep 17 00:00:00 2001 From: Uday Srinath Date: Thu, 13 Sep 2018 16:07:06 -0700 Subject: [PATCH 3/3] Differentiate currentDayTextColor uniquely from selectedDayTextColor, enabling current day to have a different text color even when it is not the selected date --- app/src/main/res/layout/activity_main.xml | 5 +++-- .../materialcalendarview/view/CalendarView.java | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7f38dd7..1d5f64a 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -48,7 +48,8 @@ app:calendarIsOverflowDatesVisible="true" app:calendarBackgroundColor="@color/colorPrimary" app:calendarTitleTextColor="@color/colorAccent" - app:calendarCurrentDayTextColor="@color/white" + app:calendarCurrentDayTextColor="@color/colorAccent" + app:calendarSelectedDayTextColor="@color/white" app:calendarDayOfWeekTextColor="@color/grey" app:calendarDayOfMonthTextColor="@android:color/white" app:calendarDisabledDayBackgroundColor="@color/colorPrimary" @@ -57,7 +58,7 @@ 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"> diff --git a/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java b/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java index 9a2c2c8..c1b81bc 100644 --- a/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java +++ b/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java @@ -616,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) { @@ -629,6 +629,8 @@ private void clearDayViewSelection(Date currentDate) { if (isCommonDay) { dayView.setTextColor(dayOfMonthTextColor); + } else { + dayView.setTextColor(currentDayTextColor); } } } @@ -692,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);