aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-11-08 22:15:03 -0500
committerGitHub <noreply@github.com>2017-11-08 22:15:03 -0500
commit3b1cbd2f2cf211b804784bef33de85b8a889677e (patch)
treee11fa8cf0081c117ee3c60b419dd02473ef6dd8d /core/src/main/kotlin/ca
parenta0587e8877f35ac2dc149a64e06665dff424b469 (diff)
downloadkau-3b1cbd2f2cf211b804784bef33de85b8a889677e.tar.gz
kau-3b1cbd2f2cf211b804784bef33de85b8a889677e.tar.bz2
kau-3b1cbd2f2cf211b804784bef33de85b8a889677e.zip
Translations Italian (#98)
* Add translations * Update dependencies * Show lint output * Fix type inference * Add annotation
Diffstat (limited to 'core/src/main/kotlin/ca')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt5
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt2
2 files changed, 4 insertions, 3 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
index 8537185..16d1d01 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
@@ -1,5 +1,6 @@
package ca.allanwang.kau.utils
+import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
@@ -9,7 +10,6 @@ import android.os.Build
import android.support.annotation.ColorInt
import android.support.annotation.FloatRange
import android.support.annotation.IntRange
-import android.support.v4.content.ContextCompat
import android.support.v4.graphics.drawable.DrawableCompat
import android.support.v7.widget.AppCompatEditText
import android.support.v7.widget.Toolbar
@@ -225,6 +225,7 @@ fun Context.textColorStateList(@ColorInt color: Int): ColorStateList {
return ColorStateList(states, colors)
}
+@SuppressLint("RestrictedApi")
fun EditText.tint(@ColorInt color: Int) {
val editTextColorStateList = context.textColorStateList(color)
if (this is AppCompatEditText) {
@@ -247,7 +248,7 @@ fun EditText.tintCursor(@ColorInt color: Int) {
val fCursorDrawable = clazz.getDeclaredField("mCursorDrawable")
fCursorDrawable.isAccessible = true
val drawables: Array<Drawable> = Array(2, {
- val drawable = ContextCompat.getDrawable(context, mCursorDrawableRes)
+ val drawable = context.drawable(mCursorDrawableRes)
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN)
drawable
})
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
index 0664dc6..545a3f0 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -121,7 +121,7 @@ inline fun Context.color(@ColorRes id: Int): Int = ContextCompat.getColor(this,
inline fun Context.integer(@IntegerRes id: Int): Int = resources.getInteger(id)
inline fun Context.dimen(@DimenRes id: Int): Float = resources.getDimension(id)
inline fun Context.dimenPixelSize(@DimenRes id: Int): Int = resources.getDimensionPixelSize(id)
-inline fun Context.drawable(@DrawableRes id: Int): Drawable = ContextCompat.getDrawable(this, id)
+inline fun Context.drawable(@DrawableRes id: Int): Drawable = ContextCompat.getDrawable(this, id) ?: throw KauException("Drawable with id $id not found")
inline fun Context.drawable(@DrawableRes id: Int, fallback: Drawable?): Drawable? = if (id > 0) drawable(id) else fallback
inline fun Context.interpolator(@InterpolatorRes id: Int) = AnimationUtils.loadInterpolator(this, id)
inline fun Context.animation(@AnimRes id: Int) = AnimationUtils.loadAnimation(this, id)