aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin/ca
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-12 20:01:34 -0700
committerAllan Wang <me@allanwang.ca>2017-06-12 20:01:34 -0700
commit1805793c7cea8a3c56a8111e0a80d7ac5da95f63 (patch)
tree204a801f948e6f2e22b16ee5414da4b99c96a4bc /library/src/main/kotlin/ca
parent37a2059fa15f23093fc38bca236f517ef96b030d (diff)
downloadkau-1805793c7cea8a3c56a8111e0a80d7ac5da95f63.tar.gz
kau-1805793c7cea8a3c56a8111e0a80d7ac5da95f63.tar.bz2
kau-1805793c7cea8a3c56a8111e0a80d7ac5da95f63.zip
Add sliding activities
Diffstat (limited to 'library/src/main/kotlin/ca')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt22
1 files changed, 22 insertions, 0 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
index e2c1eb8..87bc547 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -9,6 +9,7 @@ import android.net.ConnectivityManager
import android.os.Bundle
import android.os.Handler
import android.support.annotation.*
+import android.support.v4.app.ActivityOptionsCompat
import android.support.v4.content.ContextCompat
import android.util.TypedValue
import android.widget.Toast
@@ -39,6 +40,27 @@ fun Context.startActivity(clazz: Class<out Activity>, clearStack: Boolean = fals
if (this is Activity && clearStack) finish()
}
+/**
+ * Bring in activity from the right
+ */
+fun Context.startActivitySlideIn(clazz: Class<out Activity>, clearStack: Boolean = false, intentBuilder: Intent.() -> Unit = {}, bundleBuilder: Bundle.() -> Unit = {}) {
+ val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.kau_slide_in_right, R.anim.kau_fade_out).toBundle()
+ bundle.bundleBuilder()
+ startActivity(clazz, clearStack, intentBuilder, bundle)
+}
+
+/**
+ * Bring in activity from behind while pushing the current activity to the right
+ * This replicates the exit animation of a sliding activity, but is a forward creation
+ * For the animation to work, the previous activity should not be in the stack (otherwise you wouldn't need this in the first place)
+ * Consequently, the stack will be cleared by default
+ */
+fun Context.startActivitySlideOut(clazz: Class<out Activity>, clearStack: Boolean = true, intentBuilder: Intent.() -> Unit = {}, bundleBuilder: Bundle.() -> Unit = {}) {
+ val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.kau_fade_in, R.anim.kau_slide_out_right_top).toBundle()
+ bundle.bundleBuilder()
+ startActivity(clazz, clearStack, intentBuilder, bundle)
+}
+
var Activity.navigationBarColor: Int
get() = if (buildIsLollipopAndUp) window.navigationBarColor else Color.BLACK
set(value) {