分割线改fontMetrics直接计算修复消失;删除线按墨迹中点自绘居中;置顶圆圈粗细与底部对齐调整,版本 1.8

This commit is contained in:
XIGE
2026-11-30 00:10:10 +08:00
parent 035da90a76
commit 3cad26fbdb
5 changed files with 86 additions and 41 deletions

View File

@@ -1,5 +1,16 @@
# 变更记录 # 变更记录
## 2026-11-30 · 分割线改fontMetrics直接计算修复消失;删除线按墨迹中点自绘居中;置顶圆圈粗细与底部对齐调整,版本 1.8
- 同步源码更新 4 个文件(新增/修改 4,删除 0)。
## 2026-11-29 · 分割线算法化/删除线居中/置顶图标对齐(v1.8)
- 横屏分割线消失修复:上一版用 View.post 等布局完成后取 height 再赋值,在锁屏/悬浮窗链路上时机不稳导致线整条消失;改为直接由 paint.fontMetrics 算出文字实际高度(includeFontPadding=false 时 TextView 高度即 ascent..descent 跨度),零时序依赖、立即生效(Activity 与悬浮窗两链路同步)
- 删除线视觉居中:系统 StrikethroughSpan 按「字体半高」定位(baseline + ascent/2),数字/汉字实际墨迹顶比字体 ascent 低,线看起来偏下;改为 MidStrikeSpan 自绘——按 getTextBounds 实际墨迹边界取垂直中点,线严格穿过文字中间,仍只划任务名不划图标
- 置顶图标对齐与粗细:圈线粗细改为 1/10 图标高(贴近重要度圆圈数字的描边),箭头细化为 1/15;圆心从基线上方 0.50 下移到 0.45 个图标高(圆圈数字底缘本就略过基线,底部对齐不再偏上)
- versionCode 42
## 2026-11-29 · 锁屏/通知/任务列表细节修复(v1.7) ## 2026-11-29 · 锁屏/通知/任务列表细节修复(v1.7)
- 任务完成文案:「恭喜你,再接再厉,休息下再继续」→「再接再厉,短暂的休息下再继续」(通知与锁屏共用) - 任务完成文案:「恭喜你,再接再厉,休息下再继续」→「再接再厉,短暂的休息下再继续」(通知与锁屏共用)

View File

@@ -145,19 +145,19 @@ object LockOverlay {
} }
/** /**
* 横屏排版里的分割线只分割两块大时间:高度对齐倒计时文字的实际渲染高度。 * 横屏排版里的分割线只分割两块大时间:高度直接由 paint.fontMetrics 算出
* (includeFontPadding=false 时 TextView 高度就是 ascent..descent 跨度),
* 不依赖布局完成时机——上一版 View.post 在悬浮窗链路上时序不稳导致线消失。
* 竖屏布局没有这个控件,查找结果为 null 直接跳过。 * 竖屏布局没有这个控件,查找结果为 null 直接跳过。
*/ */
private fun syncDivider(view: View) { private fun syncDivider(view: View) {
val divider = view.findViewById<View>(R.id.lockDivider) ?: return val divider = view.findViewById<View>(R.id.lockDivider) ?: return
val countdown = view.findViewById<TextView>(R.id.tvLockCountdown) ?: return val countdown = view.findViewById<TextView>(R.id.tvLockCountdown) ?: return
divider.post { val fm = countdown.paint.fontMetrics
if (countdown.height > 0 && divider.layoutParams != null && val h = (fm.descent - fm.ascent).toInt()
divider.layoutParams.height != countdown.height if (h > 0 && divider.layoutParams != null && divider.layoutParams.height != h) {
) { divider.layoutParams.height = h
divider.layoutParams.height = countdown.height divider.requestLayout()
divider.requestLayout()
}
} }
} }

View File

@@ -163,18 +163,19 @@ class LockScreenActivity : AppCompatActivity() {
} }
/** /**
* 横屏排版里的分割线只分割两块大时间:高度对齐倒计时文字的实际渲染高度, * 横屏排版里的分割线只分割两块大时间,高度对齐倒计时文字的实际渲染高度。
* 不再盖住下方的任务名/日期行。竖屏布局没有这个控件,查找结果为 null 直接跳过。 * 上一版用 View.post 等布局完成后再取 height,实测在悬浮窗/锁屏链路上
* 时机不稳导致分割线整条消失;这里改为直接由 paint.fontMetrics 算出
* (includeFontPadding=false 时 TextView 高度就是 ascent..descent 跨度),
* 零时序依赖、立即生效。竖屏布局没有这个控件,查找结果为 null 直接跳过。
*/ */
private fun syncDivider() { private fun syncDivider() {
val divider = findViewById<View>(R.id.lockDivider) ?: return val divider = findViewById<View>(R.id.lockDivider) ?: return
divider.post { val fm = tvCountdown.paint.fontMetrics
if (tvCountdown.height > 0 && divider.layoutParams != null && val h = (fm.descent - fm.ascent).toInt()
divider.layoutParams.height != tvCountdown.height if (h > 0 && divider.layoutParams != null && divider.layoutParams.height != h) {
) { divider.layoutParams.height = h
divider.layoutParams.height = tvCountdown.height divider.requestLayout()
divider.requestLayout()
}
} }
} }

View File

@@ -539,6 +539,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
} }
companion object { companion object {
const val VERSION = "1.7" const val VERSION = "1.8"
} }
} }

View File

