8 Commits
v1.2 ... v1.6

13 changed files with 446 additions and 88 deletions

View File

@@ -1,8 +1,42 @@
# 变更记录 # 变更记录
## 2026-11-29 · 项目排序模式序号与置顶;横屏锁屏遮状态栏、排版对称化;版本 1.2 ## 2026-11-29 · 完成任务删除线只画任务名;置顶改圆圈箭头图标;饼图中心删小字居中;悬浮窗权限已开启不可点;每日目标可输入去上限,版本 1.6
- 同步源码更新 10 个文件(新增/修改 10,删除 0)。 - 同步源码更新 5 个文件(新增/修改 5,删除 0)。
## 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)
- 根因链补全:鸿蒙 4.0 的"后台弹出界面"策略只拦 startActivity,悬浮窗(WindowManager.addView)不属于 Activity 启动、不在拦截范围——这正是专注清单等 App 锁屏显示稳定的原因(其权限列表含"悬浮窗")
- 新增 SYSTEM_ALERT_WINDOW 权限 + service/LockOverlay.kt:计时中锁屏/灭屏时把黑底倒计时窗口(TYPE_APPLICATION_OVERLAY + FLAG_SHOW_WHEN_LOCKED)直接画在锁屏之上;复用锁屏页布局(自动选竖屏/横屏版本,旋转重建窗口);FLAG_NOT_FOCUSABLE 不影响锁屏密码输入;点按任意处关闭;解锁(USER_PRESENT)自动关闭;计时结束自动关闭
- 三级降级链路:悬浮窗(有权限,主链路)→ 全屏意图通知/服务直启 → 抽屉通知点进锁屏页
- 设置页新增「悬浮窗权限(锁屏显示)」入口:有公开检测 API(canDrawOverlays),显示"已开启/去开启",一键跳本应用授权页
- 版本 1.3 → 1.4(versionCode 38)
## 2026-11-29 · 竖屏删「工作中」提示;横屏时间加大、下方文字统一规格并收紧间距(v1.3)
- 竖屏锁屏页删除「工作中/休息中」字样(代码同步移除 tvLockMode 赋值,横竖屏均无该控件)
- 横屏两个时间(倒计时/时钟)96sp → 130sp,尽可能大
- 横屏时间下方文字(左任务名 / 右日期星期)统一为 15sp、同色 #99FFFFFF,与时间距离由 20dp 收紧到 10dp(约一半)
- 右侧日期星期去掉 letterSpacing,与时钟严格左右居中(与左侧倒计时/任务名的居中方式一致)
- 版本 1.2 → 1.3(versionCode 37)
## 2026-11-29 · 项目排序模式(序号+置顶);横屏锁屏遮状态栏、排版对称化(v1.2) ## 2026-11-29 · 项目排序模式(序号+置顶);横屏锁屏遮状态栏、排版对称化(v1.2)

View File

@@ -15,6 +15,8 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<!-- 锁屏全屏倒计时:计时中锁屏亮屏时把全屏页盖在锁屏上 --> <!-- 锁屏全屏倒计时:计时中锁屏亮屏时把全屏页盖在锁屏上 -->
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" /> <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<!-- 锁屏悬浮窗:鸿蒙拦 Activity 后台启动,改用 WindowManager 直接把倒计时画在锁屏上(addView 不受"后台弹出界面"限制) -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />

View File

