5 Commits
v1.4 ... v1.7

11 changed files with 290 additions and 66 deletions

View File

@@ -1,5 +1,35 @@
# 变更记录 # 变更记录
## 2026-11-29 · 完成文案改字;横屏分割线只分时间;置顶图标黑色bug修复恢复品牌蓝;完成删除线恢复,版本 1.7
- 同步源码更新 6 个文件(新增/修改 6,删除 0)。
## 2026-11-29 · 锁屏/通知/任务列表细节修复(v1.7)
- 任务完成文案:「恭喜你,再接再厉,休息下再继续」→「再接再厉,短暂的休息下再继续」(通知与锁屏共用)
- 横屏锁屏分割线:只分割两块大时间——运行时把分割线高度对齐倒计时文字的实际渲染高度(Activity 与悬浮窗两条链路都同步),不再盖住下方任务名/日期行
- 置顶图标颜色修复:PinIconSpan 在 `Paint(...).apply { this.color = color }` 里,作用域内 color 被 Paint 自身属性遮蔽,实际画的是 Paint 默认黑色——改名 iconColor 并显式赋值,恢复品牌蓝;深色 #64A8FF / 浅色 #2F80ED 自动适配
- 已完成删除线恢复:StrikethroughSpan 之前在 tvTitle.text 赋值之后才挂 span 导致不生效,移到赋值之前;仍然只划任务名、不划图标
- versionCode 41
## 2026-11-29 · 任务列表/统计细节打磨(v1.6)
- 已完成任务:删除线只画任务名(StrikethroughSpan 限定区间),后面的重要度圆圈/紧急度星标/置顶图标不再被划线
- 「随时」置顶图标:由裸 ↑ 字符改为自绘「圆圈内向上箭头」(PinIconSpan,ReplacementSpan 实现)——圆圈与箭头同为品牌蓝,图标大小与重要度圆圈数字一致(0.85 倍字号)
- 统计页两个饼图(项目分布/任务分布):环中心的「总专注」「任务占比」小字删除,累计时间按字体度量把墨迹垂直中心落在圆心,真正居中
- 设置页悬浮窗权限行:已授权时不再显示右侧箭头、且整行不可点(该权限无应用内开关,避免误以为可点);未授权保持「去设置」可点跳授权页
- 每日目标:数值支持点击弹窗直接输入分钟数(软键盘数字盘,非法输入红框提示),加减步进保留;去除 720 分钟上限(下限 15 防误输)
- versionCode 40
## 2026-11-29 · 悬浮窗补齐遮状态栏与横竖屏排版;解锁残留秒级自动关窗(v1.5)
- 悬浮窗遮状态栏:EMUI 把悬浮窗限制在状态栏以下内容区,顶部时间/信号/电池露出——窗口改为比屏幕更大(高度补状态栏+导航栏)、y 负偏移状态栏高度向上顶出,配 FLAG_LAYOUT_NO_LIMITS 越界绘制,黑底完整盖住状态栏区域(护眼滤镜类 App 同款做法)
- 横竖屏排版恢复:TimerService 增加 onConfigurationChanged 回调,旋转时立刻重建悬浮窗窗口换对应布局;update() 内旋转检测保留双保险
- 解锁残留修复:悬浮窗每秒刷新时检查 keyguard,解锁后自动关窗(不依赖 USER_PRESENT 广播),不再出现"解锁后全屏界面挡住桌面"
- 亮屏时悬浮窗显示中仍尝试直启沉浸式锁屏页(主题级全屏+横竖屏排版),成功则接管显示,被拦无损失
- 说明:v1.4 并未删除沉浸式遮状态栏与横屏布局——它们在锁屏 Activity 上完好,问题出在悬浮窗是新窗口没有继承这两个表现,本版补齐
- 版本 1.4 → 1.5(versionCode 39)
## 2026-11-29 · 锁屏倒计时主链路改悬浮窗:WindowManager 直接画在锁屏上,不受"后台弹出界面"限制(v1.4) ## 2026-11-29 · 锁屏倒计时主链路改悬浮窗:WindowManager 直接画在锁屏上,不受"后台弹出界面"限制(v1.4)
- 根因链补全:鸿蒙 4.0 的"后台弹出界面"策略只拦 startActivity,悬浮窗(WindowManager.addView)不属于 Activity 启动、不在拦截范围——这正是专注清单等 App 锁屏显示稳定的原因(其权限列表含"悬浮窗") - 根因链补全:鸿蒙 4.0 的"后台弹出界面"策略只拦 startActivity,悬浮窗(WindowManager.addView)不属于 Activity 启动、不在拦截范围——这正是专注清单等 App 锁屏显示稳定的原因(其权限列表含"悬浮窗")

