Skip to content

Commit 3397c11

Browse files
authored
Merge branch 'master' into feature/add-setting-for-display-outside-this-month
2 parents 3f99f1f + 7fc134d commit 3397c11

File tree

8 files changed

+57
-3
lines changed

8 files changed

+57
-3
lines changed

javasample/src/main/java/jp/co/recruit_mp/android/lightcalendarview/javasample/MainActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
4646

4747
// 前月・翌月を表示する
4848
calendarView.setDisplayOutside(true);
49+
// 当日の強調表示固定
50+
calendarView.setFixToday(true);
4951

5052
calendarView.setOnMonthSelected(new Function2<Date, MonthView, Unit>() {
5153
@Override
@@ -57,11 +59,16 @@ public Unit invoke(Date date, final MonthView monthView) {
5759
public void run() {
5860
Calendar cal = Calendar.getInstance();
5961
List<Date> dates = new ArrayList<Date>();
62+
List<Date> holidays = new ArrayList<Date>();
6063
for (int i = 0; i < 31; i++) {
6164
if (i % 2 == 0) {
6265
cal.set(monthView.getMonth().getYear() + 1900, monthView.getMonth().getMonth(), i);
6366
dates.add(cal.getTime());
6467
}
68+
if (i < 7) {
69+
cal.set(monthView.getMonth().getYear() + 1900, monthView.getMonth().getMonth(), i);
70+
holidays.add(cal.getTime());
71+
}
6572
}
6673
HashMap<Date, List<Accent>> map = new HashMap<>();
6774
for (Date date : dates) {
@@ -72,6 +79,8 @@ public void run() {
7279
map.put(date, accents);
7380
}
7481
monthView.setAccents(map);
82+
// 祝日を設定
83+
monthView.setHolidays(holidays);
7584
}
7685
}, 1000);
7786

javasample/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
app:lcv_selectionColor="@color/calendar_selection"
3030
app:lcv_accentColor="@color/calendar_accent"
3131
app:lcv_outsideTextColor="#ccc"
32+
app:lcv_holidayTextColor="#CD0303"
3233
app:lcv_firstDayOfWeek="@integer/lcv_monday"/>
3334

3435
</LinearLayout>

library/src/main/kotlin/jp/co/recruit_mp/android/lightcalendarview/CalendarSettings.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class CalendarSettings(private val context: Context) : ObservableSettings() {
3737
var locale: Locale = Locale.getDefault()
3838
var displayOutside: Boolean = false
3939

40+
// 当日を常に強調表示
41+
var fixToday: Boolean = false
42+
4043
// settings for DayLayout and WeekDayLayout: first day of the week
4144
var firstDayOfWeek: WeekDay = WeekDay.SUNDAY
4245
val dayOfWeekOffset: Int
@@ -171,6 +174,7 @@ class CalendarSettings(private val context: Context) : ObservableSettings() {
171174
internal fun defaultTextPaint(weekDay: WeekDay): Paint = defaultTextPaints[weekDay] ?: throw IllegalStateException("cannot find default Paint with weekDay - $weekDay")
172175

173176
internal var outsideTextPaint: Paint = initializeOutsideTextPaint()
177+
internal var holidayTextPaint: Paint = initializeHolidayTextPaint()
174178
internal var defaultTextPaints: Map<WeekDay, Paint> = initializedDefaultTextPaints()
175179
internal var todayTextPaint: Paint = initializedTodayTextPaint()
176180
internal var selectedTextPaint: Paint = initializeSelectedTextPaint()
@@ -181,6 +185,7 @@ class CalendarSettings(private val context: Context) : ObservableSettings() {
181185
}.toMap()
182186

183187
private fun initializeOutsideTextPaint() = baseTextPaint.copy().color(context.getStyledColor(android.R.attr.textColorPrimary, context.getColorCompat(R.color.light_calendar_view__day_today_text_color)))
188+
private fun initializeHolidayTextPaint() = baseTextPaint.copy().color(context.getStyledColor(android.R.attr.textColorPrimary, context.getColorCompat(R.color.light_calendar_view__day_today_text_color)))
184189
private fun initializedTodayTextPaint() = baseTextPaint.copy().color(context.getStyledColor(android.R.attr.textColorPrimary, context.getColorCompat(R.color.light_calendar_view__day_today_text_color)))
185190
private fun initializeSelectedTextPaint() = baseTextPaint.copy().typeface(Typeface.DEFAULT_BOLD).color(context.getStyledColor(android.R.attr.textColorPrimaryInverse, context.getColorCompat(R.color.light_calendar_view__day_selected_text_color)))
186191
private fun initializedSelectedTodayTextPaint() = baseTextPaint.copy().typeface(Typeface.DEFAULT_BOLD).color(context.getStyledColor(android.R.attr.textColorPrimaryInverse, context.getColorCompat(R.color.light_calendar_view__day_selected_today_text_color)))
@@ -213,6 +218,10 @@ class CalendarSettings(private val context: Context) : ObservableSettings() {
213218
outsideTextPaint.color = color
214219
}
215220

221+
internal fun setHolidayTextColorStateList(color: Int) {
222+
holidayTextPaint.color = color
223+
}
224+
216225
internal fun setTextFilterColor(weekDay: WeekDay, color: Int?) {
217226
textFilterColorMap[weekDay] = color
218227
defaultTextPaints[weekDay]?.colorFilter(textFilterColorMap[weekDay]?.let { color -> PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP) } ?: throw IllegalStateException("Day color map for $weekDay not found."))

library/src/main/kotlin/jp/co/recruit_mp/android/lightcalendarview/DayLayout.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package jp.co.recruit_mp.android.lightcalendarview
1818

1919
import android.content.Context
2020
import android.support.v4.view.ViewCompat
21-
import android.util.Log
21+
import android.text.format.DateUtils
2222
import java.util.*
2323

2424
/**
@@ -140,8 +140,11 @@ class DayLayout(context: Context, settings: CalendarSettings, var month: Date) :
140140

141141
private fun setSelectedDay(view: DayView?) {
142142
selectedDayView?.apply {
143-
isSelected = false
144-
updateState()
143+
if (!settings.fixToday || !DateUtils.isToday(selectedDayView?.date!!.time)) {
144+
// 今日の場合は常に丸を表示させる
145+
isSelected = false
146+
updateState()
147+
}
145148
}
146149
selectedDayView = view?.apply {
147150
isSelected = true

library/src/main/kotlin/jp/co/recruit_mp/android/lightcalendarview/DayView.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class DayView(context: Context, settings: CalendarSettings, cal: Calendar) : Cel
5555

5656
private var drawCircle: Boolean = false
5757
private var isOutside: Boolean = false
58+
private var isHoliday: Boolean = false
5859

5960
private var radius: Float = 0f
6061
private var currentRadius: Float = 0f
@@ -114,6 +115,10 @@ class DayView(context: Context, settings: CalendarSettings, cal: Calendar) : Cel
114115
fun setOutside():DayView {
115116
this.isOutside = true
116117
return this
118+
// 祝日に設定
119+
fun setHoliday() {
120+
this.isHoliday = true
121+
updatePaint();
117122
}
118123
// 各アクセントの位置を設定する
119124
private fun layoutAccents() {
@@ -215,6 +220,9 @@ class DayView(context: Context, settings: CalendarSettings, cal: Calendar) : Cel
215220
}
216221
isOutside -> {
217222
textPaint = settings.dayView.outsideTextPaint
223+
// 祝日の設定
224+
isHoliday -> {
225+
textPaint = settings.dayView.holidayTextPaint
218226
accentPaint = settings.dayView.defaultAccentPaint
219227
}
220228
else -> {

library/src/main/kotlin/jp/co/recruit_mp/android/lightcalendarview/LightCalendarView.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class LightCalendarView(context: Context, attrs: AttributeSet? = null, defStyleA
8080
R.styleable.LightCalendarView_lcv_accentColor -> setAccentColor(a.getColorStateList(attr))
8181
R.styleable.LightCalendarView_lcv_firstDayOfWeek -> setFirstDayOfWeek(a.getInt(attr, 0))
8282
R.styleable.LightCalendarView_lcv_outsideTextColor -> setOutsideTextColor(a.getColor(attr, 0))
83+
R.styleable.LightCalendarView_lcv_holidayTextColor -> setHolidayTextColor(a.getColor(attr, 0))
8384
}
8485
}
8586
a.recycle()
@@ -186,6 +187,14 @@ class LightCalendarView(context: Context, attrs: AttributeSet? = null, defStyleA
186187
setOutsideTextColorStateList(color)
187188
}.notifySettingsChanged()
188189
}
190+
/**
191+
* 祝日の文字色を設定する
192+
*/
193+
fun setHolidayTextColor(color: Int) {
194+
settings.dayView.apply {
195+
setHolidayTextColorStateList(color)
196+
}.notifySettingsChanged()
197+
}
189198

190199
/**
191200
* 日付ビューの選択時の背景色を設定する
@@ -256,6 +265,13 @@ class LightCalendarView(context: Context, attrs: AttributeSet? = null, defStyleA
256265
}.notifySettingsChanged()
257266
}
258267

268+
var fixToday: Boolean
269+
get() = settings.fixToday
270+
set(value) {
271+
settings.apply {
272+
fixToday = value
273+
}.notifySettingsChanged()
274+
}
259275
/**
260276
* Sets the locale to use in LightCalendarView.
261277
* Set null to use Locale.getDefault()

library/src/main/kotlin/jp/co/recruit_mp/android/lightcalendarview/MonthView.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ class MonthView(context: Context, settings: CalendarSettings, var month: Date) :
5959
dayLayout.invalidateDayViews()
6060
}
6161

62+
// 祝日追加
63+
fun setHolidays(map: Collection<Date>) {
64+
map.forEach { it ->
65+
val date = it
66+
dayLayout.getDayView(date)?.setHoliday();
67+
}
68+
}
6269

6370
override fun toString(): String = "MonthView($month)"
6471
}

library/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<attr name="lcv_accentColor" format="reference|color" />
99
<attr name="lcv_firstDayOfWeek" format="integer" />
1010
<attr name="lcv_outsideTextColor" format="reference|color" />
11+
<attr name="lcv_holidayTextColor" format="reference|color" />
1112
</declare-styleable>
1213
</resources>

0 commit comments

Comments
 (0)