@@ -0,0 +1,147 @@
package com.focusbox.app.service
import android.content.Context
import android.content.res.Configuration
import android.graphics.PixelFormat
import android.os.Build
import android.provider.Settings
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import com.focusbox.app.R
import com.focusbox.app.data.Store
import com.focusbox.app.util.Dates
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale
/**
* 锁屏悬浮窗:计时中锁屏/灭屏时,把黑底倒计时窗口直接画在锁屏之上。
*
* 为什么用悬浮窗:鸿蒙 4.0 对「后台弹出界面」的限制只拦 startActivity
* (实测开了权限也拦,全屏意图灭屏投递也不可靠),而 WindowManager.addView
* 悬浮窗不属于 Activity 启动,只要用户授了「悬浮窗」权限就能稳定盖在锁屏上
* ——这正是专注清单等 App 锁屏显示的做法。
*
* 窗口内容直接复用锁屏页布局(activity_lock_screen),inflate 时系统按当前
* 横竖屏自动选 layout 或 layout-land,旋转后重建窗口即可切换排版。
* FLAG_NOT_FOCUSABLE 不抢按键(不影响锁屏密码输入),点击任意处关闭。
*/
object LockOverlay {
private var root: View? = null
private var wm: WindowManager? = null
private var orientation = Configuration.ORIENTATION_PORTRAIT
private val clockFmt = SimpleDateFormat("HH:mm", Locale.getDefault())
/** 悬浮窗窗口是否正显示在锁屏上 */
fun isShowing(): Boolean = root != null
/** 用户是否已授予「悬浮窗」权限 */
fun canShow(context: Context): Boolean = Settings.canDrawOverlays(context)
/** 显示(幂等):已在显示或无权限时不重复添加 */
fun show(context: Context) {
if (root != null || !canShow(context)) return
try {
val ctx = context.applicationContext
val manager = ctx.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val view = LayoutInflater.from(ctx).inflate(R.layout.activity_lock_screen, null)
view.setOnClickListener { hide() }
// API 26+ 用应用悬浮窗类型;更旧版本退回 TYPE_PHONE(本应用 minSdk 24)
val type = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
} else {
@Suppress("DEPRECATION")
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(
res.displayMetrics.widthPixels,
res.displayMetrics.heightPixels + statusBar + navBar,
type,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
or WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
PixelFormat.TRANSLUCENT,
)
lp.gravity = Gravity.TOP
lp.x = 0
lp.y = -statusBar
manager.addView(view, lp)
root = view
wm = manager
orientation = ctx.resources.configuration.orientation
render(view)
} catch (_: Exception) {
root = null
wm = null
}
}
/** 关闭(幂等):窗口不存在时无事发生 */
fun hide() {
val view = root ?: return
root = null
wm?.let { runCatching { it.removeView(view) } }
wm = null
}
/**
* 每秒刷新读数;顺带做两件保活级检查:
* 1. 用户已解锁(keyguard 解除)→ 自动关窗——不依赖 USER_PRESENT 广播,
* 广播在个别 ROM 上时序不稳,靠这秒级兜底保证解锁后不留全屏黑窗挡桌面;
* 2. 横竖屏变化 → 重建窗口换对应排版(悬浮窗不经过 Activity 重建)。
*/
fun update(context: Context) {
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
if (current != orientation) {
hide()
show(context)
return
}
render(view)
}
private fun render(view: View) {
val now = TimerCore.displayNow()
// 计时结束:窗口使命完成,自动关闭
if (!TimerCore.running && now <= 0) {
hide()
return
}
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 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)
}
/** Calendar 的 DAY_OF_WEEK(周日=1)转成 weekdayShort 的下标(周一=0 … 周日=6) */
private fun weekdayIndex(cal: Calendar): Int = (cal.get(Calendar.DAY_OF_WEEK) + 5) % 7
}

View File