View File

@@ -59,9 +59,18 @@ object LockOverlay {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
WindowManager.LayoutParams.TYPE_PHONE WindowManager.LayoutParams.TYPE_PHONE
} }
// 关键:EMUI 把悬浮窗限制在状态栏以下的内容区里(顶部时间/信号/电池露出来)。
// 对策是把窗口做得比屏幕更大并向上顶出——高度补上状态栏和导航栏,
// y 偏移取负的状态栏高度,配 FLAG_LAYOUT_NO_LIMITS 允许越界绘制,
// 黑底就完整盖住状态栏区域(护眼滤镜类 App 同款做法)
val res = ctx.resources
val sbId = res.getIdentifier("status_bar_height", "dimen", "android")
val navId = res.getIdentifier("navigation_bar_height", "dimen", "android")
val statusBar = if (sbId > 0) res.getDimensionPixelSize(sbId) else 0
val navBar = if (navId > 0) res.getDimensionPixelSize(navId) else 0
val lp = WindowManager.LayoutParams( val lp = WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, res.displayMetrics.widthPixels,
WindowManager.LayoutParams.MATCH_PARENT, res.displayMetrics.heightPixels + statusBar + navBar,
type, type,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
or WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
@@ -69,7 +78,9 @@ object LockOverlay {
or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
PixelFormat.TRANSLUCENT, PixelFormat.TRANSLUCENT,
) )
lp.gravity = Gravity.CENTER lp.gravity = Gravity.TOP
lp.x = 0
lp.y = -statusBar
manager.addView(view, lp) manager.addView(view, lp)
root = view root = view
@@ -91,11 +102,18 @@ object LockOverlay {
} }
/** /**
* 每秒刷新读数;横竖屏变化时重建窗口(悬浮窗不经过 Activity 重建, * 每秒刷新读数;顺带做两件保活级检查:
* 只能自己检测 configuration 并换布局重新 inflate)。 * 1. 用户已解锁(keyguard 解除)→ 自动关窗——不依赖 USER_PRESENT 广播,
* 广播在个别 ROM 上时序不稳,靠这秒级兜底保证解锁后不留全屏黑窗挡桌面;
* 2. 横竖屏变化 → 重建窗口换对应排版(悬浮窗不经过 Activity 重建)。
*/ */
fun update(context: Context) { fun update(context: Context) {
val view = root ?: return val view = root ?: return
val km = context.getSystemService(Context.KEYGUARD_SERVICE) as android.app.KeyguardManager
if (!km.isKeyguardLocked()) {
hide()
return
}
val current = context.resources.configuration.orientation val current = context.resources.configuration.orientation
if (current != orientation) { if (current != orientation) {
hide() hide()
@@ -119,11 +137,30 @@ object LockOverlay {
view.findViewById<TextView>(R.id.tvLockClock)?.text = clockFmt.format(cal.time) view.findViewById<TextView>(R.id.tvLockClock)?.text = clockFmt.format(cal.time)
view.findViewById<TextView>(R.id.tvLockCountdown)?.text = Dates.clock(now) view.findViewById<TextView>(R.id.tvLockCountdown)?.text = Dates.clock(now)
syncDivider(view)
val task = if (TimerCore.taskId > 0) Store.task(TimerCore.taskId)?.title else null val task = if (TimerCore.taskId > 0) Store.task(TimerCore.taskId)?.title else null
view.findViewById<TextView>(R.id.tvLockTask)?.text = view.findViewById<TextView>(R.id.tvLockTask)?.text =
task?.takeIf { it.isNotBlank() } ?: view.context.getString(R.string.notif_no_task) task?.takeIf { it.isNotBlank() } ?: view.context.getString(R.string.notif_no_task)
} }
/**
* 横屏排版里的分割线只分割两块大时间:高度对齐倒计时文字的实际渲染高度。
* 竖屏布局没有这个控件,查找结果为 null 直接跳过。
*/
private fun syncDivider(view: View) {
val divider = view.findViewById<View>(R.id.lockDivider) ?: return
val countdown = view.findViewById<TextView>(R.id.tvLockCountdown) ?: return
divider.post {
if (countdown.height > 0 && divider.layoutParams != null &&
divider.layoutParams.height != countdown.height
) {
divider.layoutParams.height = countdown.height
divider.requestLayout()
}
}
}
/** Calendar 的 DAY_OF_WEEK(周日=1)转成 weekdayShort 的下标(周一=0 … 周日=6) */ /** Calendar 的 DAY_OF_WEEK(周日=1)转成 weekdayShort 的下标(周一=0 … 周日=6) */
private fun weekdayIndex(cal: Calendar): Int = (cal.get(Calendar.DAY_OF_WEEK) + 5) % 7 private fun weekdayIndex(cal: Calendar): Int = (cal.get(Calendar.DAY_OF_WEEK) + 5) % 7
} }

View File

@@ -129,23 +129,32 @@ class TimerService : Service() {
private fun onScreenOn() { private fun onScreenOn() {
TimerCore.tick() TimerCore.tick()
syncLockOverlay() syncLockOverlay()
if (LockOverlay.isShowing()) return // 悬浮窗已盖住锁屏时,仍尝试用沉浸式锁屏页接管——
if (LockScreenActivity.showing) { // Activity 有主题级全屏(状态栏彻底遮掉)+ 横竖屏专属排版,
// 悬浮窗不可用但锁屏页已被全屏意图拉起,抽屉里的触发通知清掉 // 直启成功则显示效果更完整;被鸿蒙拦截也无损失,悬浮窗继续顶着
Notif.cancelFullscreen(this) if (Prefs.lockFullscreen && TimerCore.running) {
} else if (Prefs.lockFullscreen && TimerCore.running) {
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
if (km.isKeyguardLocked()) { if (km.isKeyguardLocked()) {
// 全兜底:先试服务直启,再留一条全屏意图通知让用户点进同一页面
runCatching { runCatching {
startActivity( startActivity(
Intent(this, LockScreenActivity::class.java) Intent(this, LockScreenActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
) )
} }
if (!LockOverlay.isShowing() && !LockScreenActivity.showing) {
// 悬浮窗和直启都失败:留全屏意图通知兜底(点进同一页面)
Notif.updateFullscreen(this) Notif.updateFullscreen(this)
} }
} }
} else if (LockScreenActivity.showing) {
Notif.cancelFullscreen(this)
}
}
/** 系统配置变化(旋转):悬浮窗立刻换横/竖屏排版重建 */
override fun onConfigurationChanged(newConfig: android.content.res.Configuration) {
super.onConfigurationChanged(newConfig)
LockOverlay.update(this)
} }
private val onStateChanged: () -> Unit = { private val onStateChanged: () -> Unit = {

View File

@@ -156,10 +156,28 @@ class LockScreenActivity : AppCompatActivity() {
tvClock.text = clockFmt.format(cal.time) tvClock.text = clockFmt.format(cal.time)
tvCountdown.text = Dates.clock(now) tvCountdown.text = Dates.clock(now)
syncDivider()
val task = if (TimerCore.taskId > 0) Store.task(TimerCore.taskId)?.title else null val task = if (TimerCore.taskId > 0) Store.task(TimerCore.taskId)?.title else null
tvTask.text = task?.takeIf { it.isNotBlank() } ?: getString(R.string.notif_no_task) tvTask.text = task?.takeIf { it.isNotBlank() } ?: getString(R.string.notif_no_task)
} }
/**
* 横屏排版里的分割线只分割两块大时间:高度对齐倒计时文字的实际渲染高度,
* 不再盖住下方的任务名/日期行。竖屏布局没有这个控件,查找结果为 null 直接跳过。
*/
private fun syncDivider() {
val divider = findViewById<View>(R.id.lockDivider) ?: return
divider.post {
if (tvCountdown.height > 0 && divider.layoutParams != null &&
divider.layoutParams.height != tvCountdown.height
) {
divider.layoutParams.height = tvCountdown.height
divider.requestLayout()
}
}
}
/** Calendar 的 DAY_OF_WEEK(周日=1)转成 weekdayShort 的下标(周一=0 … 周日=6) */ /** Calendar 的 DAY_OF_WEEK(周日=1)转成 weekdayShort 的下标(周一=0 … 周日=6) */
private fun weekdayIndex(cal: Calendar): Int = (cal.get(Calendar.DAY_OF_WEEK) + 5) % 7 private fun weekdayIndex(cal: Calendar): Int = (cal.get(Calendar.DAY_OF_WEEK) + 5) % 7
} }

View File

@@ -94,15 +94,16 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
toggle(getString(R.string.vibrate), Prefs.vibrateOn) { Prefs.vibrateOn = it }, toggle(getString(R.string.vibrate), Prefs.vibrateOn) { Prefs.vibrateOn = it },
toggle(getString(R.string.keep_screen_on), Prefs.keepScreenOn) { Prefs.keepScreenOn = it }, toggle(getString(R.string.keep_screen_on), Prefs.keepScreenOn) { Prefs.keepScreenOn = it },
toggle(getString(R.string.lock_fullscreen_title), Prefs.lockFullscreen) { Prefs.lockFullscreen = it }, toggle(getString(R.string.lock_fullscreen_title), Prefs.lockFullscreen) { Prefs.lockFullscreen = it },
// 悬浮窗权限:锁屏倒计时主链路(鸿蒙拦 Activity 后台启动,悬浮窗不受限) // 悬浮窗权限:锁屏倒计时主链路(鸿蒙拦 Activity 后台启动,悬浮窗不受限)。
action( // 已授权时既没有右侧箭头也不可点——权限本身没有应用内开关,免得误以为能点进去设置
getString(R.string.overlay_perm_title), run {
if (com.focusbox.app.service.LockOverlay.canShow(requireContext())) { val granted = com.focusbox.app.service.LockOverlay.canShow(requireContext())
getString(R.string.perm_granted) if (granted) {
action(getString(R.string.overlay_perm_title), getString(R.string.perm_granted), showArrow = false)
} else { } else {
getString(R.string.go_set) action(getString(R.string.overlay_perm_title), getString(R.string.go_set)) { openOverlayPerm() }
}
}, },
) { openOverlayPerm() },
// 华为/鸿蒙默认拦截后台拉起页面,无悬浮窗权限时的 Activity 兜底链路也要这两项权限; // 华为/鸿蒙默认拦截后台拉起页面,无悬浮窗权限时的 Activity 兜底链路也要这两项权限;
// 放在开关正下方,用户开了开关不生效时第一眼就能看到入口 // 放在开关正下方,用户开了开关不生效时第一眼就能看到入口
action(getString(R.string.lock_perm_title), getString(R.string.lock_perm_value)) { openLockPerm() }, action(getString(R.string.lock_perm_title), getString(R.string.lock_perm_value)) { openLockPerm() },
@@ -113,6 +114,8 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
stepper( stepper(
getString(R.string.daily_goal), getString(R.string.daily_goal),
getString(R.string.value_minutes, Prefs.dailyGoalMinutes), getString(R.string.value_minutes, Prefs.dailyGoalMinutes),
// 数值支持直接点击输入;步进用于微调。Prefs 里没有上限
onEdit = { inputDailyGoal() },
) { delta -> ) { delta ->
Prefs.dailyGoalMinutes += delta * 15 Prefs.dailyGoalMinutes += delta * 15
build() build()
@@ -184,7 +187,8 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
setBackgroundColor(col(R.color.divider)) setBackgroundColor(col(R.color.divider))
} }
private fun stepper(title: String, value: String, onChange: (Int) -> Unit): View { /** onEdit 非空时点击数值可直接输入(目前只有每日目标用);onChange 为加减步进 */
private fun stepper(title: String, value: String, onEdit: (() -> Unit)? = null, onChange: (Int) -> Unit): View {
val ctx = requireContext() val ctx = requireContext()
val row = LinearLayout(ctx).apply { val row = LinearLayout(ctx).apply {
orientation = LinearLayout.HORIZONTAL orientation = LinearLayout.HORIZONTAL
@@ -205,6 +209,7 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
gravity = Gravity.CENTER gravity = Gravity.CENTER
setTextColor(col(R.color.title)) setTextColor(col(R.color.title))
layoutParams = LinearLayout.LayoutParams(dpi(74f), LinearLayout.LayoutParams.WRAP_CONTENT) layoutParams = LinearLayout.LayoutParams(dpi(74f), LinearLayout.LayoutParams.WRAP_CONTENT)
if (onEdit != null) setOnClickListener { onEdit() }
}) })
row.addView(stepButton("+") { onChange(1) }) row.addView(stepButton("+") { onChange(1) })
return row return row
@@ -246,13 +251,19 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
return row return row
} }
private fun action(title: String, value: String, danger: Boolean = false, onClick: () -> Unit): View { private fun action(
title: String,
value: String,
danger: Boolean = false,
showArrow: Boolean = true,
onClick: (() -> Unit)? = null,
): View {
val ctx = requireContext() val ctx = requireContext()
val row = LinearLayout(ctx).apply { val row = LinearLayout(ctx).apply {
orientation = LinearLayout.HORIZONTAL orientation = LinearLayout.HORIZONTAL
gravity = Gravity.CENTER_VERTICAL gravity = Gravity.CENTER_VERTICAL
minimumHeight = dpi(54f) minimumHeight = dpi(54f)
setOnClickListener { onClick() } if (onClick != null) setOnClickListener { onClick() }
} }
row.addView(TextView(ctx).apply { row.addView(TextView(ctx).apply {
text = title text = title
@@ -268,11 +279,13 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
setPadding(0, 0, dpi(6f), 0) setPadding(0, 0, dpi(6f), 0)
}) })
} }
if (showArrow) {
row.addView(android.widget.ImageView(ctx).apply { row.addView(android.widget.ImageView(ctx).apply {
setImageResource(R.drawable.ic_chevron_right) setImageResource(R.drawable.ic_chevron_right)
tint(col(R.color.text_tertiary)) tint(col(R.color.text_tertiary))
layoutParams = LinearLayout.LayoutParams(dpi(15f), dpi(15f)) layoutParams = LinearLayout.LayoutParams(dpi(15f), dpi(15f))
}) })
}
return row return row
} }
@@ -328,6 +341,78 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
dialog.show() dialog.show()
} }
/** 每日目标:弹小窗直接输入分钟数(无上限,下限 15 由 Prefs 兜底) */
private fun inputDailyGoal() {
val ctx = requireContext()
val dialog = android.app.Dialog(ctx)
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
val panel = LinearLayout(ctx).apply {
orientation = LinearLayout.VERTICAL
background = ctx.roundBg(ctx.col(R.color.surface), 16f, ctx.col(R.color.card_stroke), 1f)
setPadding(dpi(20f), dpi(20f), dpi(20f), dpi(14f))
}
panel.addView(TextView(ctx).apply {
text = getString(R.string.daily_goal)
textSize = 16f
typeface = Typeface.DEFAULT_BOLD
setTextColor(col(R.color.text))
})
val et = android.widget.EditText(ctx).apply {
inputType = android.text.InputType.TYPE_CLASS_NUMBER
setText(Prefs.dailyGoalMinutes.toString())
textSize = 15f
setTextColor(col(R.color.text))
background = ctx.roundBg(ctx.col(R.color.surface_alt), 12f)
setPadding(dpi(14f), dpi(12f), dpi(14f), dpi(12f))
layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
).apply { topMargin = dpi(14f) }
}
panel.addView(et)
et.requestFocus()
val btnRow = LinearLayout(ctx).apply {
orientation = LinearLayout.HORIZONTAL
gravity = Gravity.END
setPadding(0, dpi(12f), 0, 0)
}
fun btn(labelRes: Int, onClick: () -> Unit) = TextView(ctx).apply {
text = getString(labelRes)
textSize = 14f
typeface = Typeface.DEFAULT_BOLD
gravity = Gravity.CENTER
setTextColor(col(R.color.brand))
background = ctx.roundBg(ctx.col(R.color.surface_alt), 12f)
setPadding(dpi(22f), dpi(10f), dpi(22f), dpi(10f))
setOnClickListener { onClick() }
}
btnRow.addView(btn(R.string.cancel) { dialog.dismiss() })
btnRow.addView(btn(R.string.save) {
val input = et.text.toString().trim().toIntOrNull()
if (input != null) {
Prefs.dailyGoalMinutes = input
dialog.dismiss()
build()
} else {
et.error = " "
}
}, LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT).apply {
marginStart = dpi(10f)
})
panel.addView(btnRow)
dialog.setContentView(panel)
dialog.show()
// 弹窗不自动抢输入法焦点,手动拉起软键盘
et.postDelayed({
val imm = ctx.getSystemService(android.content.Context.INPUT_METHOD_SERVICE)
as? android.view.inputmethod.InputMethodManager
imm?.showSoftInput(et, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
}, 100L)
}
/** 悬浮窗权限:标准 Android 特殊权限,有公开检测 API 和授权页,一键直达本应用 */ /** 悬浮窗权限:标准 Android 特殊权限,有公开检测 API 和授权页,一键直达本应用 */
private fun openOverlayPerm() { private fun openOverlayPerm() {
val ctx = requireContext() val ctx = requireContext()
@@ -454,6 +539,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
} }
companion object { companion object {
const val VERSION = "1.4" const val VERSION = "1.7"
} }
} }

