@@ -77,23 +77,16 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
7777 mCurrentOrigin.x = 0f
7878 invalidate()
7979 }
80- private val mTimeTextPaint: Paint = Paint (Paint .ANTI_ALIAS_FLAG )
81- private var mTimeTextWidth: Float = 0f
82- private var mTimeTextHeight: Float = 0f
80+ private val mTimeTextPaint = TextPaint (Paint .ANTI_ALIAS_FLAG )
8381 private val mHeaderWeekDayTitleTextPaint = TextPaint (Paint .ANTI_ALIAS_FLAG )
84- private var mHeaderWeekDayTitleTextHeight: Float = 0f
85- private var mHeaderHeight: Float = 0f
8682 private val mHeaderWeekDaySubtitleTextPaint = TextPaint (Paint .ANTI_ALIAS_FLAG )
87- private var mHeaderWeekDaySubtitleTextHeight: Float = 0f
8883 private val mHeaderWeekDayTitleTodayTextPaint = TextPaint (Paint .ANTI_ALIAS_FLAG )
8984 private val mHeaderWeekDaySubtitleTodayTextPaint = TextPaint (Paint .ANTI_ALIAS_FLAG )
90- private var mGestureDetector: GestureDetectorCompat ? = null
91- private var mScroller: OverScroller ? = null
92- private val mCurrentOrigin = PointF (0f , 0f )
93- private var mCurrentScrollDirection = Direction .NONE
85+ private val mEventTextPaint = TextPaint (Paint .ANTI_ALIAS_FLAG or Paint .LINEAR_TEXT_FLAG )
86+ private val sideTitleTextPaint = TextPaint (Paint .ANTI_ALIAS_FLAG )
87+ private val allDaySideTitleTextPaint = TextPaint (Paint .ANTI_ALIAS_FLAG )
9488 private val mEmptyEventPaint = Paint ()
9589 private val mHeaderBackgroundPaint: Paint = Paint ()
96- private var mWidthPerDay: Float = 0f
9790 private val mDayBackgroundPaint: Paint = Paint ()
9891 private val mHourSeparatorPaint = Paint ()
9992 private val mTodayColumnBackgroundPaint: Paint = Paint ()
@@ -104,11 +97,20 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
10497 private val mNowLinePaint = Paint ()
10598 private val mEventBackgroundPaint = Paint ()
10699 private val mNewEventBackgroundPaint = Paint ()
100+ private var containsAllDayEvent: Boolean = false
101+ private var mTimeTextWidth: Float = 0f
102+ private var mTimeTextHeight: Float = 0f
103+ private var mHeaderWeekDayTitleTextHeight: Float = 0f
104+ private var mHeaderHeight: Float = 0f
105+ private var mHeaderWeekDaySubtitleTextHeight: Float = 0f
106+ private var mGestureDetector: GestureDetectorCompat ? = null
107+ private var mScroller: OverScroller ? = null
108+ private val mCurrentOrigin = PointF (0f , 0f )
109+ private var mCurrentScrollDirection = Direction .NONE
110+ private var mWidthPerDay: Float = 0f
107111 private var mHeaderColumnWidth: Float = 0f
108112 private var mEventRects: MutableList <EventRect >? = null
109113 private var mEvents: MutableList <WeekViewEvent >? = null
110- private val mEventTextPaint = TextPaint (Paint .ANTI_ALIAS_FLAG or Paint .LINEAR_TEXT_FLAG )
111- private val mHeaderColumnBackgroundPaint: Paint = Paint ()
112114 private var mFetchedPeriod = - 1 // the middle period the calendar has fetched.
113115 private var mRefreshEvents = false
114116 private var mCurrentFlingDirection = Direction .NONE
@@ -139,8 +141,6 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
139141 private var mDistanceMin: Float = 0f
140142 private var mOffsetValueToSecureScreen = 9
141143 private var mStartOriginForScroll = 0f
142-
143- // Attributes and their default values.
144144 private var mNewHourHeight = - 1
145145 var minHourHeight = 0
146146 // no minimum specified (will be dynamic, based on screen)
@@ -152,7 +152,6 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
152152 var newEventLengthInMinutes = 60
153153 var newEventTimeResolutionInMinutes = 15
154154 var isShowFirstDayOfWeekFirst = false
155-
156155 private var mIsFirstDraw = true
157156 private var mAreDimensionsInvalid = true
158157 /* *
@@ -176,7 +175,7 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
176175 /* *
177176 * the height of AllDay-events.
178177 */
179- var allDayEventHeight = 100
178+ var allDayEventHeight = TypedValue .applyDimension( TypedValue . COMPLEX_UNIT_DIP , 40f , resources.displayMetrics).toInt()
180179 /* *
181180 * If you set this to false the `zoomFocusPoint` won't take effect any more while zooming.
182181 * The zoom will always be focused at the center of your gesture.
@@ -193,6 +192,13 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
193192 init ()
194193 }
195194 }
195+ var allDaySideTitleText: String? = null
196+ set(value) {
197+ if (value == field)
198+ return
199+ field = value
200+ invalidate()
201+ }
196202
197203 private var mMinTime = 0
198204 private var mMaxTime = 24
@@ -245,8 +251,6 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
245251 field = value
246252 invalidate()
247253 }
248- private val sideTitleTextPaint = Paint (Paint .ANTI_ALIAS_FLAG )
249-
250254
251255 private val mGestureListener = object : GestureDetector .SimpleOnGestureListener () {
252256 override fun onDown (e : MotionEvent ): Boolean {
@@ -633,7 +637,7 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
633637 return
634638 field = value
635639 mTimeTextPaint.textSize = value
636- sideTitleTextPaint .textSize = value
640+ allDaySideTitleTextPaint .textSize = value
637641 invalidate()
638642 }
639643
@@ -678,9 +682,21 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
678682 mHeaderWeekDaySubtitleTextPaint.color = value
679683 mTimeTextPaint.color = value
680684 sideTitleTextPaint.color = value
685+ allDaySideTitleTextPaint.color = value
686+ invalidate()
687+ }
688+
689+ @ColorInt
690+ var allDaySideTitleTextColor = headerColumnTextColor
691+ set(value) {
692+ if (field == value)
693+ return
694+ field = value
695+ allDaySideTitleTextPaint.color = value
681696 invalidate()
682697 }
683698
699+
684700 @ColorInt
685701 var headerRowBackgroundColor: Int = Color .WHITE
686702 set(value) {
@@ -768,16 +784,6 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
768784 invalidate()
769785 }
770786
771- @ColorInt
772- var headerColumnBackgroundColor: Int = Color .WHITE
773- set(value) {
774- if (field == value)
775- return
776- field = value
777- mHeaderColumnBackgroundPaint.color = value
778- invalidate()
779- }
780-
781787 @ColorInt
782788 var defaultEventColor: Int = 0
783789 set(value) {
@@ -1030,7 +1036,6 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
10301036 newEventLengthInMinutes = a.getInt(R .styleable.WeekView_newEventLengthInMinutes , newEventLengthInMinutes)
10311037 newEventTimeResolutionInMinutes = a.getInt(R .styleable.WeekView_newEventTimeResolutionInMinutes , newEventTimeResolutionInMinutes)
10321038 eventPadding = a.getDimensionPixelSize(R .styleable.WeekView_eventPadding , eventPadding)
1033- headerColumnBackgroundColor = a.getColor(R .styleable.WeekView_headerColumnBackground , headerColumnBackgroundColor)
10341039 dayNameLength = a.getInteger(R .styleable.WeekView_dayNameLength , dayNameLength)
10351040 overlappingEventGap = a.getDimensionPixelSize(R .styleable.WeekView_overlappingEventGap , overlappingEventGap)
10361041 spaceBetweenWeekDaysAndAllDayEvents = a.getDimensionPixelSize(R .styleable.WeekView_spaceBetweenWeekDaysAndAllDayEvents , spaceBetweenWeekDaysAndAllDayEvents)
@@ -1063,6 +1068,7 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
10631068 mHeaderWeekDayTitleTextPaint.textAlign = Paint .Align .CENTER
10641069 mHeaderWeekDaySubtitleTextPaint.textAlign = Paint .Align .CENTER
10651070 sideTitleTextPaint.textAlign = Paint .Align .CENTER
1071+ allDaySideTitleTextPaint.textAlign = Paint .Align .CENTER
10661072 mTimeTextPaint.textAlign = Paint .Align .RIGHT
10671073 mEventTextPaint.style = Paint .Style .FILL
10681074 mHourSeparatorPaint.style = Paint .Style .STROKE
@@ -1095,10 +1101,14 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
10951101 initTextTimeWidth()
10961102
10971103 // handle sideTitleTextPaint
1098- sideTitleTextPaint.textSize = textSize
10991104 sideTitleTextPaint.color = headerColumnTextColor
11001105 sideTitleTextPaint.typeface = typeface
11011106
1107+ // handle allDaySideTitleTextPaint
1108+ allDaySideTitleTextPaint.textSize = textSize
1109+ allDaySideTitleTextPaint.color = allDaySideTitleTextColor
1110+ allDaySideTitleTextPaint.typeface = typeface
1111+
11021112 // Measure settings for header row.
11031113 // TODO measure the text that will actually be used, based on the locale and dates. Important because various characters might look different.
11041114 val sampleText = " ABCDEFGHIKLMNOPQRSTUVWXYZabcdefghiklmnopqrstuvwxyz0123456789"
@@ -1151,9 +1161,6 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
11511161 // Prepare empty event background color.
11521162 mNewEventBackgroundPaint.color = Color .rgb(60 , 147 , 217 )
11531163
1154- // Prepare header column background color.
1155- mHeaderColumnBackgroundPaint.color = headerColumnBackgroundColor
1156-
11571164 // Prepare event text size and color.
11581165 mEventTextPaint.color = eventTextColor
11591166 mEventTextPaint.textSize = eventTextSize
@@ -1229,20 +1236,20 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
12291236
12301237 private fun calculateHeaderHeight () {
12311238 // Make sure the header is the right size (depends on AllDay events)
1232- var containsAllDayEvent = false
1239+ containsAllDayEvent = false
12331240 if (mEventRects != null && mEventRects!! .size > 0 ) {
1241+ val day = firstVisibleDay!! .clone() as Calendar
12341242 for (dayNumber in 0 until realNumberOfVisibleDays) {
1235- val day = firstVisibleDay!! .clone() as Calendar
1236- day.add(Calendar .DATE , dayNumber)
12371243 for (i in mEventRects!! .indices) {
1238- if (isSameDay(mEventRects!! [i].event.startTime!! , day) && mEventRects!! [i].event.isAllDay) {
1244+ val event = mEventRects!! [i].event
1245+ if (isSameDay(event.startTime!! , day) && event.isAllDay) {
12391246 containsAllDayEvent = true
12401247 break
12411248 }
12421249 }
1243- if (containsAllDayEvent) {
1250+ if (containsAllDayEvent)
12441251 break
1245- }
1252+ day.add( Calendar . DATE , 1 )
12461253 }
12471254 }
12481255 mHeaderHeight = if (containsAllDayEvent) {
@@ -1255,9 +1262,6 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
12551262 }
12561263
12571264 private fun drawTimeColumnAndAxes (canvas : Canvas ) {
1258- // Draw the background color for the header column.
1259- canvas.drawRect(0f , mHeaderHeight + weekDaysHeaderRowPadding * 2 , mHeaderColumnWidth, height.toFloat(), mHeaderColumnBackgroundPaint)
1260- canvas.restore()
12611265 canvas.save()
12621266 // Clip to paint in left column only.
12631267 canvas.clipRect(0.0f , mHeaderHeight + weekDaysHeaderRowPadding * 2 , mHeaderColumnWidth, height.toFloat())
@@ -1490,6 +1494,7 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
14901494 canvas.save()
14911495 canvas.clipRect(mHeaderColumnWidth, 0f , width.toFloat(), mHeaderHeight + weekDaysHeaderRowPadding * 2 )
14921496
1497+
14931498 // Draw the header background.
14941499 if (enableDrawHeaderBackgroundOnlyOnWeekDays)
14951500 canvas.drawRect(0f , 0f , width.toFloat(), headerTitleAndSubtitleTextHeight + weekDaysHeaderRowPadding * 2 , mHeaderBackgroundPaint)
@@ -1524,11 +1529,24 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
15241529 canvas.drawText(subtitleText, startPixel + mWidthPerDay / 2 , headerTitleAndSubtitleTextHeight + weekDaysHeaderRowPadding,
15251530 if (isToday) mHeaderWeekDaySubtitleTodayTextPaint else mHeaderWeekDaySubtitleTextPaint)
15261531 }
1527- drawAllDayEvents(day, startPixel, canvas)
1532+ if (containsAllDayEvent)
1533+ drawAllDayEvents(day, startPixel, canvas)
15281534 startPixel + = mWidthPerDay + columnGap
15291535 day.add(Calendar .DAY_OF_YEAR , 1 )
15301536 }
15311537 }
1538+ canvas.restore()
1539+ // draw text on the left of the all-day events
1540+ if (containsAllDayEvent && ! TextUtils .isEmpty(allDaySideTitleText)) {
1541+ canvas.save()
1542+ val headerTitleAndSubtitleTextHeight = mHeaderWeekDayTitleTextHeight + (if (isSubtitleHeaderEnabled) mHeaderWeekDaySubtitleTextHeight + spaceBetweenHeaderWeekDayTitleAndSubtitle else 0.0f )
1543+ val weekDaysHeight = headerTitleAndSubtitleTextHeight + weekDaysHeaderRowPadding * 2
1544+ val top = weekDaysHeight + spaceBetweenWeekDaysAndAllDayEvents + mTimeTextHeight / 2
1545+ val bottom = top + allDayEventHeight
1546+ canvas.clipRect(0f , 0f , top, bottom)
1547+ canvas.drawText(allDaySideTitleText, mHeaderColumnWidth / 2 , (top+ bottom)/ 2 , allDaySideTitleTextPaint)
1548+ canvas.restore()
1549+ }
15321550 }
15331551
15341552 /* *
@@ -1647,7 +1665,7 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
16471665 * @param canvas The canvas to draw upon.
16481666 */
16491667 private fun drawAllDayEvents (date : Calendar , startFromPixel : Float , canvas : Canvas ) {
1650- if (mEventRects != null && mEventRects!! .size > 0 ) {
1668+ if (mEventRects != null && mEventRects!! .isNotEmpty() ) {
16511669 val headerTitleAndSubtitleTextHeight = mHeaderWeekDayTitleTextHeight + (if (isSubtitleHeaderEnabled) mHeaderWeekDaySubtitleTextHeight + spaceBetweenHeaderWeekDayTitleAndSubtitle else 0.0f )
16521670
16531671 for (i in mEventRects!! .indices) {
0 commit comments