@@ -53,6 +53,8 @@ class TimerService : Service() {
// 只推进状态,不再每秒重发通知:通知里的时间是系统的 Chronometer 在走, // 只推进状态,不再每秒重发通知:通知里的时间是系统的 Chronometer 在走,
// 每秒 notify 反而会让锁屏上的计时被系统限流后"冻住"。 // 每秒 notify 反而会让锁屏上的计时被系统限流后"冻住"。
TimerCore.tick() TimerCore.tick()
// 锁屏悬浮窗的读数刷新(窗口存在时每秒重画日期/时钟/倒计时)
LockOverlay.update(this@TimerService)
handler.postDelayed(this, 1000L) handler.postDelayed(this, 1000L)
} }
} }
@@ -60,8 +62,8 @@ class TimerService : Service() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
TimerCore.addListener(onStateChanged) TimerCore.addListener(onStateChanged)
// 锁屏全屏倒计时:计时中亮屏(用户按电源键偷看)→ 发全屏意图把 // 锁屏倒计时主链路:悬浮窗(WindowManager 直接画在锁屏上,
// LockScreenActivity 盖在锁屏上;灭屏时撤回触发通知,不在抽屉里堆垃圾 // 不受"后台弹出界面"限制);灭屏/亮屏/解锁三个时机同步显隐
ContextCompat.registerReceiver( ContextCompat.registerReceiver(
this, this,
screenReceiver, screenReceiver,
@@ -71,6 +73,13 @@ class TimerService : Service() {
}, },
ContextCompat.RECEIVER_NOT_EXPORTED, ContextCompat.RECEIVER_NOT_EXPORTED,
) )
// 用户解锁(输密码/指纹进入系统)后悬浮窗没有存在意义,立即关闭
ContextCompat.registerReceiver(
this,
unlockReceiver,
IntentFilter(Intent.ACTION_USER_PRESENT),
ContextCompat.RECEIVER_NOT_EXPORTED,
)
} }
private val screenReceiver = object : BroadcastReceiver() { private val screenReceiver = object : BroadcastReceiver() {
@@ -82,49 +91,77 @@ class TimerService : Service() {
} }
} }
private val unlockReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_USER_PRESENT) {
LockOverlay.hide()
Notif.cancelFullscreen(this@TimerService)
}
}
}
/** /**
* 灭屏瞬间投递全屏意图通知——这是鸿蒙唯一会直接拉起 LockScreenActivity 的窗口。 * 悬浮窗显隐的总开关:锁屏中 + 计时未清零 + 开关打开 + 有悬浮窗权限。
* 鸿蒙 4.0 的规则:全屏意图只在「锁屏 + 灭屏」时投递才直接把页面盖在锁屏上; * 显示成功时顺手清掉抽屉里的全屏意图触发通知(不再需要)。
* 亮屏后投递永远只出横幅;服务直接 startActivity 则被"后台弹出界面"策略静默拦截
* (实测开了权限也一样)。所以改成灭屏时就投递:页面(turnScreenOn=false)
* 悄悄盖在锁屏底下、屏幕保持熄灭,用户按电源键亮屏就直接看到倒计时,
* 不会再出现任何通知横幅。
*/ */
private fun onScreenOff() { private fun syncLockOverlay() {
if (!Prefs.lockFullscreen || !TimerCore.running) return
TimerCore.tick() // 灭屏一瞬先补结算,避免到点边界上拉出 00:00 的空页面
if (!TimerCore.running) return
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
if (!km.isKeyguardLocked()) return val want = Prefs.lockFullscreen
Notif.updateFullscreen(this) && LockOverlay.canShow(this)
&& km.isKeyguardLocked()
&& (TimerCore.running || TimerCore.displayNow() > 0)
if (want) LockOverlay.show(this) else LockOverlay.hide()
if (LockOverlay.isShowing()) Notif.cancelFullscreen(this)
}
/** 灭屏:先补结算,悬浮窗可用就直接盖到锁屏上(保持熄屏,按电源键即见);不可用走全屏意图兜底 */
private fun onScreenOff() {
TimerCore.tick() // 灭屏一瞬先补结算,避免到点边界上拉出 00:00 的空页面
if (!Prefs.lockFullscreen || !TimerCore.running) return
syncLockOverlay()
if (LockOverlay.isShowing()) return
// 无悬浮窗权限的兜底:灭屏投递全屏意图(个别 ROM 直启,其余进抽屉可点)
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
if (km.isKeyguardLocked()) Notif.updateFullscreen(this)
} }
/** 亮屏:先补结算(冻结进程的到点闹钟被推迟时,靠这一下止损,不再滚负数) */ /** 亮屏:先补结算(冻结进程的到点闹钟被推迟时,靠这一下止损,不再滚负数) */
private fun onScreenOn() { private fun onScreenOn() {
TimerCore.tick() TimerCore.tick()
if (LockScreenActivity.showing) { syncLockOverlay()
// 页面已经盖在锁屏上(灭屏投递拉起的),抽屉里的触发通知清掉 // 悬浮窗已盖住锁屏时,仍尝试用沉浸式锁屏页接管——
Notif.cancelFullscreen(this) // Activity 有主题级全屏(状态栏彻底遮掉)+ 横竖屏专属排版,
} else if (Prefs.lockFullscreen && TimerCore.running) { // 直启成功则显示效果更完整;被鸿蒙拦截也无损失,悬浮窗继续顶着
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()) {
// 灭屏投递没拉起来(个别 ROM 拦全屏意图)的兜底:
// 先试服务直启,再留一条全屏意图通知让用户点进同一页面
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 = {
Notif.updateOngoing(this) Notif.updateOngoing(this)
// 计时结束/暂停时清掉锁屏触发通知,抽屉里不留垃圾 // 计时结束/暂停时清掉锁屏触发通知,抽屉里不留垃圾
if (!TimerCore.running) Notif.cancelFullscreen(this) if (!TimerCore.running) Notif.cancelFullscreen(this)
syncLockOverlay()
syncTicker() syncTicker()
syncWakeLock() syncWakeLock()
} }
@@ -236,7 +273,9 @@ class TimerService : Service() {
override fun onDestroy() { override fun onDestroy() {
stopTicker() stopTicker()
releaseWakeLock() releaseWakeLock()
LockOverlay.hide()
runCatching { unregisterReceiver(screenReceiver) } runCatching { unregisterReceiver(screenReceiver) }
runCatching { unregisterReceiver(unlockReceiver) }
Notif.cancelFullscreen(this) Notif.cancelFullscreen(this)
TimerCore.removeListener(onStateChanged) TimerCore.removeListener(onStateChanged)
super.onDestroy() super.onDestroy()

View File

@@ -156,11 +156,6 @@ 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)
// 工作中/休息中提示只有竖屏布局有(横屏排版里删掉了),横屏下 findViewById 返回 null
findViewById<TextView>(R.id.tvLockMode)?.text = getString(
if (TimerCore.mode == TimerCore.MODE_FOCUS) R.string.lock_mode_focus else R.string.lock_mode_break
)
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)
} }

View File

@@ -94,7 +94,17 @@ 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 后台启动,悬浮窗不受限)。
// 已授权时既没有右侧箭头也不可点——权限本身没有应用内开关,免得误以为能点进去设置
run {
val granted = com.focusbox.app.service.LockOverlay.canShow(requireContext())
if (granted) {
action(getString(R.string.overlay_perm_title), getString(R.string.perm_granted), showArrow = false)
} else {
action(getString(R.string.overlay_perm_title), getString(R.string.go_set)) { openOverlayPerm() }
}
},
// 华为/鸿蒙默认拦截后台拉起页面,无悬浮窗权限时的 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() },
) )
@@ -104,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()
@@ -175,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
@@ -196,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
@@ -237,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
@@ -259,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
} }
@@ -319,6 +341,92 @@ 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 和授权页,一键直达本应用 */
private fun openOverlayPerm() {
val ctx = requireContext()
if (com.focusbox.app.service.LockOverlay.canShow(ctx)) return
runCatching {
startActivity(
android.content.Intent(
android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
android.net.Uri.parse("package:${ctx.packageName}"),
).addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)
)
}
}
/** 锁屏显示权限:弹说明后直达华为「应用启动管理」,非华为/直达失败退回应用详情页 */ /** 锁屏显示权限:弹说明后直达华为「应用启动管理」,非华为/直达失败退回应用详情页 */
private fun openLockPerm() { private fun openLockPerm() {
val ctx = requireContext() val ctx = requireContext()
@@ -431,6 +539,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
} }
companion object { companion object {
const val VERSION = "1.2" const val VERSION = "1.6"
} }
} }

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,23 +116,26 @@ 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 tvTitle.text = title
tvTitle.paintFlags = if (task.done) { // 完成横线只画任务名本身(StrikethroughSpan 限定区间),
tvTitle.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG // 后面的重要度/紧急度/置顶图标不跟着划线
} else { tvTitle.paintFlags = tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() if (task.done) {
title.setSpan(
android.text.style.StrikethroughSpan(),
0, task.title.length, 0,
)
} }
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 +206,53 @@ class TaskAdapter(
private const val TYPE_FOOTER = 1 private const val TYPE_FOOTER = 1
} }
} }
/**
* 置顶图标:圆圈内向上箭头。
* 自绘而不是用字体字形——常用字体里没有"圆圈+箭头"的组合字符,
* 画出来才能精确控制圆圈与箭头同色、且和重要度圆圈数字(0.85 倍字号)等高。
*/
private class PinIconSpan(
private val color: 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
val p = Paint(Paint.ANTI_ALIAS_FLAG).apply {
this.color = color
style = Paint.Style.STROKE
strokeWidth = s / 8f
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

@@ -28,19 +28,19 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:includeFontPadding="false" android:includeFontPadding="false"
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="96sp" android:textSize="130sp"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
android:id="@+id/tvLockTask" android:id="@+id/tvLockTask"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="10dp"
android:ellipsize="end" android:ellipsize="end"
android:maxWidth="320dp" android:maxWidth="320dp"
android:maxLines="1" android:maxLines="1"
android:textColor="#CCFFFFFF" android:textColor="#99FFFFFF"
android:textSize="17sp" /> android:textSize="15sp" />
</LinearLayout> </LinearLayout>
<!-- 中:细分隔线 --> <!-- 中:细分隔线 -->
@@ -63,15 +63,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:includeFontPadding="false" android:includeFontPadding="false"
android:textColor="#FFFFFF" android:textColor="#FFFFFF"
android:textSize="96sp" android:textSize="130sp"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
android:id="@+id/tvLockDate" android:id="@+id/tvLockDate"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="10dp"
android:letterSpacing="0.08"
android:textColor="#99FFFFFF" android:textColor="#99FFFFFF"
android:textSize="15sp" /> android:textSize="15sp" />
</LinearLayout> </LinearLayout>

View File

@@ -38,15 +38,6 @@
android:textSize="96sp" android:textSize="96sp"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView
android:id="@+id/tvLockMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:letterSpacing="0.2"
android:textColor="#66FFFFFF"
android:textSize="13sp" />
<TextView <TextView
android:id="@+id/tvLockTask" android:id="@+id/tvLockTask"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -190,6 +190,8 @@
<string name="lock_fullscreen_title">锁屏全屏倒计时</string> <string name="lock_fullscreen_title">锁屏全屏倒计时</string>
<string name="lock_perm_title">锁屏显示权限</string> <string name="lock_perm_title">锁屏显示权限</string>
<string name="lock_perm_value">去开启</string> <string name="lock_perm_value">去开启</string>
<string name="overlay_perm_title">悬浮窗权限(锁屏显示)</string>
<string name="perm_granted">已开启</string>
<string name="go_set">去设置</string> <string name="go_set">去设置</string>
<string name="project_sort_index">排序序号</string> <string name="project_sort_index">排序序号</string>
<string name="sort_index_hint">序号,越小越靠前</string> <string name="sort_index_hint">序号,越小越靠前</string>