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 --- .travis.yml | 2 +- .../main/groovy/ca/allanwang/kau/Versions.groovy | 16 ++-- .../kotlin/ca/allanwang/kau/ui/views/CutoutView.kt | 40 +++++---- core-ui/src/main/res-public/values/public.xml | 2 +- .../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 +++++++++++----------- docs/Changelog.md | 1 + mediapicker/src/main/res-public/values/public.xml | 4 +- 9 files changed, 105 insertions(+), 86 deletions(-) diff --git a/.travis.yml b/.travis.yml index a5086d4..22743c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ cache: - $HOME/.gradle/wrapper/ - $HOME/.android/build-cache before_install: -- yes | sdkmanager "platforms;android-27" +- yes | sdkmanager "platforms;android-28" - openssl aes-256-cbc -K $encrypted_12e8842891a3_key -iv $encrypted_12e8842891a3_iv -in files/kau.tar.enc -out kau.tar -d - tar xvf kau.tar \ No newline at end of file diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy b/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy index 4b7149e..936e22b 100644 --- a/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy +++ b/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy @@ -3,16 +3,16 @@ package ca.allanwang.kau class Versions { static def coreMinSdk = 19 static def minSdk = 21 - static def targetSdk = 27 + static def targetSdk = 28 // https://developer.android.com/studio/releases/build-tools - static def buildTools = '27.0.3' + static def buildTools = '28.0.2' // https://developer.android.com/topic/libraries/support-library/revisions static def supportLibs = '27.1.1' // https://kotlinlang.org/docs/reference/using-gradle.html - static def kotlin = '1.2.41' + static def kotlin = '1.2.61' // https://github.com/mikepenz/AboutLibraries/releases static def aboutLibraries = '6.0.8' @@ -45,11 +45,11 @@ class Versions { static def junit = '4.12' static def testRunner = '1.0.1' - static def gradlePlugin = '3.1.2' - static def mavenPlugin = '2.0' - static def playPublishPlugin = '1.2.0' + static def gradlePlugin = '3.2.0-rc02' + static def mavenPlugin = '2.1' + static def playPublishPlugin = '1.2.2' // https://github.com/KeepSafe/dexcount-gradle-plugin/releases - static def dexCountPlugin = '0.8.2' - static def gitVersionPlugin = '0.4.3' + static def dexCountPlugin = '0.8.3' + static def gitVersionPlugin = '0.4.4' } \ No newline at end of file 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 @@ - + 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 diff --git a/docs/Changelog.md b/docs/Changelog.md index aeb119a..a93b4c8 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -5,6 +5,7 @@ * Fix new lint issues (see Migration for resource related methods) * :adapter: Add more IAdapter functions to help retrieve selections * :core: Add deprecation warning to bindView for fragment based extensions; use bindViewResettable instead +* :kpref-activity: Fix seekbar increment ## v3.7.1 * Update appcompat to 27.1.0 diff --git a/mediapicker/src/main/res-public/values/public.xml b/mediapicker/src/main/res-public/values/public.xml index 3c6f0fa..ac608bb 100644 --- a/mediapicker/src/main/res-public/values/public.xml +++ b/mediapicker/src/main/res-public/values/public.xml @@ -1,7 +1,7 @@ - - + + \ No newline at end of file -- cgit v1.2.3