aboutsummaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-21 15:22:07 -0700
committerAllan Wang <me@allanwang.ca>2017-06-21 15:22:07 -0700
commita8fb90b75c9827fa0f3af37044fc48272c15a670 (patch)
tree9a20d5e22f0beff0feddbf96e6b5afec938e525b /library
parent957b3be0bd1eccc761ba8ca98255771b11198a69 (diff)
downloadkau-a8fb90b75c9827fa0f3af37044fc48272c15a670.tar.gz
kau-a8fb90b75c9827fa0f3af37044fc48272c15a670.tar.bz2
kau-a8fb90b75c9827fa0f3af37044fc48272c15a670.zip
Add set menu icons
Diffstat (limited to 'library')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt56
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt28
2 files changed, 56 insertions, 28 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt
new file mode 100644
index 0000000..c74a3ec
--- /dev/null
+++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt
@@ -0,0 +1,56 @@
+package ca.allanwang.kau.utils
+
+import android.app.Activity
+import android.content.Intent
+import android.graphics.Color
+import android.support.annotation.ColorInt
+import android.view.Menu
+import ca.allanwang.kau.R
+import com.mikepenz.iconics.typeface.IIcon
+
+/**
+ * Created by Allan Wang on 2017-06-21.
+ */
+
+/**
+ * Restarts an activity from itself without animations
+ * Keeps its existing extra bundles and has a builder to accept other parameters
+ */
+fun Activity.restart(builder: Intent.() -> Unit = {}) {
+ val i = Intent(this, this::class.java)
+ i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
+ i.putExtras(intent.extras)
+ i.builder()
+ startActivity(i)
+ overridePendingTransition(0, 0) //No transitions
+ finish()
+ overridePendingTransition(0, 0)
+}
+
+fun Activity.finishSlideOut() {
+ finish()
+ overridePendingTransition(R.anim.kau_fade_in, R.anim.kau_slide_out_right_top)
+}
+
+var Activity.navigationBarColor: Int
+ get() = if (buildIsLollipopAndUp) window.navigationBarColor else Color.BLACK
+ set(value) {
+ if (buildIsLollipopAndUp) window.navigationBarColor = value
+ }
+
+var Activity.statusBarColor: Int
+ get() = if (buildIsLollipopAndUp) window.statusBarColor else Color.BLACK
+ set(value) {
+ if (buildIsLollipopAndUp) window.statusBarColor = value
+ }
+
+/**
+ * Themes the base menu icons and adds iicons programmatically based on ids
+ *
+ * Call in [Activity.onCreateOptionsMenu]
+ */
+fun Activity.setMenuIcons(menu: Menu, @ColorInt color: Int = Color.WHITE, vararg iicons: Pair<Int, IIcon>) {
+ iicons.forEach { (id, iicon) ->
+ menu.findItem(id).icon = iicon.toDrawable(this, sizeDp = 20, color = color)
+ }
+} \ No newline at end of file
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 b293dc1..9508173 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -22,17 +22,6 @@ import java.util.*
/**
* Created by Allan Wang on 2017-06-03.
*/
-fun Activity.restart(action: Intent.() -> Unit = {}) {
- val i = Intent(this, this::class.java)
- i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
- i.putExtras(intent.extras)
- i.action()
- startActivity(i)
- overridePendingTransition(0, 0) //No transitions
- finish()
- overridePendingTransition(0, 0)
-}
-
fun Context.startActivity(clazz: Class<out Activity>, clearStack: Boolean = false, intentBuilder: Intent.() -> Unit = {}, bundle: Bundle? = null) {
val intent = (Intent(this, clazz))
if (clearStack) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
@@ -62,23 +51,6 @@ fun Context.startActivitySlideOut(clazz: Class<out Activity>, clearStack: Boolea
startActivity(clazz, clearStack, intentBuilder, bundle)
}
-fun Activity.finishSlideOut() {
- finish()
- overridePendingTransition(R.anim.kau_fade_in, R.anim.kau_slide_out_right_top)
-}
-
-var Activity.navigationBarColor: Int
- get() = if (buildIsLollipopAndUp) window.navigationBarColor else Color.BLACK
- set(value) {
- if (buildIsLollipopAndUp) window.navigationBarColor = value
- }
-
-var Activity.statusBarColor: Int
- get() = if (buildIsLollipopAndUp) window.statusBarColor else Color.BLACK
- set(value) {
- if (buildIsLollipopAndUp) window.statusBarColor = value
- }
-
//Toast helpers
fun Context.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG) = toast(this.string(id), duration)