aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-15 19:25:17 -0700
committerAllan Wang <me@allanwang.ca>2017-06-15 19:25:17 -0700
commitc8f76b5aa406f84f49789a50871c68a1a95a232d (patch)
tree7a47029f13dd023b2947eb294c8c9f7c7dbd3fe0 /app/src/main/kotlin/com/pitchedapps/frost/views
parent0d1f0e215b1890f2f5d45373b2746b7ef91da494 (diff)
downloadfrost-c8f76b5aa406f84f49789a50871c68a1a95a232d.tar.gz
frost-c8f76b5aa406f84f49789a50871c68a1a95a232d.tar.bz2
frost-c8f76b5aa406f84f49789a50871c68a1a95a232d.zip
Only animate webview when explicitly asked
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/AnimUtils.kt119
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/ViewUtils.kt39
3 files changed, 1 insertions, 158 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
index 8cb189e7..244c1388 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
@@ -6,6 +6,7 @@ import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.ImageView
import ca.allanwang.kau.utils.bindView
+import ca.allanwang.kau.utils.fadeIn
import ca.allanwang.kau.utils.toDrawable
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/AnimUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/AnimUtils.kt
deleted file mode 100644
index 3d212cc0..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/AnimUtils.kt
+++ /dev/null
@@ -1,119 +0,0 @@
-package com.pitchedapps.frost.views
-
-import android.animation.Animator
-import android.animation.AnimatorListenerAdapter
-import android.support.annotation.StringRes
-import android.view.View
-import android.view.ViewAnimationUtils
-import android.view.animation.Animation
-import android.view.animation.AnimationUtils
-import android.view.animation.DecelerateInterpolator
-import android.widget.TextView
-
-
-/**
- * Created by Allan Wang on 2017-06-01.
- */
-
-fun View.rootCircularReveal(x: Int = 0, y: Int = 0, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
- this.addOnLayoutChangeListener(object : View.OnLayoutChangeListener {
- override fun onLayoutChange(v: View, left: Int, top: Int, right: Int, bottom: Int, oldLeft: Int, oldTop: Int,
- oldRight: Int, oldBottom: Int) {
- v.removeOnLayoutChangeListener(this)
- var x2 = x
- var y2 = y
- if (x2 > right) x2 = 0
- if (y2 > bottom) y2 = 0
- val radius = Math.hypot(Math.max(x2, right - x2).toDouble(), Math.max(y2, bottom - y2).toDouble()).toInt()
- val reveal = ViewAnimationUtils.createCircularReveal(v, x2, y2, 0f, radius.toFloat())
- reveal.interpolator = DecelerateInterpolator(1f)
- reveal.duration = duration
- reveal.addListener(object : AnimatorListenerAdapter() {
- override fun onAnimationStart(animation: Animator?) {
- visibility = View.VISIBLE
- onStart?.invoke()
- }
-
- override fun onAnimationEnd(animation: Animator?) = onFinish?.invoke() ?: Unit
- override fun onAnimationCancel(animation: Animator?) = onFinish?.invoke() ?: Unit
- })
- reveal.start()
- }
- })
-}
-
-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) {
- visibility = View.VISIBLE
- return
- }
- var r = radius
- if (r < 0.0f) {
- r = Math.max(Math.hypot(x.toDouble(), y.toDouble()), Math.hypot((width - x.toDouble()), (height - y.toDouble()))).toFloat()
- }
- val anim = ViewAnimationUtils.createCircularReveal(this, x, y, 0f, r).setDuration(duration)
- anim.startDelay = offset
- anim.addListener(object : AnimatorListenerAdapter() {
- override fun onAnimationStart(animation: Animator?) {
- visibility = View.VISIBLE
- onStart?.invoke()
- }
-
- override fun onAnimationEnd(animation: Animator?) = onFinish?.invoke() ?: Unit
- override fun onAnimationCancel(animation: Animator?) = onFinish?.invoke() ?: Unit
- })
- anim.start()
-}
-
-fun View.fadeIn(offset: Long = 0L, duration: Long = 200L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
- if (!isAttachedToWindow) {
- visibility = View.VISIBLE
- return
- }
- if (isAttachedToWindow) {
- val anim = AnimationUtils.loadAnimation(context, android.R.anim.fade_in)
- anim.startOffset = offset
- anim.duration = duration
- anim.setAnimationListener(object : Animation.AnimationListener {
- override fun onAnimationRepeat(animation: Animation?) {}
- override fun onAnimationEnd(animation: Animation?) = onFinish?.invoke() ?: Unit
- override fun onAnimationStart(animation: Animation?) {
- visibility = View.VISIBLE
- onStart?.invoke()
- }
- })
- startAnimation(anim)
- }
-}
-
-fun View.fadeOut(offset: Long = 0L, duration: Long = 200L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) {
- if (!isAttachedToWindow) {
- visibility = View.INVISIBLE
- return
- }
- val anim = AnimationUtils.loadAnimation(context, android.R.anim.fade_out)
- anim.startOffset = offset
- anim.duration = duration
- anim.setAnimationListener(object : Animation.AnimationListener {
- override fun onAnimationRepeat(animation: Animation?) {}
- override fun onAnimationEnd(animation: Animation?) {
- visibility = View.INVISIBLE
- onFinish?.invoke()
- }
-
- override fun onAnimationStart(animation: Animation?) {
- onStart?.invoke()
- }
- })
- startAnimation(anim)
-}
-
-fun TextView.setTextWithFade(text: String, duration: Long = 200, onFinish: (() -> Unit)? = null) {
- fadeOut(duration = duration, onFinish = {
- setText(text)
- fadeIn(duration = duration, onFinish = onFinish)
- })
-}
-
-fun TextView.setTextWithFade(@StringRes textId: Int, duration: Long = 200, onFinish: (() -> Unit)? = null) = setTextWithFade(context.getString(textId), duration, onFinish)
-
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/ViewUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/ViewUtils.kt
deleted file mode 100644
index 8dc3f01f..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/ViewUtils.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.pitchedapps.frost.views
-
-import android.content.res.ColorStateList
-import android.support.annotation.ColorInt
-import android.support.annotation.ColorRes
-import android.support.annotation.StringRes
-import android.support.design.widget.Snackbar
-import android.support.v4.content.ContextCompat
-import android.view.View
-import android.view.ViewGroup
-import android.widget.ProgressBar
-
-
-/**
- * Created by Allan Wang on 2017-05-31.
- */
-fun View.matchParent() {
- with(layoutParams) {
- height = ViewGroup.LayoutParams.MATCH_PARENT
- width = ViewGroup.LayoutParams.MATCH_PARENT
- }
-}
-
-fun ProgressBar.tintRes(@ColorRes id: Int) = tint(ContextCompat.getColor(context, id))
-
-fun ProgressBar.tint(@ColorInt color: Int) {
- val sl = ColorStateList.valueOf(color)
- progressTintList = sl
- secondaryProgressTintList = sl
- indeterminateTintList = sl
-}
-
-fun View.snackbar(text: String, duration: Int = Snackbar.LENGTH_LONG) {
- Snackbar.make(this, text, duration).show()
-}
-
-fun View.snackbar(@StringRes textId: Int, duration: Int = Snackbar.LENGTH_LONG) {
- Snackbar.make(this, textId, duration).show()
-} \ No newline at end of file