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