This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.siu.android.univelo.paris.ui.view.util | |
import android.content.res.AssetManager | |
import android.graphics.Typeface | |
import android.view.View | |
import java.util.* | |
/** | |
* @author Lukasz Piliszczuk - lukasz.pili@gmail.com | |
*/ | |
private val fonts = HashMap<String, Typeface>() | |
private const val FONT_AVENIR_LIGHT = "Avenir-Light.ttf" | |
private const val FONT_HELVETICA = "Helvetica.ttf" | |
private const val FONT_HELVETICA_LIGHT = "Helvetica-Light.ttf" | |
private const val FONT_HEITI_LIGHT = "STHeiti-TC-Light.ttf" | |
private const val FONT_HEITI_MEDIUM = "STHeiti-TC-Medium.ttf" | |
private fun load(assetManager: AssetManager, filePath: String): Typeface? { | |
if (!fonts.containsKey(filePath)) { | |
val typeface = Typeface.createFromAsset(assetManager, filePath) | |
fonts.put(filePath, typeface) | |
return typeface | |
} | |
return fonts[filePath] | |
} | |
fun View.font(name: String) = load(context.assets, "fonts/$name") | |
fun View.avenirLight() = font(FONT_AVENIR_LIGHT) | |
fun View.helvetica() = font(FONT_HELVETICA) | |
fun View.helveticaLight() = font(FONT_HELVETICA_LIGHT) | |
fun View.heitiLight() = font(FONT_HEITI_LIGHT) | |
fun View.heitiMedium() = font(FONT_HEITI_MEDIUM) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment