Skip to content

Commit

Permalink
Prepare version 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkil committed Dec 26, 2016
1 parent e55c343 commit a98bc1a
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ Change Log

_2016-12-26_

* Fixed lags.
* Support different start position on y-axis for snowflakes (attr `snowflakesAlreadyFalling`).
* Rename attr `snowflakeFadingEnabled` to `snowflakesFadingEnabled`.
* Fixed animation lags.
* Fixed API 15 support.


## Version 1.1.0

_2016-12-25_
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ Fully customized implementation:
android:layout_width="match_parent"
android:layout_height="match_parent"
app:snowflakesNum="250"
app:snowflakeAlphaMin="200"
app:snowflakeAlphaMax="250"
app:snowflakeAlphaMin="150"
app:snowflakeAlphaMax="255"
app:snowflakeAngleMax="5"
app:snowflakeSizeMin="8dp"
app:snowflakeSizeMax="32dp"
app:snowflakeSpeedMin="4"
app:snowflakeSpeedMax="12"
app:snowflakeFadingEnabled="true"
app:snowflakesFadingEnabled="true"
app:snowflakesAlreadyFalling="false"
app:snowflakeImage="@drawable/snowflake"/>
```

Expand Down
Binary file modified snowfall-sample/src/main/res/drawable-hdpi/snowflake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified snowfall-sample/src/main/res/drawable-mdpi/snowflake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified snowfall-sample/src/main/res/drawable-xhdpi/snowflake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified snowfall-sample/src/main/res/drawable-xxhdpi/snowflake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified snowfall-sample/src/main/res/drawable-xxxhdpi/snowflake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions snowfall-sample/src/main/res/layout/activity_snowfall.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:snowflakesNum="250"
app:snowflakeAlphaMin="200"
app:snowflakeAlphaMax="250"
app:snowflakeAlphaMin="150"
app:snowflakeAlphaMax="255"
app:snowflakeAngleMax="5"
app:snowflakeSizeMin="8dp"
app:snowflakeSizeMax="32dp"
app:snowflakeSpeedMin="4"
app:snowflakeSpeedMax="12"
app:snowflakeFadingEnabled="true"
app:snowflakesFadingEnabled="true"
app:snowflakesAlreadyFalling="false"
app:snowflakeImage="@drawable/snowflake"/>

</FrameLayout>
23 changes: 14 additions & 9 deletions snowfall/src/main/java/com/jetradarmobile/snowfall/SnowfallView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs)
private val DEFAULT_SNOWFLAKE_SIZE_MAX_IN_DP = 8
private val DEFAULT_SNOWFLAKE_SPEED_MIN = 2
private val DEFAULT_SNOWFLAKE_SPEED_MAX = 8
private val DEFAULT_SNOWFLAKE_FADING_ENABLED = false
private val DEFAULT_SNOWFLAKES_FADING_ENABLED = false
private val DEFAULT_SNOWFLAKES_ALREADY_FALLING = false

private val snowflakesNum: Int
private val snowflakeImage: Bitmap?
Expand All @@ -46,7 +47,8 @@ class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs)
private val snowflakeSizeMaxInPx: Int
private val snowflakeSpeedMin: Int
private val snowflakeSpeedMax: Int
private val snowflakeFadingEnabled: Boolean
private val snowflakesFadingEnabled: Boolean
private val snowflakesAlreadyFalling: Boolean

private val snowflakes: MutableList<Snowflake>
private val updateSnowflakesThread: UpdateSnowflakesThread
Expand All @@ -62,19 +64,15 @@ class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs)
snowflakeSizeMaxInPx = a.getDimensionPixelSize(R.styleable.SnowfallView_snowflakeSizeMax, dpToPx(DEFAULT_SNOWFLAKE_SIZE_MAX_IN_DP))
snowflakeSpeedMin = a.getInt(R.styleable.SnowfallView_snowflakeSpeedMin, DEFAULT_SNOWFLAKE_SPEED_MIN)
snowflakeSpeedMax = a.getInt(R.styleable.SnowfallView_snowflakeSpeedMax, DEFAULT_SNOWFLAKE_SPEED_MAX)
snowflakeFadingEnabled = a.getBoolean(R.styleable.SnowfallView_snowflakeFadingEnabled, DEFAULT_SNOWFLAKE_FADING_ENABLED)
snowflakesFadingEnabled = a.getBoolean(R.styleable.SnowfallView_snowflakesFadingEnabled, DEFAULT_SNOWFLAKES_FADING_ENABLED)
snowflakesAlreadyFalling = a.getBoolean(R.styleable.SnowfallView_snowflakesAlreadyFalling, DEFAULT_SNOWFLAKES_ALREADY_FALLING)
a.recycle()

snowflakes = ArrayList(snowflakesNum)

updateSnowflakesThread = UpdateSnowflakesThread()
}

private fun updateSnowflakes() {
updateSnowflakesThread.handler.post { snowflakes.forEach { it.update() } }
ViewCompat.postInvalidateOnAnimation(this)
}

private fun dpToPx(dp: Int): Int {
return (dp * resources.displayMetrics.density).toInt()
}
Expand All @@ -87,7 +85,7 @@ class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs)
alphaMin = snowflakeAlphaMin, alphaMax = snowflakeAlphaMax, angleMax = snowflakeAngleMax,
sizeMinInPx = snowflakeSizeMinInPx, sizeMaxInPx = snowflakeSizeMaxInPx,
speedMin = snowflakeSpeedMin, speedMax = snowflakeSpeedMax,
fadingEnabled = snowflakeFadingEnabled)
fadingEnabled = snowflakesFadingEnabled, alreadyFalling = snowflakesAlreadyFalling)
snowflakes.addAll(Array(snowflakesNum, { Snowflake(snowflakeParams) }))
}

Expand All @@ -97,6 +95,13 @@ class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs)
updateSnowflakes()
}

private fun updateSnowflakes() {
updateSnowflakesThread.handler.post {
snowflakes.forEach { it.update() }
ViewCompat.postInvalidateOnAnimation(this)
}
}

private inner class UpdateSnowflakesThread() : HandlerThread("SnowflakesComputations") {
val handler by lazy { Handler(looper) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ internal class Snowflake(val params: Params) {

init {
init()
if (!params.alreadyFalling) {
positionY = positionY - params.parentHeight - size
}
}

private fun init() {
Expand Down Expand Up @@ -96,5 +99,6 @@ internal class Snowflake(val params: Params) {
val sizeMaxInPx: Int,
val speedMin: Int,
val speedMax: Int,
val fadingEnabled: Boolean)
val fadingEnabled: Boolean,
val alreadyFalling: Boolean)
}
3 changes: 2 additions & 1 deletion snowfall/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<attr name="snowflakeSizeMax" format="dimension"/>
<attr name="snowflakeSpeedMin" format="integer"/>
<attr name="snowflakeSpeedMax" format="integer"/>
<attr name="snowflakeFadingEnabled" format="boolean"/>
<attr name="snowflakesFadingEnabled" format="boolean"/>
<attr name="snowflakesAlreadyFalling" format="boolean"/>
</declare-styleable>

</resources>

0 comments on commit a98bc1a

Please sign in to comment.