make variables in smallMonthView private

This commit is contained in:
tibbi 2017-09-10 12:17:21 +02:00
parent 97df40eee7
commit 77ae86f6ab
1 changed files with 32 additions and 33 deletions

View File

@ -13,27 +13,26 @@ import com.simplemobiletools.commons.extensions.adjustAlpha
import java.util.*
class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
var mPaint: Paint
var mColoredPaint: Paint
var mDayWidth = 0f
var mTextColor = 0
var mColoredTextColor = 0
var mDays = 31
var mFirstDay = 0
var mTodaysId = 0
var mIsLandscape = false
var mEvents: ArrayList<Int>? = null
private var paint: Paint
private var coloredPaint: Paint
private var dayWidth = 0f
private var textColor = 0
private var coloredTextColor = 0
private var days = 31
private var firstDay = 0
private var todaysId = 0
private var isLandscape = false
private var mEvents: ArrayList<Int>? = null
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
fun setDays(days: Int) {
mDays = days
this.days = days
invalidate()
}
fun setFirstDay(firstDay: Int) {
mFirstDay = firstDay
this.firstDay = firstDay
}
fun setEvents(events: ArrayList<Int>?) {
@ -42,55 +41,55 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
}
fun setTodaysId(id: Int) {
mTodaysId = id
todaysId = id
}
init {
val a = context.theme.obtainStyledAttributes(
val attributes = context.theme.obtainStyledAttributes(
attrs,
R.styleable.SmallMonthView,
0, 0)
try {
mDays = a.getInt(R.styleable.SmallMonthView_days, 31)
days = attributes.getInt(R.styleable.SmallMonthView_days, 31)
} finally {
a.recycle()
attributes.recycle()
}
val baseColor = context.config.textColor
mTextColor = baseColor.adjustAlpha(MEDIUM_ALPHA)
mColoredTextColor = context.config.primaryColor.adjustAlpha(MEDIUM_ALPHA)
textColor = baseColor.adjustAlpha(MEDIUM_ALPHA)
coloredTextColor = context.config.primaryColor.adjustAlpha(MEDIUM_ALPHA)
mPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = mTextColor
paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = textColor
textSize = resources.getDimensionPixelSize(R.dimen.year_view_day_text_size).toFloat()
textAlign = Paint.Align.RIGHT
}
mColoredPaint = Paint(mPaint)
mColoredPaint.color = mColoredTextColor
mIsLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
coloredPaint = Paint(paint)
coloredPaint.color = coloredTextColor
isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
if (mDayWidth == 0f) {
mDayWidth = if (mIsLandscape) {
if (dayWidth == 0f) {
dayWidth = if (isLandscape) {
(canvas.width / 9).toFloat()
} else {
(canvas.width / 7).toFloat()
}
}
var curId = 1 - mFirstDay
var curId = 1 - firstDay
for (y in 1..6) {
for (x in 1..7) {
if (curId in 1..mDays) {
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, getPaint(curId))
if (curId in 1..days) {
canvas.drawText(curId.toString(), x * dayWidth, y * dayWidth, getPaint(curId))
if (curId == mTodaysId) {
val dividerConstant = if (mIsLandscape) 6 else 4
canvas.drawCircle(x * mDayWidth - mDayWidth / dividerConstant, y * mDayWidth - mDayWidth / dividerConstant, mDayWidth * 0.41f, mColoredPaint)
if (curId == todaysId) {
val dividerConstant = if (isLandscape) 6 else 4
canvas.drawCircle(x * dayWidth - dayWidth / dividerConstant, y * dayWidth - dayWidth / dividerConstant, dayWidth * 0.41f, coloredPaint)
}
}
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
}