aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-19 17:08:15 -0700
committerAllan Wang <me@allanwang.ca>2017-06-19 17:08:15 -0700
commita3b5b647e2651c9768a4056852aff36074590e94 (patch)
tree4398fd2f27dfda32d26c21d71ed0af746061bdc6 /app/src/main/kotlin/com/pitchedapps/frost/views
parent382433780c3f4403723a78e409cb161c9fad5034 (diff)
downloadfrost-a3b5b647e2651c9768a4056852aff36074590e94.tar.gz
frost-a3b5b647e2651c9768a4056852aff36074590e94.tar.bz2
frost-a3b5b647e2651c9768a4056852aff36074590e94.zip
Created notification badges
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt55
1 files changed, 55 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt
new file mode 100644
index 00000000..bc932480
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt
@@ -0,0 +1,55 @@
+package com.pitchedapps.frost.views
+
+import android.content.Context
+import android.graphics.drawable.GradientDrawable
+import android.support.constraint.ConstraintLayout
+import android.util.AttributeSet
+import android.widget.ImageView
+import android.widget.TextView
+import ca.allanwang.kau.utils.*
+import com.mikepenz.iconics.typeface.IIcon
+import com.pitchedapps.frost.R
+import com.pitchedapps.frost.utils.Prefs
+
+
+/**
+ * Created by Allan Wang on 2017-06-19.
+ */
+class BadgedIcon @JvmOverloads constructor(
+ context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+) : ConstraintLayout(context, attrs, defStyleAttr) {
+
+ val badgeTextView: TextView by bindView(R.id.badge_text)
+ val badgeImage: ImageView by bindView(R.id.badge_image)
+
+ init {
+ inflate(context, R.layout.view_badged_icon, this)
+ val badgeColor = Prefs.headerColor.withAlpha(255).colorToForeground(0.1f)
+ val badgeBackground = GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf(badgeColor, badgeColor))
+ badgeBackground.cornerRadius = 13.dpToPx.toFloat()
+ badgeTextView.background = badgeBackground
+ badgeTextView.setTextColor(Prefs.iconColor)
+ }
+
+
+ var iicon: IIcon? = null
+ get() = field
+ set(value) {
+ field = value
+ badgeImage.setImageDrawable(value?.toDrawable(context, color = Prefs.iconColor))
+ }
+
+ fun setAllAlpha(alpha: Float) {
+ //badgeTextView.setTextColor(Prefs.textColor.withAlpha(alpha.toInt()))
+ badgeImage.drawable.alpha = alpha.toInt()
+ }
+
+ var badgeText: String?
+ get() = badgeTextView.text.toString()
+ set(value) {
+ badgeTextView.text = value
+ if (value != null && value != "0") badgeTextView.visible()
+ else badgeTextView.gone()
+ }
+
+} \ No newline at end of file