横屏分割线改纯XML结构化对齐(match_parent继承时间行高),删除运行时高度代码,版本 1.9
This commit is contained in:
@@ -137,30 +137,11 @@ object LockOverlay {
|
||||
view.findViewById<TextView>(R.id.tvLockClock)?.text = clockFmt.format(cal.time)
|
||||
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
|
||||
view.findViewById<TextView>(R.id.tvLockTask)?.text =
|
||||
task?.takeIf { it.isNotBlank() } ?: view.context.getString(R.string.notif_no_task)
|
||||
}
|
||||
|
||||
/**
|
||||
* 横屏排版里的分割线只分割两块大时间:高度直接由 paint.fontMetrics 算出
|
||||
* (includeFontPadding=false 时 TextView 高度就是 ascent..descent 跨度),
|
||||
* 不依赖布局完成时机——上一版 View.post 在悬浮窗链路上时序不稳导致线消失。
|
||||
* 竖屏布局没有这个控件,查找结果为 null 直接跳过。
|
||||
*/
|
||||
private fun syncDivider(view: View) {
|
||||
val divider = view.findViewById<View>(R.id.lockDivider) ?: return
|
||||
val countdown = view.findViewById<TextView>(R.id.tvLockCountdown) ?: return
|
||||
val fm = countdown.paint.fontMetrics
|
||||
val h = (fm.descent - fm.ascent).toInt()
|
||||
if (h > 0 && divider.layoutParams != null && divider.layoutParams.height != h) {
|
||||
divider.layoutParams.height = h
|
||||
divider.requestLayout()
|
||||
}
|
||||
}
|
||||
|
||||
/** Calendar 的 DAY_OF_WEEK(周日=1)转成 weekdayShort 的下标(周一=0 … 周日=6) */
|
||||
private fun weekdayIndex(cal: Calendar): Int = (cal.get(Calendar.DAY_OF_WEEK) + 5) % 7
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user