mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-18 20:50:40 +01:00
make variables in smallMonthView private
This commit is contained in:
parent
97df40eee7
commit
77ae86f6ab
@ -13,27 +13,26 @@ import com.simplemobiletools.commons.extensions.adjustAlpha
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
|
class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
|
||||||
var mPaint: Paint
|
private var paint: Paint
|
||||||
var mColoredPaint: Paint
|
private var coloredPaint: Paint
|
||||||
var mDayWidth = 0f
|
private var dayWidth = 0f
|
||||||
var mTextColor = 0
|
private var textColor = 0
|
||||||
var mColoredTextColor = 0
|
private var coloredTextColor = 0
|
||||||
var mDays = 31
|
private var days = 31
|
||||||
var mFirstDay = 0
|
private var firstDay = 0
|
||||||
var mTodaysId = 0
|
private var todaysId = 0
|
||||||
var mIsLandscape = false
|
private var isLandscape = false
|
||||||
|
private var mEvents: ArrayList<Int>? = null
|
||||||
var mEvents: ArrayList<Int>? = null
|
|
||||||
|
|
||||||
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
||||||
|
|
||||||
fun setDays(days: Int) {
|
fun setDays(days: Int) {
|
||||||
mDays = days
|
this.days = days
|
||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setFirstDay(firstDay: Int) {
|
fun setFirstDay(firstDay: Int) {
|
||||||
mFirstDay = firstDay
|
this.firstDay = firstDay
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setEvents(events: ArrayList<Int>?) {
|
fun setEvents(events: ArrayList<Int>?) {
|
||||||
@ -42,55 +41,55 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setTodaysId(id: Int) {
|
fun setTodaysId(id: Int) {
|
||||||
mTodaysId = id
|
todaysId = id
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val a = context.theme.obtainStyledAttributes(
|
val attributes = context.theme.obtainStyledAttributes(
|
||||||
attrs,
|
attrs,
|
||||||
R.styleable.SmallMonthView,
|
R.styleable.SmallMonthView,
|
||||||
0, 0)
|
0, 0)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mDays = a.getInt(R.styleable.SmallMonthView_days, 31)
|
days = attributes.getInt(R.styleable.SmallMonthView_days, 31)
|
||||||
} finally {
|
} finally {
|
||||||
a.recycle()
|
attributes.recycle()
|
||||||
}
|
}
|
||||||
|
|
||||||
val baseColor = context.config.textColor
|
val baseColor = context.config.textColor
|
||||||
mTextColor = baseColor.adjustAlpha(MEDIUM_ALPHA)
|
textColor = baseColor.adjustAlpha(MEDIUM_ALPHA)
|
||||||
mColoredTextColor = context.config.primaryColor.adjustAlpha(MEDIUM_ALPHA)
|
coloredTextColor = context.config.primaryColor.adjustAlpha(MEDIUM_ALPHA)
|
||||||
|
|
||||||
mPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||||
color = mTextColor
|
color = textColor
|
||||||
textSize = resources.getDimensionPixelSize(R.dimen.year_view_day_text_size).toFloat()
|
textSize = resources.getDimensionPixelSize(R.dimen.year_view_day_text_size).toFloat()
|
||||||
textAlign = Paint.Align.RIGHT
|
textAlign = Paint.Align.RIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
mColoredPaint = Paint(mPaint)
|
coloredPaint = Paint(paint)
|
||||||
mColoredPaint.color = mColoredTextColor
|
coloredPaint.color = coloredTextColor
|
||||||
mIsLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDraw(canvas: Canvas) {
|
override fun onDraw(canvas: Canvas) {
|
||||||
super.onDraw(canvas)
|
super.onDraw(canvas)
|
||||||
if (mDayWidth == 0f) {
|
if (dayWidth == 0f) {
|
||||||
mDayWidth = if (mIsLandscape) {
|
dayWidth = if (isLandscape) {
|
||||||
(canvas.width / 9).toFloat()
|
(canvas.width / 9).toFloat()
|
||||||
} else {
|
} else {
|
||||||
(canvas.width / 7).toFloat()
|
(canvas.width / 7).toFloat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var curId = 1 - mFirstDay
|
var curId = 1 - firstDay
|
||||||
for (y in 1..6) {
|
for (y in 1..6) {
|
||||||
for (x in 1..7) {
|
for (x in 1..7) {
|
||||||
if (curId in 1..mDays) {
|
if (curId in 1..days) {
|
||||||
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, getPaint(curId))
|
canvas.drawText(curId.toString(), x * dayWidth, y * dayWidth, getPaint(curId))
|
||||||
|
|
||||||
if (curId == mTodaysId) {
|
if (curId == todaysId) {
|
||||||
val dividerConstant = if (mIsLandscape) 6 else 4
|
val dividerConstant = if (isLandscape) 6 else 4
|
||||||
canvas.drawCircle(x * mDayWidth - mDayWidth / dividerConstant, y * mDayWidth - mDayWidth / dividerConstant, mDayWidth * 0.41f, mColoredPaint)
|
canvas.drawCircle(x * dayWidth - dayWidth / dividerConstant, y * dayWidth - dayWidth / dividerConstant, dayWidth * 0.41f, coloredPaint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
curId++
|
curId++
|
||||||
@ -98,5 +97,5 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPaint(curId: Int) = if (mEvents?.contains(curId) == true) mColoredPaint else mPaint
|
private fun getPaint(curId: Int) = if (mEvents?.contains(curId) == true) coloredPaint else paint
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user