@@ -127,14 +127,12 @@ class TaskAdapter(
) )
} }
// 完成横线只画任务名本身(StrikethroughSpan 限定区间), // 完成横线只画任务名本身(MidStrikeSpan 限定区间,且划线取文字墨迹
// 后面的重要度/紧急度/置顶图标不跟着划线。 // 的垂直中点——系统 StrikethroughSpan 用整字面半高定位,数字/汉字
// 会让线显得偏下)。重要度/紧急度/置顶图标不跟着划线。
// 注意:span 必须在 tvTitle.text = title 之前挂好 // 注意:span 必须在 tvTitle.text = title 之前挂好
if (task.done) { if (task.done) {
title.setSpan( title.setSpan(MidStrikeSpan(), 0, task.title.length, 0)
android.text.style.StrikethroughSpan(),
0, task.title.length, 0,
)
} }
tvTitle.text = title tvTitle.text = title
tvTitle.paintFlags = tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() tvTitle.paintFlags = tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
@@ -208,6 +206,36 @@ class TaskAdapter(
} }
} }
/**
* 任务名删除线:系统 StrikethroughSpan 的划线位置按"字体半高"(baseline + ascent/2)
* 计算,但数字/汉字的实际墨迹顶比字体 ascent 低不少,划线视觉上偏下。
* 这里自绘:按实际墨迹边界(getTextBounds)取垂直中点,线严格穿过文字中间。
*/
private class MidStrikeSpan : android.text.style.ReplacementSpan() {
override fun getSize(
paint: Paint, text: CharSequence, start: Int, end: Int, fm: Paint.FontMetricsInt?,
): Int = paint.measureText(text, start, end).toInt()
override fun draw(
canvas: android.graphics.Canvas, text: CharSequence, start: Int, end: Int,
x: Float, top: Int, baseline: Int, bottom: Int, paint: Paint,
) {
// 先按原样式画字(无删除线标志)
canvas.drawText(text, start, end, x, baseline.toFloat(), paint)
val s = text.toString()
val bounds = android.graphics.Rect()
paint.getTextBounds(s, start, end, bounds)
// 墨迹垂直中点:bounds.top/bottom 相对基线的偏移(top 为负)
val lineY = baseline + (bounds.top + bounds.bottom) / 2f
val w = paint.measureText(text, start, end)
val line = Paint(Paint.ANTI_ALIAS_FLAG)
line.color = paint.color
line.strokeWidth = (paint.textSize / 28f).coerceAtLeast(1f)
canvas.drawLine(x, lineY, x + w, lineY, line)
}
}
/** /**
* 置顶图标:圆圈内向上箭头。 * 置顶图标:圆圈内向上箭头。
* 自绘而不是用字体字形——常用字体里没有"圆圈+箭头"的组合字符, * 自绘而不是用字体字形——常用字体里没有"圆圈+箭头"的组合字符,
@@ -238,24 +266,29 @@ private class PinIconSpan(
x: Float, top: Int, baseline: Int, bottom: Int, paint: Paint, x: Float, top: Int, baseline: Int, bottom: Int, paint: Paint,
) { ) {
val s = size val s = size
// 与 ①②③ 底部对齐:字体里的圆圈数字底缘略微越过基线(约 -0.05 个图标高),
// 圆心取基线上方 0.45 个图标高,比之前 0.50 略下移,底部不再"悬空"显偏上
val cx = x + s / 2f val cx = x + s / 2f
// 与 ①②③ 字形对齐:圆圈数字贴基线站立,圆心约在基线上方 0.5 个图标高 val cy = baseline - s * 0.45f
val cy = baseline - s * 0.5f // 圈线与重要度圆圈数字的描边粗细一致(约 1/10 图标高)
// 不能用 apply { this.color = ... }:作用域里 color 会命中 Paint 自己的 val ring = Paint(Paint.ANTI_ALIAS_FLAG)
// color 属性(默认黑色),把外面的品牌蓝遮掉——就是那版"图标变黑"的原因 ring.color = iconColor
val p = Paint(Paint.ANTI_ALIAS_FLAG) ring.style = Paint.Style.STROKE
p.color = iconColor ring.strokeWidth = s / 10f
p.style = Paint.Style.STROKE ring.strokeCap = Paint.Cap.ROUND
p.strokeWidth = s / 8f canvas.drawCircle(cx, cy, s / 2f - ring.strokeWidth / 2f, ring)
p.strokeCap = Paint.Cap.ROUND
canvas.drawCircle(cx, cy, s / 2f - p.strokeWidth / 2f, p)
// 向上箭头:竖杆 + 两条斜线,整体落在圆内 // 箭头比圈线更细(约 1/15 图标高),整体落在圆内
val head = s * 0.17f val arrow = Paint(Paint.ANTI_ALIAS_FLAG)
val yTop = cy - s * 0.15f arrow.color = iconColor
val yBot = cy + s * 0.19f arrow.style = Paint.Style.STROKE
canvas.drawLine(cx, yBot, cx, yTop, p) arrow.strokeWidth = s / 15f
canvas.drawLine(cx - head, yTop + head, cx, yTop, p) arrow.strokeCap = Paint.Cap.ROUND
canvas.drawLine(cx + head, yTop + head, cx, yTop, p) val head = s * 0.18f
val yTop = cy - s * 0.16f
val yBot = cy + s * 0.18f
canvas.drawLine(cx, yBot, cx, yTop, arrow)
canvas.drawLine(cx - head, yTop + head, cx, yTop, arrow)
canvas.drawLine(cx + head, yTop + head, cx, yTop, arrow)
} }
} }