diff options
author | Allan Wang <me@allanwang.ca> | 2018-09-07 14:42:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-07 14:42:37 -0400 |
commit | 718a51ed00a0a5c3dc7a655e617308e82da65d1a (patch) | |
tree | 970783021ea2e21135a63fa888240f8dd3e8d543 /core/src/main/kotlin | |
parent | 6af0c6f7671898d0756c2e63dd17e830a2389885 (diff) | |
download | kau-718a51ed00a0a5c3dc7a655e617308e82da65d1a.tar.gz kau-718a51ed00a0a5c3dc7a655e617308e82da65d1a.tar.bz2 kau-718a51ed00a0a5c3dc7a655e617308e82da65d1a.zip |
Fix up cutoutview setup (#160)
* Fix up cutoutview setup
* Update gradle plugin versions
* Update kotlin gradle version
* Update canvas dimensions
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt | 26 |
2 files changed, 18 insertions, 10 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt index 62a16d9..3d86419 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt @@ -36,7 +36,7 @@ class RippleCanvas @JvmOverloads constructor( */ override fun onDraw(canvas: Canvas) { paint.color = baseColor - canvas.drawRect(0f, 0f, canvas.width.toFloat(), canvas.height.toFloat(), paint) + canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), paint) val itr = ripples.iterator() while (itr.hasNext()) { val r = itr.next() diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt index 9a70ae7..46e29b2 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt @@ -25,28 +25,36 @@ import java.text.DecimalFormat @DslMarker annotation class KauUtils -@KauUtils inline val Float.dpToPx: Float +@KauUtils +inline val Float.dpToPx: Float get() = this * Resources.getSystem().displayMetrics.density -@KauUtils inline val Int.dpToPx: Int +@KauUtils +inline val Int.dpToPx: Int get() = toFloat().dpToPx.toInt() -@KauUtils inline val Float.pxToDp: Float +@KauUtils +inline val Float.pxToDp: Float get() = this / Resources.getSystem().displayMetrics.density -@KauUtils inline val Int.pxToDp: Int +@KauUtils +inline val Int.pxToDp: Int get() = toFloat().pxToDp.toInt() -@KauUtils inline val Float.dpToSp: Float +@KauUtils +inline val Float.dpToSp: Float get() = this * Resources.getSystem().displayMetrics.scaledDensity -@KauUtils inline val Int.dpToSp: Int +@KauUtils +inline val Int.dpToSp: Int get() = toFloat().dpToSp.toInt() -@KauUtils inline val Float.spToDp: Float +@KauUtils +inline val Float.spToDp: Float get() = this / Resources.getSystem().displayMetrics.scaledDensity -@KauUtils inline val Int.spToDp: Int +@KauUtils +inline val Int.spToDp: Int get() = toFloat().spToDp.toInt() /** @@ -87,7 +95,7 @@ fun Drawable.toBitmap(scaling: Float = 1f, config: Bitmap.Config = Bitmap.Config else Bitmap.createBitmap((intrinsicWidth * scaling).toInt(), (intrinsicHeight * scaling).toInt(), config) val canvas = Canvas(bitmap) - setBounds(0, 0, canvas.width, canvas.height) + setBounds(0, 0, bitmap.width, bitmap.height) draw(canvas) return bitmap } |