diff options
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 } |