package com.qimai.android.tools

import android.content.Context

/**
 *   created by wangwei   ON 2019-08-29  email:wangwei_5521@163.com
 *   @version 1.1.1
 *   @Description
 **/

fun Context.dpTopx(dp: Float): Int {
    val scale = resources.displayMetrics.density
    return (dp * scale + 0.5f).toInt()
}

fun Context.pxToDp(px: Float): Int {
    val scale = resources.displayMetrics.density
    return (px / scale + 0.5f).toInt();
}

fun Context.pxTosp(pxValue: Float): Int {
    val fontScale = resources.displayMetrics.scaledDensity
    return (pxValue / fontScale + 0.5f).toInt()
}

fun Context.spTopx(spValue: Float): Int {
    val fontScale = resources.displayMetrics.scaledDensity
    return (spValue * fontScale + 0.5f).toInt()
}

//spanString拼接
fun Context.SpannableString(text: CharSequence) =  MySpannableString(this,text)
