diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-12 16:15:00 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-12 16:15:00 -0700 |
commit | dcdf008c1e83af4ba0509736a389522a71797264 (patch) | |
tree | d22b7b9618fbec7cf61c230970587e592315ea9a /library | |
parent | a92a71a490f875bb30cef1db933d2a172bf8a653 (diff) | |
download | kau-dcdf008c1e83af4ba0509736a389522a71797264.tar.gz kau-dcdf008c1e83af4ba0509736a389522a71797264.tar.bz2 kau-dcdf008c1e83af4ba0509736a389522a71797264.zip |
Add start activity
Diffstat (limited to 'library')
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 8 | ||||
-rw-r--r-- | library/src/main/res/layout/kau_activity_kpref.xml | 5 |
2 files changed, 11 insertions, 2 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 5547fe1..a856ed2 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -30,6 +30,14 @@ fun Activity.restart(extras: ((Intent) -> Unit)? = null) { overridePendingTransition(0, 0) } +fun Context.startActivity(clazz: Class<out Activity>, clearStack: Boolean = false, intentBuilder: Intent.() -> Unit = {}) { + val intent = (Intent(this, clazz)) + if (clearStack) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK) + intent.intentBuilder() + startActivity(intent) + if (this is Activity && clearStack) finish() +} + var Activity.navigationBarColor: Int get() = if (buildIsLollipopAndUp) window.navigationBarColor else Color.BLACK set(value) { diff --git a/library/src/main/res/layout/kau_activity_kpref.xml b/library/src/main/res/layout/kau_activity_kpref.xml index 35f16cd..4135edc 100644 --- a/library/src/main/res/layout/kau_activity_kpref.xml +++ b/library/src/main/res/layout/kau_activity_kpref.xml @@ -8,16 +8,17 @@ android:id="@+id/kau_toolbar_ripple" android:layout_width="0dp" android:layout_height="0dp" - app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="@+id/kau_toolbar" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintBottom_toBottomOf="@+id/kau_toolbar" /> + app:layout_constraintTop_toTopOf="parent" /> <android.support.v7.widget.Toolbar android:id="@id/kau_toolbar" android:layout_width="0dp" android:layout_height="?attr/actionBarSize" android:layout_marginTop="@dimen/kau_status_bar_height" + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> |