mihon/app/src/main/java/eu/kanade/tachiyomi/widget/PTSansTextView.kt

48 lines
1.4 KiB
Kotlin
Raw Normal View History

2016-03-08 01:22:56 +01:00
package eu.kanade.tachiyomi.widget
import android.content.Context
import android.graphics.Canvas
import android.graphics.Typeface
import android.util.AttributeSet
import android.widget.TextView
import eu.kanade.tachiyomi.R
import java.util.*
2016-03-08 01:22:56 +01:00
class PTSansTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
TextView(context, attrs) {
companion object {
const val PTSANS_NARROW = 0
const val PTSANS_NARROW_BOLD = 1
// Map where typefaces are cached
private val typefaces = HashMap<Int, Typeface>(2)
2016-03-08 01:22:56 +01:00
}
init {
if (attrs != null) {
val values = context.obtainStyledAttributes(attrs, R.styleable.PTSansTextView)
val typeface = values.getInt(R.styleable.PTSansTextView_typeface, 0)
setTypeface(typefaces.getOrPut(typeface) {
Typeface.createFromAsset(context.assets, when (typeface) {
PTSANS_NARROW -> "fonts/PTSans-Narrow.ttf"
PTSANS_NARROW_BOLD -> "fonts/PTSans-NarrowBold.ttf"
else -> throw IllegalArgumentException("Font not found " + typeface)
})
})
2016-03-08 01:22:56 +01:00
values.recycle()
}
}
override fun onDraw(canvas: Canvas) {
2016-03-08 01:22:56 +01:00
// Draw two times for a more visible shadow around the text
super.onDraw(canvas)
super.onDraw(canvas)
2016-03-08 01:22:56 +01:00
}
}