aboutsummaryrefslogtreecommitdiff
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
parent37a2059fa15f23093fc38bca236f517ef96b030d (diff)
downloadkau-1805793c7cea8a3c56a8111e0a80d7ac5da95f63.tar.gz
kau-1805793c7cea8a3c56a8111e0a80d7ac5da95f63.tar.bz2
kau-1805793c7cea8a3c56a8111e0a80d7ac5da95f63.zip
Add sliding activities
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt22
-rw-r--r--library/src/main/res/anim/kau_fade_in.xml5
-rw-r--r--library/src/main/res/anim/kau_fade_out.xml5
-rw-r--r--library/src/main/res/anim/kau_slide_out_right_top.xml8
-rw-r--r--sample/src/main/AndroidManifest.xml3
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt22
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt11
-rw-r--r--sample/src/main/res/layout/sample.xml13
-rw-r--r--sample/src/main/res/menu/menu_main.xml20
-rw-r--r--sample/src/main/res/values/styles.xml1
10 files changed, 81 insertions, 29 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) {
diff --git a/library/src/main/res/anim/kau_fade_in.xml b/library/src/main/res/anim/kau_fade_in.xml
new file mode 100644
index 0000000..03312a2
--- /dev/null
+++ b/library/src/main/res/anim/kau_fade_in.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<alpha xmlns:android="http://schemas.android.com/apk/res/android"
+ android:duration="@android:integer/config_shortAnimTime"
+ android:fromAlpha="0.0"
+ android:toAlpha="1.0" /> \ No newline at end of file
diff --git a/library/src/main/res/anim/kau_fade_out.xml b/library/src/main/res/anim/kau_fade_out.xml
new file mode 100644
index 0000000..322befc
--- /dev/null
+++ b/library/src/main/res/anim/kau_fade_out.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<alpha xmlns:android="http://schemas.android.com/apk/res/android"
+ android:duration="@android:integer/config_shortAnimTime"
+ android:fromAlpha="1.0"
+ android:toAlpha="0.0" /> \ No newline at end of file
diff --git a/library/src/main/res/anim/kau_slide_out_right_top.xml b/library/src/main/res/anim/kau_slide_out_right_top.xml
new file mode 100644
index 0000000..5b63474
--- /dev/null
+++ b/library/src/main/res/anim/kau_slide_out_right_top.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+ android:zAdjustment="top">
+ <translate
+ android:duration="@android:integer/config_shortAnimTime"
+ android:fromXDelta="0"
+ android:toXDelta="100%p" />
+</set> \ No newline at end of file
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index 1934e71..03ca52c 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -19,6 +19,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity
+ android:name=".AnimActivity"
+ android:theme="@style/Theme.AppCompat" />
</application>
</manifest> \ No newline at end of file
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt
new file mode 100644
index 0000000..10f2065
--- /dev/null
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt
@@ -0,0 +1,22 @@
+package ca.allanwang.kau.sample
+
+import android.os.Bundle
+import android.support.v7.app.AppCompatActivity
+import ca.allanwang.kau.utils.startActivitySlideOut
+
+/**
+ * Created by Allan Wang on 2017-06-12.
+ *
+ * Empty Activity for animations
+ */
+class AnimActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.sample)
+ }
+
+ override fun onBackPressed() {
+ startActivitySlideOut(MainActivity::class.java)
+ }
+} \ No newline at end of file
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
index ac80fc6..2b11ced 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
@@ -7,7 +7,7 @@ import ca.allanwang.kau.kpref.KPrefActivity
import ca.allanwang.kau.kpref.KPrefAdapterBuilder
import ca.allanwang.kau.utils.darken
import ca.allanwang.kau.utils.navigationBarColor
-import ca.allanwang.kau.utils.showChangelog
+import ca.allanwang.kau.utils.startActivitySlideIn
import ca.allanwang.kau.views.RippleCanvas
import com.mikepenz.google_material_typeface_library.GoogleMaterial
@@ -65,14 +65,7 @@ class MainActivity : KPrefActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_settings -> {
-
- }
- R.id.action_changelog -> showChangelog(R.xml.kau_changelog)
- R.id.action_call -> {
- }
- R.id.action_db -> {
- }
- R.id.action_restart -> {
+ startActivitySlideIn(AnimActivity::class.java, clearStack = true)
}
else -> return super.onOptionsItemSelected(item)
}
diff --git a/sample/src/main/res/layout/sample.xml b/sample/src/main/res/layout/sample.xml
new file mode 100644
index 0000000..c237fda
--- /dev/null
+++ b/sample/src/main/res/layout/sample.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_gravity="center"
+ android:orientation="vertical">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="This is a sample" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/sample/src/main/res/menu/menu_main.xml b/sample/src/main/res/menu/menu_main.xml
index 5562ea4..3725b18 100644
--- a/sample/src/main/res/menu/menu_main.xml
+++ b/sample/src/main/res/menu/menu_main.xml
@@ -7,25 +7,5 @@
android:orderInCategory="100"
android:title="Settings"
app:showAsAction="never" />
- <item
- android:id="@+id/action_changelog"
- android:orderInCategory="200"
- android:title="@string/kau_changelog"
- app:showAsAction="never" />
- <item
- android:id="@+id/action_restart"
- android:orderInCategory="220"
- android:title="Restart"
- app:showAsAction="never" />
- <item
- android:id="@+id/action_call"
- android:orderInCategory="300"
- android:title="Call"
- app:showAsAction="never" />
- <item
- android:id="@+id/action_db"
- android:orderInCategory="400"
- android:title="DB"
- app:showAsAction="never" />
</menu>
diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml
index 7867278..ac2f9c8 100644
--- a/sample/src/main/res/values/styles.xml
+++ b/sample/src/main/res/values/styles.xml
@@ -6,6 +6,7 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
+ <item name="android:colorBackground">#303030</item>
<item name="android:windowShowWallpaper">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>