View File

@@ -205,8 +205,6 @@ class PeriodDistributionCard @JvmOverloads constructor(
} }
) )
donut.centerText = Dates.durationBrief(raw.sumOf { it.seconds }) donut.centerText = Dates.durationBrief(raw.sumOf { it.seconds })
donut.centerCaption =
context.getString(if (byTask) R.string.task_share else R.string.total_focus)
tvPeriod.text = periodLabel(from, to) tvPeriod.text = periodLabel(from, to)
applySegments() applySegments()

View File

@@ -116,24 +116,28 @@ class TaskAdapter(
) )
title.setSpan(RelativeSizeSpan(0.95f), title.length - stars.length, title.length, 0) title.setSpan(RelativeSizeSpan(0.95f), title.length - stars.length, title.length, 0)
// 「随时」任务:标题后带品牌蓝上箭头表示置顶,列表里排在未完成最前面。 // 「随时」任务:标题后带品牌蓝圆圈上箭头表示置顶,列表里排在未完成最前面。
// ↑ 字形窄、两侧留白大,全角空格会显得左边距比五角星宽, // 图标与重要度圆圈数字同规格(0.85 倍字号,圆圈里画向上箭头),
// 改用细空格(U+2009)让两侧间隙与星标一致。 // 圆圈与箭头同色(品牌蓝);前面的细空格(U+2009)保持与星标的间距一致。
if (task.repeatType == com.focusbox.app.model.Repeat.ANYTIME && !task.done) { if (task.repeatType == com.focusbox.app.model.Repeat.ANYTIME && !task.done) {
title.append("\u2009↑") title.append("\u2009 ")
title.setSpan( title.setSpan(
android.text.style.ForegroundColorSpan(ctx.col(R.color.brand)), PinIconSpan(ctx.col(R.color.brand), tvTitle.textSize * 0.85f),
title.length - 2, title.length, 0 title.length - 1, title.length, 0,
) )
title.setSpan(RelativeSizeSpan(0.85f), title.length - 2, title.length, 0)
} }
tvTitle.text = title // 完成横线只画任务名本身(StrikethroughSpan 限定区间),
tvTitle.paintFlags = if (task.done) { // 后面的重要度/紧急度/置顶图标不跟着划线。
tvTitle.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG // 注意:span 必须在 tvTitle.text = title 之前挂好
} else { if (task.done) {
tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() title.setSpan(
android.text.style.StrikethroughSpan(),
0, task.title.length, 0,
)
} }
tvTitle.text = title
tvTitle.paintFlags = tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
tvTitle.setTextColor(ctx.col(if (task.done) R.color.text_tertiary else R.color.text)) tvTitle.setTextColor(ctx.col(if (task.done) R.color.text_tertiary else R.color.text))
tvTitle.typeface = if (task.priority >= 2 && !task.done) Typeface.DEFAULT_BOLD else Typeface.DEFAULT tvTitle.typeface = if (task.priority >= 2 && !task.done) Typeface.DEFAULT_BOLD else Typeface.DEFAULT
@@ -203,3 +207,55 @@ class TaskAdapter(
private const val TYPE_FOOTER = 1 private const val TYPE_FOOTER = 1
} }
} }
/**
* 置顶图标:圆圈内向上箭头。
* 自绘而不是用字体字形——常用字体里没有"圆圈+箭头"的组合字符,
* 画出来才能精确控制圆圈与箭头同色、且和重要度圆圈数字(0.85 倍字号)等高。
* 颜色用品牌蓝(R.color.brand,深浅色主题各有一版),与之前的 ↑ 字符颜色一致。
*/
private class PinIconSpan(
private val iconColor: Int,
private val size: Float,
) : 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 cx = x + s / 2f
// 与 ①②③ 字形对齐:圆圈数字贴基线站立,圆心约在基线上方 0.5 个图标高
val cy = baseline - s * 0.5f
// 不能用 apply { this.color = ... }:作用域里 color 会命中 Paint 自己的
// color 属性(默认黑色),把外面的品牌蓝遮掉——就是那版"图标变黑"的原因
val p = Paint(Paint.ANTI_ALIAS_FLAG)
p.color = iconColor
p.style = Paint.Style.STROKE
p.strokeWidth = s / 8f
p.strokeCap = Paint.Cap.ROUND
canvas.drawCircle(cx, cy, s / 2f - p.strokeWidth / 2f, p)
// 向上箭头:竖杆 + 两条斜线,整体落在圆内
val head = s * 0.17f
val yTop = cy - s * 0.15f
val yBot = cy + s * 0.19f
canvas.drawLine(cx, yBot, cx, yTop, p)
canvas.drawLine(cx - head, yTop + head, cx, yTop, p)
canvas.drawLine(cx + head, yTop + head, cx, yTop, p)
}
}

