Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60fd3d1044 | ||
|
|
ed7927af1d | ||
|
|
2d999edc0c | ||
|
|
4e062923ef |
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,5 +1,26 @@
|
||||
# 变更记录
|
||||
|
||||
## 2026-11-30 · 回退 v2.3 布局基线 + 倒计时等宽缩号(v2.6)
|
||||
|
||||
- 起因:v2.5 的 autoSize 方案在锁屏/悬浮窗特殊窗口上渲染异常(时间缩小居中、高度只显示约三分之一),判定 autoSize 在该链路不可靠,彻底放弃。按用户要求回退到 v2.3(确认"高度对齐成功"的版本)重新修。
|
||||
- 回退:layout-land 布局从 git 提交 2dd7f8b 原样恢复,撤销 v2.4/v2.5 全部布局改动(贴线边距、match_parent、autoSize、tnum、gravity end/start)。
|
||||
- 重新修「右边距离比左边大」:唯一来源是倒计时 ≥100 分钟时为 6 位数(120:00),比右侧时钟宽出一个数字。新增 util/CountdownFit:按实际字体测量(Paint.measureText)把 6 位倒计时缩到与时钟完全等宽,居中布局下左右间隙天然相等;回到 5 位立即恢复 130sp(越大越好不变)。LockScreenActivity 与 LockOverlay 两条渲染链路同时接入。
|
||||
- 竖向对齐不受影响:时间列「时间+10dp+小字」整体居中,时间垂直中心=列中心−(10dp+小字)/2 与字号无关;中列锚点保持 130sp。
|
||||
- 版本号不回退(Android 不允许 versionCode 降级覆盖安装):2.6 / versionCode 50。
|
||||
- 改动文件:layout-land/activity_lock_screen.xml(恢复 v2.3)、LockScreenActivity.kt、LockOverlay.kt、util/CountdownFit.kt(新增)、build.gradle.kts、build.sh、SettingsFragment.kt。
|
||||
- 本地验证:构建通过,aapt2 确认 versionCode 50 / versionName 2.6,签名 SHA-256 7bcbd511…cc8c83 不变。
|
||||
- 升级说明:直接覆盖安装(可覆盖 v2.4/v2.5),无数据迁移。
|
||||
|
||||
## 2026-11-30 · 分割线左右等距 + autoSize 防溢出(v2.5)
|
||||
|
||||
- 起因:v2.4 后用户反馈「距离没变、一个屏幕装不下、需要左右滑动才能完整显示两个时间」。
|
||||
- 根因(本轮钉死):倒计时 ≥100 分钟时是 6 位数(如 120:00),130sp 下宽约 410dp,超出半屏可用宽度(约 366dp);wrap_content 被压缩后文字从框左缘起画、向右溢出越过分割线——左边贴死/越线、右边 24dp,即「右边距离比左边大 + 装不下」。
|
||||
- 方案:两个大时间改 match_parent 定宽 + autoSize 自动缩号(40sp..130sp)。5 位数保持 130sp 原样(「越大越好」不变);6 位数缩到刚好装下,永不溢出;文字 end/start 对齐 → 线到两边时间间隙恒为 24dp。时间列「时间+10dp+小字」整体居中,时间垂直中心=列中心−(10dp+小字)/2 与字号无关 → 一侧缩号不破坏竖向对齐。
|
||||
- 视觉变化:时间从「半屏居中」改为「贴线排布」,文字向外生长,与线的距离恒定;≥100 分钟时倒计时一侧字号自动略小。
|
||||
- 改动文件:layout-land/activity_lock_screen.xml、build.gradle.kts、build.sh、SettingsFragment.kt。
|
||||
- 本地验证:构建通过,aapt2 确认 versionCode 49 / versionName 2.5,签名 SHA-256 7bcbd511…cc8c83 不变。
|
||||
- 升级说明:直接覆盖安装,无数据迁移。
|
||||
|
||||
## 2026-11-30 · 分割线左右等距 + 等宽数字(v2.4)
|
||||
|
||||
- 起因:v2.3 垂直对齐成功后,用户反馈线到左右两边时间的水平间隙不相等。
|
||||
|
||||
@@ -12,6 +12,7 @@ import android.view.WindowManager
|
||||
import android.widget.TextView
|
||||
import com.focusbox.app.R
|
||||
import com.focusbox.app.data.Store
|
||||
import com.focusbox.app.util.CountdownFit
|
||||
import com.focusbox.app.util.Dates
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
@@ -134,8 +135,14 @@ object LockOverlay {
|
||||
val cal = Calendar.getInstance()
|
||||
view.findViewById<TextView>(R.id.tvLockDate)?.text =
|
||||
"${Dates.mdLong(cal.timeInMillis)} 星期${Dates.weekdayShort(weekdayIndex(cal))}"
|
||||
view.findViewById<TextView>(R.id.tvLockClock)?.text = clockFmt.format(cal.time)
|
||||
view.findViewById<TextView>(R.id.tvLockCountdown)?.text = Dates.clock(now)
|
||||
val tvClock = view.findViewById<TextView>(R.id.tvLockClock)
|
||||
val tvCountdown = view.findViewById<TextView>(R.id.tvLockCountdown)
|
||||
tvClock?.text = clockFmt.format(cal.time)
|
||||
tvCountdown?.text = Dates.clock(now)
|
||||
// 倒计时 6 位数(≥100 分钟)时缩到与时钟等宽,保证左右间隙相等;5 位恢复 130sp
|
||||
if (tvClock != null && tvCountdown != null) {
|
||||
CountdownFit.fit(tvCountdown, tvClock, tvCountdown.text.toString(), tvClock.text.toString())
|
||||
}
|
||||
|
||||
val task = if (TimerCore.taskId > 0) Store.task(TimerCore.taskId)?.title else null
|
||||
view.findViewById<TextView>(R.id.tvLockTask)?.text =
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.focusbox.app.R
|
||||
import com.focusbox.app.data.Store
|
||||
import com.focusbox.app.service.Notif
|
||||
import com.focusbox.app.service.TimerCore
|
||||
import com.focusbox.app.util.CountdownFit
|
||||
import com.focusbox.app.util.Dates
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
@@ -155,6 +156,8 @@ class LockScreenActivity : AppCompatActivity() {
|
||||
tvDate.text = "${Dates.mdLong(cal.timeInMillis)} 星期${Dates.weekdayShort(weekdayIndex(cal))}"
|
||||
tvClock.text = clockFmt.format(cal.time)
|
||||
tvCountdown.text = Dates.clock(now)
|
||||
// 倒计时 6 位数(≥100 分钟)时缩到与时钟等宽,保证左右间隙相等;5 位恢复 130sp
|
||||
CountdownFit.fit(tvCountdown, tvClock, tvCountdown.text.toString(), tvClock.text.toString())
|
||||
|
||||
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)
|
||||
|
||||
@@ -539,6 +539,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val VERSION = "2.4"
|
||||
const val VERSION = "2.6"
|
||||
}
|
||||
}
|
||||
|
||||
41
src/main/java/com/focusbox/app/util/CountdownFit.kt
Normal file
41
src/main/java/com/focusbox/app/util/CountdownFit.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.focusbox.app.util
|
||||
|
||||
import android.util.TypedValue
|
||||
import android.widget.TextView
|
||||
import kotlin.math.abs
|
||||
|
||||
/**
|
||||
* 倒计时等宽缩号:倒计时 ≥100 分钟时为 6 位数(如 120:00),比右侧时钟
|
||||
* (恒 5 位 HH:mm)宽出整整一个数字。锁屏横屏是居中布局,左边文字更宽
|
||||
* 会把左侧间隙压小、甚至越过分割线——表现为「右边距离比左边大」。
|
||||
*
|
||||
* 对策:按实际字体测量(Paint.measureText,不依赖任何估算的字体参数),
|
||||
* 把倒计时文字宽度缩到与时钟完全等宽 → 居中布局下左右间隙天然相等;
|
||||
* 回到 5 位时恢复基准字号(130sp,越大越好不变)。
|
||||
*
|
||||
* 竖向对齐不受影响:时间列结构为「时间 + 10dp + 小字」且整体居中,
|
||||
* 时间的垂直中心 = 列中心 − (10dp+小字)/2,与时间自身字号无关,
|
||||
* 缩号后分割线仍与两侧时间上下对齐。
|
||||
*/
|
||||
object CountdownFit {
|
||||
|
||||
/** 每个 TextView 的基准字号(px),首次调用时捕获(来自布局 130sp) */
|
||||
private val baseSizes = HashMap<TextView, Float>()
|
||||
|
||||
/** 应用等宽缩号。调用前提:clockText 已先行设置到 clock 上 */
|
||||
fun fit(countdown: TextView, clock: TextView, countdownText: String, clockText: String) {
|
||||
val base = baseSizes.getOrPut(countdown) { countdown.textSize }
|
||||
// 先复位到基准,再按基准度量宽度(paint 的 textSize 在 setTextSize 后同步生效)
|
||||
if (countdown.textSize != base) {
|
||||
countdown.setTextSize(TypedValue.COMPLEX_UNIT_PX, base)
|
||||
}
|
||||
val cdW = countdown.paint.measureText(countdownText)
|
||||
val clockW = clock.paint.measureText(clockText)
|
||||
if (cdW > clockW) {
|
||||
val target = base * clockW / cdW
|
||||
if (abs(countdown.textSize - target) > 0.5f) {
|
||||
countdown.setTextSize(TypedValue.COMPLEX_UNIT_PX, target)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,13 +16,6 @@
|
||||
v2.3 改为中列完整镜像左右两栏(时间锚点 + 同规格小字占位),三列同高同顶,
|
||||
锚点中心严格等于时间文字中心;纯静态 XML,不受锁屏/悬浮窗特殊窗口运行时
|
||||
调整失效问题影响,字体缩放变化也同步。
|
||||
|
||||
v2.4 左右等距:v2.3 后用户反馈线到两边时间的左右间隙不相等。实测 Roboto
|
||||
数字等宽且布局对称,间隙不等只可能来自系统字体(鸿蒙 HarmonyOS Sans)
|
||||
数字非等宽,或倒计时 ≥100 分钟时多出一位。对策:①左栏改右对齐、右栏改
|
||||
左对齐,各距分割线固定 24dp——布局间隙无条件相等,不依赖文字宽度;
|
||||
②两侧大时间与锚点加 fontFeatureSettings=tnum,系统字体支持时强制数字
|
||||
等宽,连墨迹抖动也消除(不支持时无副作用)。
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/lockRoot"
|
||||
@@ -34,22 +27,18 @@
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<!-- 左:倒计时 + 任务名(右对齐贴线:右缘距分割线固定 24dp,
|
||||
与右栏对称,保证线到两边时间的布局间隙恒相等,
|
||||
不依赖两侧文字宽度恰好相同——鸿蒙系统字体数字非等宽时也成立) -->
|
||||
<!-- 左:倒计时 + 任务名 -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical|end"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLockCountdown"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:fontFeatureSettings="tnum"
|
||||
android:includeFontPadding="false"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="130sp"
|
||||
@@ -60,7 +49,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:ellipsize="end"
|
||||
android:maxWidth="320dp"
|
||||
android:maxLines="1"
|
||||
@@ -87,7 +75,6 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFeatureSettings="tnum"
|
||||
android:includeFontPadding="false"
|
||||
android:maxLines="1"
|
||||
android:visibility="invisible"
|
||||
@@ -113,21 +100,18 @@
|
||||
android:textSize="15sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 右:时钟(大)+ 日期星期在时钟下面(左对齐贴线:左缘距分割线固定 24dp,
|
||||
与左栏对称;tnum 强制等宽数字,系统字体支持时两侧宽度恒等、不再抖动) -->
|
||||
<!-- 右:时钟(大)+ 日期星期在时钟下面 -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical|start"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLockClock"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
android:fontFeatureSettings="tnum"
|
||||
android:includeFontPadding="false"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="130sp"
|
||||
@@ -138,7 +122,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginStart="24dp"
|
||||
android:textColor="#99FFFFFF"
|
||||
android:textSize="15sp" />
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user