aboutsummaryrefslogtreecommitdiff
path: root/core-ui/src
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-09-07 14:42:37 -0400
committerGitHub <noreply@github.com>2018-09-07 14:42:37 -0400
commit718a51ed00a0a5c3dc7a655e617308e82da65d1a (patch)
tree970783021ea2e21135a63fa888240f8dd3e8d543 /core-ui/src
parent6af0c6f7671898d0756c2e63dd17e830a2389885 (diff)
downloadkau-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-ui/src')
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt40
-rw-r--r--core-ui/src/main/res-public/values/public.xml2
2 files changed, 26 insertions, 16 deletions
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt
index fc03563..eeaac6e 100644
--- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt
@@ -39,29 +39,39 @@ class CutoutView @JvmOverloads constructor(
companion object {
const val PHI = 1.6182f
- const val TYPE_TEXT = 100
- const val TYPE_DRAWABLE = 101
+ const val TYPE_EMPTY = 100
+ const val TYPE_TEXT = 101
+ const val TYPE_DRAWABLE = 102
}
- private val paint: TextPaint = TextPaint(Paint.ANTI_ALIAS_FLAG)
+ private val paint: TextPaint = TextPaint().apply {
+ isAntiAlias = true
+ xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR)
+ }
private var bitmapScaling: Float = 1f
private var cutout: Bitmap? = null
var foregroundColor = Color.MAGENTA
var text: String? = "Text"
set(value) {
field = value
- if (value != null) cutoutType = TYPE_TEXT
- else if (drawable != null) cutoutType = TYPE_DRAWABLE
+ cutoutType = when {
+ value != null -> TYPE_TEXT
+ drawable != null -> TYPE_DRAWABLE
+ else -> TYPE_EMPTY
+ }
}
- var cutoutType: Int = TYPE_TEXT
+ var cutoutType: Int = TYPE_EMPTY
private var textSize: Float = 0f
private var cutoutY: Float = 0f
private var cutoutX: Float = 0f
var drawable: Drawable? = null
set(value) {
field = value
- if (value != null) cutoutType = TYPE_DRAWABLE
- else if (text != null) cutoutType = TYPE_TEXT
+ cutoutType = when {
+ drawable != null -> TYPE_DRAWABLE
+ value != null -> TYPE_TEXT
+ else -> TYPE_EMPTY
+ }
}
private var heightPercentage: Float = 0f
private var minHeight: Float = 0f
@@ -159,22 +169,22 @@ class CutoutView @JvmOverloads constructor(
if (cutout?.isRecycled == false)
cutout?.recycle()
if (width == 0 || height == 0) return
- cutout = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
- cutout!!.setHasAlpha(true)
+ cutout = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888).apply {
+ setHasAlpha(true)
+ }
val cutoutCanvas = Canvas(cutout!!)
cutoutCanvas.drawColor(foregroundColor)
- paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR)
when (cutoutType) {
TYPE_TEXT -> {
- // this is the magic – Clear mode punches out the bitmap
- paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR)
- cutoutCanvas.drawText(text, cutoutX, cutoutY, paint)
+ cutoutCanvas.drawText(text!!, cutoutX, cutoutY, paint)
}
TYPE_DRAWABLE -> {
cutoutCanvas.drawBitmap(drawable!!.toBitmap(bitmapScaling, Bitmap.Config.ALPHA_8), cutoutX, cutoutY, paint)
}
-
+ TYPE_EMPTY -> {
+ // do nothing
+ }
}
}
diff --git a/core-ui/src/main/res-public/values/public.xml b/core-ui/src/main/res-public/values/public.xml
index dcaa583..f46b3eb 100644
--- a/core-ui/src/main/res-public/values/public.xml
+++ b/core-ui/src/main/res-public/values/public.xml
@@ -1,8 +1,8 @@
<resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'>
<!-- AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task -->
<public name='kau_recycler_detached_background' type='layout' />
- <public name='kau_recycler_textslider' type='layout' />
<public name='kau_elastic_recycler_activity' type='layout' />
+ <public name='kau_recycler_textslider' type='layout' />
<public name='Kau.Translucent' type='style' />
<public name='Kau.Translucent.NoAnimation' type='style' />
<public name='Kau.Translucent.SlideBottom' type='style' />