aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca/allanwang/kau/utils
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau/utils')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt21
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/FileUtils.kt1
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt3
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt9
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt12
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt1
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt60
7 files changed, 70 insertions, 37 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt
index 5cef0ac..a287cf2 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt
@@ -18,7 +18,8 @@ import android.widget.TextView
*/
@SuppressLint("NewApi")
-@KauUtils fun View.circularReveal(x: Int = 0, y: Int = 0, offset: Long = 0L, radius: Float = -1.0f, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
+@KauUtils
+fun View.circularReveal(x: Int = 0, y: Int = 0, offset: Long = 0L, radius: Float = -1.0f, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
if (!isAttachedToWindow) {
onStart?.invoke()
visible()
@@ -45,7 +46,8 @@ import android.widget.TextView
}
@SuppressLint("NewApi")
-@KauUtils fun View.circularHide(x: Int = 0, y: Int = 0, offset: Long = 0L, radius: Float = -1.0f, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
+@KauUtils
+fun View.circularHide(x: Int = 0, y: Int = 0, offset: Long = 0L, radius: Float = -1.0f, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
if (!isAttachedToWindow) {
onStart?.invoke()
invisible()
@@ -72,7 +74,8 @@ import android.widget.TextView
anim.start()
}
-@KauUtils fun View.fadeIn(offset: Long = 0L, duration: Long = 200L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
+@KauUtils
+fun View.fadeIn(offset: Long = 0L, duration: Long = 200L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
if (!isAttachedToWindow) {
onStart?.invoke()
visible()
@@ -93,7 +96,8 @@ import android.widget.TextView
startAnimation(anim)
}
-@KauUtils fun View.fadeOut(offset: Long = 0L, duration: Long = 200L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
+@KauUtils
+fun View.fadeOut(offset: Long = 0L, duration: Long = 200L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
if (!isAttachedToWindow) {
onStart?.invoke()
invisible()
@@ -117,13 +121,16 @@ import android.widget.TextView
startAnimation(anim)
}
-@KauUtils fun TextView.setTextWithFade(text: String, duration: Long = 200, onFinish: (() -> Unit)? = null) {
+@KauUtils
+fun TextView.setTextWithFade(text: String, duration: Long = 200, onFinish: (() -> Unit)? = null) {
fadeOut(duration = duration, onFinish = {
setText(text)
fadeIn(duration = duration, onFinish = onFinish)
})
}
-@KauUtils fun TextView.setTextWithFade(@StringRes textId: Int, duration: Long = 200, onFinish: (() -> Unit)? = null) = setTextWithFade(context.getString(textId), duration, onFinish)
+@KauUtils
+fun TextView.setTextWithFade(@StringRes textId: Int, duration: Long = 200, onFinish: (() -> Unit)? = null) = setTextWithFade(context.getString(textId), duration, onFinish)
-@KauUtils fun ViewPropertyAnimator.scaleXY(value: Float) = scaleX(value).scaleY(value) \ No newline at end of file
+@KauUtils
+fun ViewPropertyAnimator.scaleXY(value: Float) = scaleX(value).scaleY(value) \ No newline at end of file
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/FileUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/FileUtils.kt
index 65c28f7..b97f4aa 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/FileUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/FileUtils.kt
@@ -1,6 +1,5 @@
package ca.allanwang.kau.utils
-import android.os.Bundle
import java.io.File
import java.io.InputStream
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt
index 4c71945..a8c710e 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt
@@ -11,7 +11,8 @@ import com.mikepenz.iconics.typeface.IIcon
/**
* Created by Allan Wang on 2017-05-29.
*/
-@KauUtils fun IIcon.toDrawable(c: Context, sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {}): Drawable {
+@KauUtils
+fun IIcon.toDrawable(c: Context, sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {}): Drawable {
val state = ColorStateList.valueOf(color)
val icon = IconicsDrawable(c).icon(this).sizeDp(sizeDp).color(state)
icon.builder()
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt
index ebd7161..77750d3 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt
@@ -17,7 +17,8 @@ import android.provider.Settings
* @param packageName packageId
* @return true if installed with activity, false otherwise
*/
-@KauUtils fun Context.isAppInstalled(packageName: String): Boolean {
+@KauUtils
+fun Context.isAppInstalled(packageName: String): Boolean {
try {
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
return true
@@ -26,7 +27,8 @@ import android.provider.Settings
}
}
-@KauUtils fun Context.isAppEnabled(packageName: String): Boolean {
+@KauUtils
+fun Context.isAppEnabled(packageName: String): Boolean {
try {
return packageManager.getApplicationInfo(packageName, 0).enabled
} catch (e: Exception) {
@@ -34,7 +36,8 @@ import android.provider.Settings
}
}
-@KauUtils fun Context.showAppInfo(packageName: String) {
+@KauUtils
+fun Context.showAppInfo(packageName: String) {
try {
//Open the specific App Info page:
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt
index 1f4536b..ec206ee 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt
@@ -23,7 +23,8 @@ class TransitionEndListener(val onEnd: (transition: Transition) -> Unit) : Trans
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
-@KauUtils fun Transition.addEndListener(onEnd: (transition: Transition) -> Unit) {
+@KauUtils
+fun Transition.addEndListener(onEnd: (transition: Transition) -> Unit) {
addListener(TransitionEndListener(onEnd))
}
@@ -37,18 +38,21 @@ class SupportTransitionEndListener(val onEnd: (transition: SupportTransition) ->
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
-@KauUtils fun SupportTransition.addEndListener(onEnd: (transition: SupportTransition) -> Unit) {
+@KauUtils
+fun SupportTransition.addEndListener(onEnd: (transition: SupportTransition) -> Unit) {
addListener(SupportTransitionEndListener(onEnd))
}
-@KauUtils fun ViewGroup.transitionAuto(builder: AutoTransition.() -> Unit = {}) {
+@KauUtils
+fun ViewGroup.transitionAuto(builder: AutoTransition.() -> Unit = {}) {
if (!buildIsLollipopAndUp) return
val transition = AutoTransition()
transition.builder()
TransitionManager.beginDelayedTransition(this, transition)
}
-@KauUtils fun ViewGroup.transitionDelayed(@TransitionRes id: Int, builder: android.support.transition.Transition.() -> Unit = {}) {
+@KauUtils
+fun ViewGroup.transitionDelayed(@TransitionRes id: Int, builder: android.support.transition.Transition.() -> Unit = {}) {
if (!buildIsLollipopAndUp) return
val transition = TransitionInflater.from(context).inflateTransition(id)
transition.builder()
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 8b32894..9a70ae7 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt
@@ -6,7 +6,6 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
-import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.support.annotation.IntRange
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt
index f6a541b..1946dbc 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt
@@ -72,11 +72,13 @@ fun View.snackbar(text: String, duration: Int = Snackbar.LENGTH_LONG, builder: S
fun View.snackbar(@StringRes textId: Int, duration: Int = Snackbar.LENGTH_LONG, builder: Snackbar.() -> Unit = {})
= snackbar(context.string(textId), duration, builder)
-@KauUtils fun TextView.setTextIfValid(@StringRes id: Int) {
+@KauUtils
+fun TextView.setTextIfValid(@StringRes id: Int) {
if (id > 0) text = context.string(id)
}
-@KauUtils fun ImageView.setIcon(icon: IIcon?, sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {}) {
+@KauUtils
+fun ImageView.setIcon(icon: IIcon?, sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {}) {
if (icon == null) return
setImageDrawable(icon.toDrawable(context, sizeDp = sizeDp, color = color, builder = builder))
}
@@ -87,42 +89,50 @@ fun FloatingActionButton.showIf(show: Boolean) = if (show) show() else hide()
fun FloatingActionButton.hideIf(hide: Boolean) = if (hide) hide() else show()
-@KauUtils fun ViewGroup.inflate(layoutId: Int, attachToRoot: Boolean = false): View = LayoutInflater.from(context).inflate(layoutId, this, attachToRoot)
+@KauUtils
+fun ViewGroup.inflate(layoutId: Int, attachToRoot: Boolean = false): View = LayoutInflater.from(context).inflate(layoutId, this, attachToRoot)
/**
* Set left margin to a value in px
*/
-@KauUtils fun View.setMarginLeft(margin: Int) = setMargins(margin, KAU_LEFT)
+@KauUtils
+fun View.setMarginLeft(margin: Int) = setMargins(margin, KAU_LEFT)
/**
* Set top margin to a value in px
*/
-@KauUtils fun View.setMarginTop(margin: Int) = setMargins(margin, KAU_TOP)
+@KauUtils
+fun View.setMarginTop(margin: Int) = setMargins(margin, KAU_TOP)
/**
* Set right margin to a value in px
*/
-@KauUtils fun View.setMarginRight(margin: Int) = setMargins(margin, KAU_RIGHT)
+@KauUtils
+fun View.setMarginRight(margin: Int) = setMargins(margin, KAU_RIGHT)
/**
* Set bottom margin to a value in px
*/
-@KauUtils fun View.setMarginBottom(margin: Int) = setMargins(margin, KAU_BOTTOM)
+@KauUtils
+fun View.setMarginBottom(margin: Int) = setMargins(margin, KAU_BOTTOM)
/**
* Set left and right margins to a value in px
*/
-@KauUtils fun View.setMarginHorizontal(margin: Int) = setMargins(margin, KAU_HORIZONTAL)
+@KauUtils
+fun View.setMarginHorizontal(margin: Int) = setMargins(margin, KAU_HORIZONTAL)
/**
* Set top and bottom margins to a value in px
*/
-@KauUtils fun View.setMarginVertical(margin: Int) = setMargins(margin, KAU_VERTICAL)
+@KauUtils
+fun View.setMarginVertical(margin: Int) = setMargins(margin, KAU_VERTICAL)
/**
* Set all margins to a value in px
*/
-@KauUtils fun View.setMargin(margin: Int) = setMargins(margin, KAU_ALL)
+@KauUtils
+fun View.setMargin(margin: Int) = setMargins(margin, KAU_ALL)
/**
* Base margin setter
@@ -142,37 +152,44 @@ fun FloatingActionButton.hideIf(hide: Boolean) = if (hide) hide() else show()
/**
* Set left padding to a value in px
*/
-@KauUtils fun View.setPaddingLeft(padding: Int) = setPadding(padding, KAU_LEFT)
+@KauUtils
+fun View.setPaddingLeft(padding: Int) = setPadding(padding, KAU_LEFT)
/**
* Set top padding to a value in px
*/
-@KauUtils fun View.setPaddingTop(padding: Int) = setPadding(padding, KAU_TOP)
+@KauUtils
+fun View.setPaddingTop(padding: Int) = setPadding(padding, KAU_TOP)
/**
* Set right padding to a value in px
*/
-@KauUtils fun View.setPaddingRight(padding: Int) = setPadding(padding, KAU_RIGHT)
+@KauUtils
+fun View.setPaddingRight(padding: Int) = setPadding(padding, KAU_RIGHT)
/**
* Set bottom padding to a value in px
*/
-@KauUtils fun View.setPaddingBottom(padding: Int) = setPadding(padding, KAU_BOTTOM)
+@KauUtils
+fun View.setPaddingBottom(padding: Int) = setPadding(padding, KAU_BOTTOM)
/**
* Set left and right padding to a value in px
*/
-@KauUtils fun View.setPaddingHorizontal(padding: Int) = setPadding(padding, KAU_HORIZONTAL)
+@KauUtils
+fun View.setPaddingHorizontal(padding: Int) = setPadding(padding, KAU_HORIZONTAL)
/**
* Set top and bottom padding to a value in px
*/
-@KauUtils fun View.setPaddingVertical(padding: Int) = setPadding(padding, KAU_VERTICAL)
+@KauUtils
+fun View.setPaddingVertical(padding: Int) = setPadding(padding, KAU_VERTICAL)
/**
* Set all padding to a value in px
*/
-@KauUtils fun View.setPadding(padding: Int) = setPadding(padding, KAU_ALL)
+@KauUtils
+fun View.setPadding(padding: Int) = setPadding(padding, KAU_ALL)
/**
* Base padding setter
@@ -186,19 +203,22 @@ fun FloatingActionButton.hideIf(hide: Boolean) = if (hide) hide() else show()
)
}
-@KauUtils fun View.hideKeyboard() {
+@KauUtils
+fun View.hideKeyboard() {
clearFocus()
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(windowToken, 0)
}
-@KauUtils fun View.showKeyboard() {
+@KauUtils
+fun View.showKeyboard() {
requestFocus()
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
-@KauUtils fun View.setRippleBackground(@ColorInt foregroundColor: Int, @ColorInt backgroundColor: Int) {
+@KauUtils
+fun View.setRippleBackground(@ColorInt foregroundColor: Int, @ColorInt backgroundColor: Int) {
background = createSimpleRippleDrawable(foregroundColor, backgroundColor)
}