View File

@@ -62,9 +62,10 @@ object Prefs {
set(v) = sp.edit().putBoolean("lock_fullscreen", v).apply() set(v) = sp.edit().putBoolean("lock_fullscreen", v).apply()
// ---- 目标 ---- // ---- 目标 ----
// 无上限:输入多大存多大(下限 15 防止误输 0/负数把目标显示搞崩)
var dailyGoalMinutes: Int var dailyGoalMinutes: Int
get() = sp.getInt("daily_goal", 120) get() = sp.getInt("daily_goal", 120)
set(v) = sp.edit().putInt("daily_goal", v.coerceIn(15, 720)).apply() set(v) = sp.edit().putInt("daily_goal", v.coerceAtLeast(15)).apply()
/** 0 跟随系统 / 1 浅色 / 2 深色 */ /** 0 跟随系统 / 1 浅色 / 2 深色 */
var themeMode: Int var themeMode: Int

View File

@@ -43,13 +43,6 @@ class LabelDonutView @JvmOverloads constructor(
invalidate() invalidate()
} }
/** 环中心的小字(总专注 / 任务占比) */
var centerCaption: String = ""
set(value) {
field = value
invalidate()
}
/** 最多画几条引线标注,多出来的合并成「其他」,避免标注挤成一团 */ /** 最多画几条引线标注,多出来的合并成「其他」,避免标注挤成一团 */
var maxLabels: Int = 6 var maxLabels: Int = 6
@@ -76,13 +69,7 @@ class LabelDonutView @JvmOverloads constructor(
textAlign = Paint.Align.CENTER textAlign = Paint.Align.CENTER
isFakeBoldText = true isFakeBoldText = true
} }
private val captionPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { private val linePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE
textSize = context.spf(10f)
color = context.col(R.color.text_tertiary)
textAlign = Paint.Align.CENTER
}
private val linePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.STROKE
strokeWidth = context.dpf(1.2f) strokeWidth = context.dpf(1.2f)
} }
private val dotPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL } private val dotPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
@@ -188,13 +175,15 @@ class LabelDonutView @JvmOverloads constructor(
) )
} }
/**
* 环中心只画一行:累计时间(或空态提示)。
* 之前按 cy + 2dp 硬偏移定位,字面重心偏下;改为按字体度量
* 把墨迹垂直中心落在圆心,并删除原来的小字说明行。
*/
private fun drawCenter(canvas: Canvas, cx: Float, cy: Float, emptyHint: String?) { private fun drawCenter(canvas: Canvas, cx: Float, cy: Float, emptyHint: String?) {
val big = centerText.takeIf { it.isNotBlank() } ?: "0m" val text = emptyHint ?: centerText.ifBlank { "0m" }
canvas.drawText(big, cx, cy + context.dpf(2f), centerPaint) val fm = centerPaint.fontMetrics
val cap = emptyHint ?: centerCaption canvas.drawText(text, cx, cy - (fm.ascent + fm.descent) / 2f, centerPaint)
if (cap.isNotBlank()) {
canvas.drawText(cap, cx, cy + context.dpf(18f), captionPaint)
}
} }
/** /**

View File

@@ -43,8 +43,9 @@
android:textSize="15sp" /> android:textSize="15sp" />
</LinearLayout> </LinearLayout>
<!-- 中:细分隔线 --> <!-- 中:细分隔线(只分割两块大时间,高度运行时对齐倒计时文字的实际高度) -->
<View <View
android:id="@+id/lockDivider"
android:layout_width="1dp" android:layout_width="1dp"
android:layout_height="180dp" android:layout_height="180dp"
android:background="#26FFFFFF" /> android:background="#26FFFFFF" />

View File

@@ -222,7 +222,7 @@
<string name="notif_action_stop">结束</string> <string name="notif_action_stop">结束</string>
<string name="notif_no_task">未选择任务</string> <string name="notif_no_task">未选择任务</string>
<string name="notif_focus_done">任务完成</string> <string name="notif_focus_done">任务完成</string>
<string name="notif_focus_done_text">恭喜你,再接再厉,休息下再继续</string> <string name="notif_focus_done_text">再接再厉,短暂的休息下再继续</string>
<string name="notif_break_done">休息结束</string> <string name="notif_break_done">休息结束</string>
<string name="notif_break_done_text">准备好就开始下一轮</string> <string name="notif_break_done_text">准备好就开始下一轮</string>