mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Trim unit labels when necessary
This commit is contained in:
@@ -189,16 +189,19 @@ class NumberButtonView(
|
|||||||
textSize = dim(R.dimen.smallTextSize)
|
textSize = dim(R.dimen.smallTextSize)
|
||||||
typeface = getFontAwesome()
|
typeface = getFontAwesome()
|
||||||
}
|
}
|
||||||
|
|
||||||
value >= 0 -> {
|
value >= 0 -> {
|
||||||
label = value.toShortString()
|
label = value.toShortString()
|
||||||
typeface = BOLD_TYPEFACE
|
typeface = BOLD_TYPEFACE
|
||||||
textSize = dim(R.dimen.smallTextSize)
|
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)
|
textSize = dim(R.dimen.smallerTextSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
label = "0"
|
label = "0"
|
||||||
typeface = BOLD_TYPEFACE
|
typeface = BOLD_TYPEFACE
|
||||||
@@ -212,14 +215,23 @@ class NumberButtonView(
|
|||||||
pUnit.color = activeColor
|
pUnit.color = activeColor
|
||||||
|
|
||||||
if (units.isBlank()) {
|
if (units.isBlank()) {
|
||||||
|
// Draw number without units
|
||||||
rect.set(0f, 0f, width.toFloat(), height.toFloat())
|
rect.set(0f, 0f, width.toFloat(), height.toFloat())
|
||||||
rect.offset(0f, 0.5f * em)
|
rect.offset(0f, 0.5f * em)
|
||||||
canvas.drawText(label, rect.centerX(), rect.centerY(), pNumber)
|
canvas.drawText(label, rect.centerX(), rect.centerY(), pNumber)
|
||||||
} else {
|
} else {
|
||||||
|
// Draw number
|
||||||
rect.set(0f, 0f, width.toFloat(), height.toFloat())
|
rect.set(0f, 0f, width.toFloat(), height.toFloat())
|
||||||
canvas.drawText(label, rect.centerX(), rect.centerY(), pNumber)
|
canvas.drawText(label, rect.centerX(), rect.centerY(), pNumber)
|
||||||
|
|
||||||
|
// Draw units
|
||||||
|
val maxUnitsWidth = width * 0.9f
|
||||||
|
var trimmedUnits = units
|
||||||
|
while (trimmedUnits.length > 2 && pUnit.measureText(trimmedUnits) > maxUnitsWidth) {
|
||||||
|
trimmedUnits = trimmedUnits.dropLast(2) + "…"
|
||||||
|
}
|
||||||
rect.offset(0f, 1.3f * em)
|
rect.offset(0f, 1.3f * em)
|
||||||
canvas.drawText(units, rect.centerX(), rect.centerY(), pUnit)
|
canvas.drawText(trimmedUnits, rect.centerX(), rect.centerY(), pUnit)
|
||||||
}
|
}
|
||||||
|
|
||||||
drawNotesIndicator(canvas, color, em, notes)
|
drawNotesIndicator(canvas, color, em, notes)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?><!--
|
||||||
<!--
|
|
||||||
~ Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
~ Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||||
~
|
~
|
||||||
~ This file is part of Loop Habit Tracker.
|
~ This file is part of Loop Habit Tracker.
|
||||||
@@ -32,8 +31,7 @@
|
|||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:textColor="?attr/contrast60"
|
android:textColor="?attr/contrast60"
|
||||||
android:textSize="@dimen/regularTextSize"
|
android:textSize="@dimen/regularTextSize"
|
||||||
tools:text="Have you worked out today?"
|
tools:text="Have you worked out today?" />
|
||||||
/>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -54,12 +52,14 @@
|
|||||||
android:id="@+id/targetText"
|
android:id="@+id/targetText"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="8.5k"
|
android:text=""
|
||||||
android:textColor="?attr/contrast60"
|
android:textColor="?attr/contrast60"
|
||||||
android:textSize="@dimen/smallTextSize"
|
android:textSize="@dimen/smallTextSize"
|
||||||
android:layout_marginStart="4dp"
|
android:layout_marginStart="4dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
/>
|
android:maxEms="7"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:ellipsize="end" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/frequencyIcon"
|
android:id="@+id/frequencyIcon"
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="1dp"
|
android:paddingTop="1dp"
|
||||||
android:textColor="?attr/contrast60"
|
android:textColor="?attr/contrast60"
|
||||||
android:text="8:00 AM"
|
android:text=""
|
||||||
android:layout_marginStart="4dp"
|
android:layout_marginStart="4dp"
|
||||||
android:textSize="@dimen/smallTextSize" />
|
android:textSize="@dimen/smallTextSize" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user