mark current day in the yearly view with a circle

This commit is contained in:
tibbi 2016-10-22 20:43:48 +02:00
parent 761c45c414
commit f490ddf1ee
2 changed files with 17 additions and 5 deletions

View File

@ -68,8 +68,10 @@ class YearFragment : Fragment(), YearlyCalendar {
if (now.year == mYear) {
val monthLabel = mView.findViewById(res.getIdentifier("month_${now.monthOfYear}_label", "id", activity.packageName)) as TextView
monthLabel.setTextColor(Utils.adjustAlpha(res.getColor(R.color.colorPrimary), Constants.HIGH_ALPHA))
}
val monthView = mView.findViewById(res.getIdentifier("month_${now.monthOfYear}", "id", activity.packageName)) as SmallMonthView
monthView.setTodaysId(now.dayOfMonth)
}
}
fun setListener(listener: NavigationListener) {

View File

@ -20,6 +20,7 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
var mColoredTextColor = 0
var mDays = 31
var mFirstDay = 0
var mTodaysId = 0
var mEvents: ArrayList<Int>? = null
@ -40,6 +41,10 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
post { invalidate() }
}
fun setTodaysId(id: Int) {
mTodaysId = id
}
init {
val a = context.theme.obtainStyledAttributes(
attrs,
@ -76,13 +81,18 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
for (y in 1..6) {
for (x in 1..7) {
if (curId > 0 && curId <= mDays) {
if (mEvents?.contains(curId) == true)
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, mColoredPaint)
else
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, mPaint)
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, getPaint(curId))
if (curId == mTodaysId) {
canvas.drawCircle(x * mDayWidth - mDayWidth / 4, y * mDayWidth - mDayWidth / 4, mDayWidth * 0.41f, mColoredPaint)
}
}
curId++
}
}
}
private fun getPaint(curId: Int): Paint {
return if (mEvents?.contains(curId) == true) mColoredPaint else mPaint
}
}