From 718a51ed00a0a5c3dc7a655e617308e82da65d1a Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Fri, 7 Sep 2018 14:42:37 -0400 Subject: Fix up cutoutview setup (#160) * Fix up cutoutview setup * Update gradle plugin versions * Update kotlin gradle version * Update canvas dimensions --- .../ca/allanwang/kau/ui/views/RippleCanvas.kt | 2 +- .../main/kotlin/ca/allanwang/kau/utils/Utils.kt | 26 ++++-- core/src/main/res-public/values/public.xml | 98 +++++++++++----------- 3 files changed, 67 insertions(+), 59 deletions(-) (limited to 'core/src/main') 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 } diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml index f831c6d..ea8ed73 100644 --- a/core/src/main/res-public/values/public.xml +++ b/core/src/main/res-public/values/public.xml @@ -1,29 +1,48 @@ - - - - - - - - - - - - - - - + - + - + - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -79,7 +98,8 @@ - + + @@ -87,32 +107,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + \ No newline at end of file -- cgit v1.2.3