Add app/src/main/java/space/bloggin/scribe/Ui.kt
This commit is contained in:
@@ -0,0 +1,80 @@
|
|||||||
|
package space.bloggin.scribe
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.Typeface
|
||||||
|
import android.graphics.drawable.GradientDrawable
|
||||||
|
import android.util.TypedValue
|
||||||
|
import android.view.Gravity
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.Button
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.TextView
|
||||||
|
|
||||||
|
object Ui {
|
||||||
|
val INK = Color.parseColor("#1E1E24")
|
||||||
|
val PAPER = Color.parseColor("#F4F1EA")
|
||||||
|
val LINE = Color.parseColor("#D6D0C2")
|
||||||
|
val ACCENT = Color.parseColor("#B3261E")
|
||||||
|
val MUTED = Color.parseColor("#6B6B73")
|
||||||
|
val LIVE = Color.parseColor("#1F7A3E")
|
||||||
|
|
||||||
|
fun dp(ctx: Context, v: Int): Int = (v * ctx.resources.displayMetrics.density + 0.5f).toInt()
|
||||||
|
|
||||||
|
/** Square-cornered button. */
|
||||||
|
fun button(ctx: Context, label: String, fill: Int = INK, textColor: Int = Color.WHITE): Button {
|
||||||
|
val b = Button(ctx)
|
||||||
|
b.text = label
|
||||||
|
b.isAllCaps = false
|
||||||
|
b.setTextColor(textColor)
|
||||||
|
b.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
|
||||||
|
b.typeface = Typeface.DEFAULT_BOLD
|
||||||
|
val d = GradientDrawable()
|
||||||
|
d.shape = GradientDrawable.RECTANGLE
|
||||||
|
d.cornerRadius = 0f
|
||||||
|
d.setColor(fill)
|
||||||
|
d.setStroke(dp(ctx, 1), INK)
|
||||||
|
b.background = d
|
||||||
|
b.stateListAnimator = null
|
||||||
|
b.minHeight = dp(ctx, 52)
|
||||||
|
b.minimumHeight = dp(ctx, 52)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ghostButton(ctx: Context, label: String) = button(ctx, label, PAPER, INK)
|
||||||
|
|
||||||
|
fun text(ctx: Context, s: String, sp: Float = 16f, color: Int = INK, bold: Boolean = false): TextView {
|
||||||
|
val t = TextView(ctx)
|
||||||
|
t.text = s
|
||||||
|
t.setTextSize(TypedValue.COMPLEX_UNIT_SP, sp)
|
||||||
|
t.setTextColor(color)
|
||||||
|
if (bold) t.typeface = Typeface.DEFAULT_BOLD
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
fun topBar(ctx: Context, title: String, vararg right: View): LinearLayout {
|
||||||
|
val bar = LinearLayout(ctx)
|
||||||
|
bar.orientation = LinearLayout.HORIZONTAL
|
||||||
|
bar.gravity = Gravity.CENTER_VERTICAL
|
||||||
|
bar.setBackgroundColor(INK)
|
||||||
|
bar.setPadding(dp(ctx, 16), dp(ctx, 12), dp(ctx, 8), dp(ctx, 12))
|
||||||
|
val t = text(ctx, title, 22f, Color.WHITE, true)
|
||||||
|
bar.addView(t, LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f))
|
||||||
|
for (v in right) bar.addView(v)
|
||||||
|
return bar
|
||||||
|
}
|
||||||
|
|
||||||
|
fun barButton(ctx: Context, label: String): Button {
|
||||||
|
val b = Button(ctx)
|
||||||
|
b.text = label
|
||||||
|
b.isAllCaps = false
|
||||||
|
b.setTextColor(Color.WHITE)
|
||||||
|
b.background = null
|
||||||
|
b.stateListAnimator = null
|
||||||
|
b.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15f)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fmtDate(ms: Long): String =
|
||||||
|
java.text.SimpleDateFormat("MMM d, h:mm a", java.util.Locale.getDefault()).format(java.util.Date(ms))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user