项目统计补累计专注分钟、展开行点开编辑删除、置顶前移并统一圆圈规格、已完成任务折叠(v3.1)
This commit is contained in:
@@ -85,23 +85,32 @@ class TaskAdapter(
|
||||
val ctx = itemView.context
|
||||
|
||||
// 标题右侧的属性图标,未完成与已完成都显示:
|
||||
// 重要度圆圈数字(③ 高 / ② 中 / ① 普通,颜色与紧急度同色系)→
|
||||
// 紧急度五角星 → 随时上箭头。
|
||||
// 各字形在字体里的字面尺寸不同:以圆圈数字 0.85 为基准,
|
||||
// 上箭头与圆圈同高;五角星 0.95 不作参照
|
||||
// 置顶圆圈箭头(「随时」未完成任务)→ 重要度圆圈数字 → 紧急度五角星。
|
||||
// 置顶与重要度两个圆圈统一自绘:同一尺寸(0.85 倍字号)、同一描边(s/10),
|
||||
// 保证粗细与高度完全一致;五角星仍用字形,0.95 倍不作参照。
|
||||
val title = SpannableStringBuilder(task.title)
|
||||
val iconSize = tvTitle.textSize * 0.85f
|
||||
|
||||
val (badge, badgeColor) = when (task.priority) {
|
||||
2 -> " ③" to R.color.urgent_high
|
||||
1 -> " ②" to R.color.urgent_mid
|
||||
else -> " ①" to R.color.urgent_low
|
||||
// 置顶图标前移到重要度圆圈之前(品牌蓝圆圈内向上箭头)
|
||||
if (task.repeatType == com.focusbox.app.model.Repeat.ANYTIME && !task.done) {
|
||||
title.append("\u2009")
|
||||
title.setSpan(
|
||||
PinIconSpan(ctx.col(R.color.brand), iconSize),
|
||||
title.length - 1, title.length, 0,
|
||||
)
|
||||
}
|
||||
title.append(badge)
|
||||
|
||||
// 重要度圆圈:3 高 / 2 中 / 1 普通,颜色与紧急度同色系
|
||||
val (digit, badgeColor) = when (task.priority) {
|
||||
2 -> "3" to R.color.urgent_high
|
||||
1 -> "2" to R.color.urgent_mid
|
||||
else -> "1" to R.color.urgent_low
|
||||
}
|
||||
title.append(" ")
|
||||
title.setSpan(
|
||||
android.text.style.ForegroundColorSpan(ctx.col(badgeColor)),
|
||||
title.length - badge.length, title.length, 0
|
||||
PriorityBadgeSpan(ctx.col(badgeColor), iconSize, digit),
|
||||
title.length - 1, title.length, 0,
|
||||
)
|
||||
title.setSpan(RelativeSizeSpan(0.85f), title.length - badge.length, title.length, 0)
|
||||
|
||||
// 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰
|
||||
val (stars, starColor) = when (task.urgency) {
|
||||
@@ -116,17 +125,6 @@ class TaskAdapter(
|
||||
)
|
||||
title.setSpan(RelativeSizeSpan(0.95f), title.length - stars.length, title.length, 0)
|
||||
|
||||
// 「随时」任务:标题后带品牌蓝圆圈上箭头表示置顶,列表里排在未完成最前面。
|
||||
// 图标与重要度圆圈数字同规格(0.85 倍字号,圆圈里画向上箭头),
|
||||
// 圆圈与箭头同色(品牌蓝);前面的细空格(U+2009)保持与星标的间距一致。
|
||||
if (task.repeatType == com.focusbox.app.model.Repeat.ANYTIME && !task.done) {
|
||||
title.append("\u2009 ")
|
||||
title.setSpan(
|
||||
PinIconSpan(ctx.col(R.color.brand), tvTitle.textSize * 0.85f),
|
||||
title.length - 1, title.length, 0,
|
||||
)
|
||||
}
|
||||
|
||||
// 完成横线只画任务名本身(MidStrikeSpan 限定区间,且划线取文字墨迹
|
||||
// 的垂直中点——系统 StrikethroughSpan 用整字面半高定位,数字/汉字
|
||||
// 会让线显得偏下)。重要度/紧急度/置顶图标不跟着划线。
|
||||
@@ -236,6 +234,61 @@ private class MidStrikeSpan : android.text.style.ReplacementSpan() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 置顶与重要度共用的圆环绘制:同尺寸、同描边(s/10),保证两个圆圈粗细一致。 */
|
||||
private fun drawBadgeRing(
|
||||
canvas: android.graphics.Canvas, cx: Float, cy: Float, size: Float, ringColor: Int,
|
||||
) {
|
||||
val ring = android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG).apply {
|
||||
this.color = ringColor
|
||||
style = android.graphics.Paint.Style.STROKE
|
||||
strokeWidth = size / 10f
|
||||
strokeCap = android.graphics.Paint.Cap.ROUND
|
||||
}
|
||||
canvas.drawCircle(cx, cy, size / 2f - ring.strokeWidth / 2f, ring)
|
||||
}
|
||||
|
||||
/**
|
||||
* 重要度圆圈数字:自绘圆环 + 数字,与置顶圆圈共用 drawBadgeRing,
|
||||
* 高度(0.85 倍字号)与描边(s/10)严格一致,不再依赖系统字形 ①②③ 的墨迹差异。
|
||||
*/
|
||||
private class PriorityBadgeSpan(
|
||||
private val badgeColor: Int,
|
||||
private val size: Float,
|
||||
private val digit: String,
|
||||
) : android.text.style.ReplacementSpan() {
|
||||
|
||||
override fun getSize(
|
||||
paint: Paint, text: CharSequence, start: Int, end: Int, fm: Paint.FontMetricsInt?,
|
||||
): Int {
|
||||
val s = size.toInt()
|
||||
if (fm != null) {
|
||||
fm.ascent = -s
|
||||
fm.descent = 0
|
||||
fm.top = fm.ascent
|
||||
fm.bottom = fm.descent
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
override fun draw(
|
||||
canvas: android.graphics.Canvas, text: CharSequence, start: Int, end: Int,
|
||||
x: Float, top: Int, baseline: Int, bottom: Int, paint: Paint,
|
||||
) {
|
||||
val s = size
|
||||
val cy = baseline - s * 0.45f
|
||||
val cx = x + s / 2f
|
||||
drawBadgeRing(canvas, cx, cy, s, badgeColor)
|
||||
val num = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
this.color = badgeColor
|
||||
textSize = s * 0.60f
|
||||
typeface = Typeface.DEFAULT
|
||||
textAlign = Paint.Align.CENTER
|
||||
}
|
||||
val fm = num.fontMetrics
|
||||
canvas.drawText(digit, cx, cy - (fm.ascent + fm.descent) / 2f, num)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 置顶图标:圆圈内向上箭头。
|
||||
* 自绘而不是用字体字形——常用字体里没有"圆圈+箭头"的组合字符,
|
||||
@@ -270,13 +323,8 @@ private class PinIconSpan(
|
||||
// 圆心取基线上方 0.45 个图标高,比之前 0.50 略下移,底部不再"悬空"显偏上
|
||||
val cx = x + s / 2f
|
||||
val cy = baseline - s * 0.45f
|
||||
// 圈线与重要度圆圈数字的描边粗细一致(约 1/10 图标高)
|
||||
val ring = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
ring.color = iconColor
|
||||
ring.style = Paint.Style.STROKE
|
||||
ring.strokeWidth = s / 10f
|
||||
ring.strokeCap = Paint.Cap.ROUND
|
||||
canvas.drawCircle(cx, cy, s / 2f - ring.strokeWidth / 2f, ring)
|
||||
// 与重要度圆圈共用同一绘制函数:同尺寸、同 1/10 描边,粗细与高度严格一致
|
||||
drawBadgeRing(canvas, cx, cy, s, iconColor)
|
||||
|
||||
// 箭头比圈线更细(约 1/15 图标高),整体落在圆内
|
||||
val arrow = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
|
||||
Reference in New Issue
Block a user