ButtonView: Adjust size of question marks

pull/849/head
Alinson S. Xavier 5 years ago
parent ee462715de
commit 7b68938e14

@ -124,7 +124,6 @@ class CheckmarkButtonView(
typeface = getFontAwesome() typeface = getFontAwesome()
isAntiAlias = true isAntiAlias = true
textAlign = Paint.Align.CENTER textAlign = Paint.Align.CENTER
textSize = dim(R.dimen.smallTextSize)
} }
fun draw(canvas: Canvas) { fun draw(canvas: Canvas) {
@ -147,6 +146,12 @@ class CheckmarkButtonView(
} }
else -> R.string.fa_check else -> R.string.fa_check
} }
paint.textSize = when (value) {
UNKNOWN -> dim(R.dimen.smallerTextSize)
else -> dim(R.dimen.smallTextSize)
}
val label = resources.getString(id) val label = resources.getString(id)
val em = paint.measureText("m") val em = paint.measureText("m")

@ -33,6 +33,7 @@ import org.isoron.uhabits.core.preferences.Preferences
import org.isoron.uhabits.inject.ActivityContext import org.isoron.uhabits.inject.ActivityContext
import org.isoron.uhabits.utils.InterfaceUtils.getDimension import org.isoron.uhabits.utils.InterfaceUtils.getDimension
import org.isoron.uhabits.utils.StyledResources import org.isoron.uhabits.utils.StyledResources
import org.isoron.uhabits.utils.dim
import org.isoron.uhabits.utils.getFontAwesome import org.isoron.uhabits.utils.getFontAwesome
import org.isoron.uhabits.utils.showMessage import org.isoron.uhabits.utils.showMessage
import java.text.DecimalFormat import java.text.DecimalFormat
@ -131,22 +132,22 @@ class NumberButtonView(
private val lowContrast: Int private val lowContrast: Int
private val mediumContrast: Int private val mediumContrast: Int
private val pRegular: TextPaint = TextPaint().apply { private val pUnit: TextPaint = TextPaint().apply {
textSize = getDimension(context, R.dimen.smallerTextSize) textSize = getDimension(context, R.dimen.smallerTextSize)
typeface = NORMAL_TYPEFACE typeface = NORMAL_TYPEFACE
isAntiAlias = true isAntiAlias = true
textAlign = Paint.Align.CENTER textAlign = Paint.Align.CENTER
} }
private val pBold: TextPaint = TextPaint().apply { private val pNumber: TextPaint = TextPaint().apply {
textSize = getDimension(context, R.dimen.smallTextSize) textSize = dim(R.dimen.smallTextSize)
typeface = BOLD_TYPEFACE typeface = BOLD_TYPEFACE
isAntiAlias = true isAntiAlias = true
textAlign = Paint.Align.CENTER textAlign = Paint.Align.CENTER
} }
init { init {
em = pBold.measureText("m") em = pNumber.measureText("m")
lowContrast = sr.getColor(R.attr.contrast40) lowContrast = sr.getColor(R.attr.contrast40)
mediumContrast = sr.getColor(R.attr.contrast60) mediumContrast = sr.getColor(R.attr.contrast60)
} }
@ -160,31 +161,36 @@ class NumberButtonView(
val label: String val label: String
val typeface: Typeface val typeface: Typeface
val textSize: Float
when { when {
value >= 0 -> { value >= 0 -> {
label = value.toShortString() label = value.toShortString()
typeface = BOLD_TYPEFACE typeface = BOLD_TYPEFACE
textSize = dim(R.dimen.smallTextSize)
} }
preferences.areQuestionMarksEnabled() -> { preferences.areQuestionMarksEnabled() -> {
label = resources.getString(R.string.fa_question) label = resources.getString(R.string.fa_question)
typeface = getFontAwesome() typeface = getFontAwesome()
textSize = dim(R.dimen.smallerTextSize)
} }
else -> { else -> {
label = "0" label = "0"
typeface = BOLD_TYPEFACE typeface = BOLD_TYPEFACE
textSize = dim(R.dimen.smallTextSize)
} }
} }
pBold.color = activeColor pNumber.textSize = textSize
pBold.typeface = typeface pNumber.color = activeColor
pRegular.color = activeColor pNumber.typeface = typeface
pUnit.color = activeColor
rect.set(0f, 0f, width.toFloat(), height.toFloat()) rect.set(0f, 0f, width.toFloat(), height.toFloat())
canvas.drawText(label, rect.centerX(), rect.centerY(), pBold) canvas.drawText(label, rect.centerX(), rect.centerY(), pNumber)
rect.offset(0f, 1.2f * em) rect.offset(0f, 1.3f * em)
canvas.drawText(units, rect.centerX(), rect.centerY(), pRegular) canvas.drawText(units, rect.centerX(), rect.centerY(), pUnit)
} }
} }
} }

Loading…
Cancel
Save