Skip to content

Commit

Permalink
Fix support Android 4.3 and below.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkil committed Dec 29, 2016
1 parent 34cc5ea commit bbaf48d
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs)
private val snowflakesAlreadyFalling: Boolean

private val updateSnowflakesThread: UpdateSnowflakesThread
private var snowflakes: Array<Snowflake>
private var snowflakes: Array<Snowflake>? = null

init {
val a = context.obtainStyledAttributes(attrs, R.styleable.SnowfallView)
Expand All @@ -69,7 +69,6 @@ class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs)
a.recycle()
}
updateSnowflakesThread = UpdateSnowflakesThread()
snowflakes = emptyArray()
}

private fun dpToPx(dp: Int): Int {
Expand All @@ -84,7 +83,7 @@ class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs)
override fun onVisibilityChanged(changedView: View, visibility: Int) {
super.onVisibilityChanged(changedView, visibility)
if (changedView === this && visibility == GONE) {
snowflakes.forEach { it.reset() }
snowflakes?.forEach { it.reset() }
}
}

Expand All @@ -93,7 +92,7 @@ class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs)
if (isInEditMode) {
return
}
snowflakes.forEach { it.draw(canvas) }
snowflakes?.forEach { it.draw(canvas) }
updateSnowflakes()
}

Expand All @@ -116,7 +115,7 @@ class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs)

private fun updateSnowflakes() {
updateSnowflakesThread.handler.post {
snowflakes.forEach { it.update() }
snowflakes?.forEach { it.update() }
postInvalidateOnAnimation()
}
}
Expand Down

0 comments on commit bbaf48d

Please sign in to comment.