Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5cd605a5c | ||
|
|
05a3462c6e | ||
|
|
c8cc773fef | ||
|
|
c0182de5e5 | ||
|
|
65dd5bfe91 | ||
|
|
fd674322a1 | ||
|
|
bc01e0ac67 |
43
CHANGELOG.md
43
CHANGELOG.md
@@ -1,8 +1,47 @@
|
|||||||
# 变更记录
|
# 变更记录
|
||||||
|
|
||||||
## 2026-11-29 · 锁屏权限引导:设置页新增锁屏显示权限入口一键跳应用启动管理,版本 1.0
|
## 2026-11-29 · 锁屏倒计时主链路改悬浮窗:WindowManager 直接画在锁屏上,不受"后台弹出界面"限制(v1.4)
|
||||||
|
|
||||||
- 同步源码更新 3 个文件(新增/修改 3,删除 0)。
|
- 根因链补全:鸿蒙 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)
|
||||||
|
|
||||||
|
- 项目排序模式:数据库 v6 → v7,projects 新增 sort_index(序号)与 pinned_at(置顶时间)两列,旧数据自动迁移(默认 0 = 不置顶/未设置)
|
||||||
|
- 列表排序规则:归档仍排最后 → 置顶项目排最前(多个置顶按置顶时间倒序,越近越靠前)→ 非置顶按序号升序(同序号按创建先后)
|
||||||
|
- 新增/编辑项目弹窗:序号输入框(数字,留空按 0)+ 置顶开关;已置顶再保存不刷新置顶时间,新勾置顶以保存时刻为准;归档/取消归档切换原样保留序号与置顶状态
|
||||||
|
- 横屏锁屏:主题加 windowFullscreen 强制全屏,横竖屏都彻底遮掉状态栏时间/信号/电池
|
||||||
|
- 横屏排版重排:左侧倒计时(96sp)+ 任务名,右侧时钟(96sp)+ 日期星期移到时钟下面,两侧主字号统一、左右对称;删除横屏「工作中/休息中」提示(竖屏保留)
|
||||||
|
- 版本 1.1 → 1.2(versionCode 36)
|
||||||
|
|
||||||
|
## 2026-11-29 · 锁屏倒计时改灭屏投递拉起不再出横幅;沉浸式遮状态栏;横屏专属排版;版本 1.1
|
||||||
|
|
||||||
|
- 同步源码更新 5 个文件(新增/修改 5,删除 0)。
|
||||||
|
|
||||||
|
## 2026-11-29 · 锁屏倒计时改灭屏投递拉起(不再出通知横幅);沉浸式遮状态栏;横屏专属排版(v1.1)
|
||||||
|
|
||||||
|
- 拉起流程重构:实测鸿蒙 4.0 即使开了"后台弹出界面"等全部权限,亮屏后服务 startActivity 仍被静默拦截,而全屏意图亮屏后投递只出横幅。改为**灭屏瞬间投递**全屏意图(鸿蒙只在"锁屏+灭屏"投递时才直接拉页):LockScreenActivity 悄悄盖在锁屏底下、屏幕保持熄灭(去掉 turnScreenOn 防止自动亮屏耗电),用户按电源键亮屏直接看到倒计时,全程无横幅
|
||||||
|
- TimerService:SCREEN_OFF → 灭屏投递;SCREEN_ON → 只补结算 + 清抽屉触发通知;页面未拉起时保留"服务直启 + 横幅通知"双兜底;计时停止时自动清触发通知
|
||||||
|
- LockScreenActivity:沉浸式全屏(IMMERSIVE_STICKY + LAYOUT_NO_LIMITS),顶部时间/信号/电池彻底遮掉;onWindowFocusChanged 重套沉浸式;监听 USER_PRESENT 解锁即退出;新增 showing 静态标记供服务判断页面是否已在锁屏上
|
||||||
|
- 横屏专属排版:新增 layout-land/activity_lock_screen.xml 左右分栏——左侧大号倒计时(120sp)+ 任务名,细竖线分隔,右侧信息栏纵向排日期/时钟/状态;清单去掉 configChanges 使旋转时重建切换布局,launchMode=singleTask 防重复实例
|
||||||
|
- 版本 1.0 → 1.1(versionCode 35)
|
||||||
|
|
||||||
|
## 2026-11-29 · 华为锁屏权限引导:设置页新增「锁屏显示权限」入口,一键跳应用启动管理(v1.0)
|
||||||
|
|
||||||
|
- 根因:鸿蒙/EMUI 默认拦截"后台弹出界面",前台服务直接 startActivity 被**静默**拦截(runCatching 不报错),只剩全屏意图通知——亮屏后投递只显示横幅,这就是"还是弹出通知"的真正原因。该权限无公开 API 可查询/授予,只能引导手动开启
|
||||||
|
- 设置页「提醒」区「锁屏全屏倒计时」开关下方新增「锁屏显示权限 · 去开启」入口:弹窗说明开启路径,点「去设置」直达华为手机管家应用启动管理页,失败退回系统应用详情页
|
||||||
|
- 新增 util/HuaweiPerms.kt;版本号规则调整为十进制进位:0.9 → 1.0,本次 0.17 → 1.0(versionCode 34)
|
||||||
|
|
||||||
## 2026-11-29 · 华为锁屏权限引导:设置页新增「锁屏显示权限」入口,一键跳应用启动管理(v1.0)
|
## 2026-11-29 · 华为锁屏权限引导:设置页新增「锁屏显示权限」入口,一键跳应用启动管理(v1.0)
|
||||||
|
|
||||||
|
|||||||
@@ -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" />
|
||||||
@@ -44,13 +46,12 @@
|
|||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.lockscreen.LockScreenActivity"
|
android:name=".ui.lockscreen.LockScreenActivity"
|
||||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
|
||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
android:launchMode="singleTask"
|
||||||
android:showWhenLocked="true"
|
android:showWhenLocked="true"
|
||||||
android:taskAffinity=""
|
android:taskAffinity=""
|
||||||
android:theme="@style/LockScreenTheme"
|
android:theme="@style/LockScreenTheme" />
|
||||||
android:turnScreenOn="true" />
|
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".service.TimerService"
|
android:name=".service.TimerService"
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ object Store {
|
|||||||
const val INBOX_ID = 1L
|
const val INBOX_ID = 1L
|
||||||
|
|
||||||
private const val DB_NAME = "focusbox.db"
|
private const val DB_NAME = "focusbox.db"
|
||||||
private const val DB_VERSION = 6
|
private const val DB_VERSION = 7
|
||||||
|
|
||||||
private lateinit var helper: Helper
|
private lateinit var helper: Helper
|
||||||
|
|
||||||
@@ -46,6 +46,8 @@ object Store {
|
|||||||
color INTEGER NOT NULL,
|
color INTEGER NOT NULL,
|
||||||
archived INTEGER NOT NULL DEFAULT 0,
|
archived INTEGER NOT NULL DEFAULT 0,
|
||||||
sort INTEGER NOT NULL DEFAULT 0,
|
sort INTEGER NOT NULL DEFAULT 0,
|
||||||
|
sort_index INTEGER NOT NULL DEFAULT 0,
|
||||||
|
pinned_at INTEGER NOT NULL DEFAULT 0,
|
||||||
created_at INTEGER NOT NULL
|
created_at INTEGER NOT NULL
|
||||||
)
|
)
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
@@ -125,6 +127,11 @@ object Store {
|
|||||||
if (oldVersion < 6) {
|
if (oldVersion < 6) {
|
||||||
db.execSQL("ALTER TABLE tasks ADD COLUMN urgency INTEGER NOT NULL DEFAULT 1")
|
db.execSQL("ALTER TABLE tasks ADD COLUMN urgency INTEGER NOT NULL DEFAULT 1")
|
||||||
}
|
}
|
||||||
|
// v6 → v7:项目排序模式——序号(非置顶按序号升序)+ 置顶时间(置顶排最前,越近越靠前)
|
||||||
|
if (oldVersion < 7) {
|
||||||
|
db.execSQL("ALTER TABLE projects ADD COLUMN sort_index INTEGER NOT NULL DEFAULT 0")
|
||||||
|
db.execSQL("ALTER TABLE projects ADD COLUMN pinned_at INTEGER NOT NULL DEFAULT 0")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,14 +139,17 @@ object Store {
|
|||||||
|
|
||||||
fun projects(includeArchived: Boolean = false): List<Project> {
|
fun projects(includeArchived: Boolean = false): List<Project> {
|
||||||
val sql = """
|
val sql = """
|
||||||
SELECT p._id, p.name, p.color, p.archived, p.sort,
|
SELECT p._id, p.name, p.color, p.archived, p.sort, p.sort_index, p.pinned_at,
|
||||||
(SELECT COUNT(*) FROM tasks t WHERE t.project_id = p._id AND t.done = 0) AS open_tasks,
|
(SELECT COUNT(*) FROM tasks t WHERE t.project_id = p._id AND t.done = 0) AS open_tasks,
|
||||||
(SELECT COUNT(*) FROM tasks t WHERE t.project_id = p._id AND t.done = 1) AS done_tasks,
|
(SELECT COUNT(*) FROM tasks t WHERE t.project_id = p._id AND t.done = 1) AS done_tasks,
|
||||||
(SELECT IFNULL(SUM(s.seconds), 0) FROM sessions s WHERE s.project_id = p._id) AS focus_sec,
|
(SELECT IFNULL(SUM(s.seconds), 0) FROM sessions s WHERE s.project_id = p._id) AS focus_sec,
|
||||||
(SELECT COUNT(*) FROM sessions s WHERE s.project_id = p._id AND s.completed = 1) AS pomos
|
(SELECT COUNT(*) FROM sessions s WHERE s.project_id = p._id AND s.completed = 1) AS pomos
|
||||||
FROM projects p
|
FROM projects p
|
||||||
WHERE p.archived = 0 OR ${if (includeArchived) 1 else 0} = 1
|
WHERE p.archived = 0 OR ${if (includeArchived) 1 else 0} = 1
|
||||||
ORDER BY p.archived ASC, p.sort ASC, p._id ASC
|
ORDER BY p.archived ASC,
|
||||||
|
CASE WHEN p.pinned_at > 0 THEN 1 ELSE 0 END DESC,
|
||||||
|
CASE WHEN p.pinned_at > 0 THEN p.pinned_at ELSE 0 END DESC,
|
||||||
|
p.sort_index ASC, p.sort ASC, p._id ASC
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
val list = ArrayList<Project>()
|
val list = ArrayList<Project>()
|
||||||
db.rawQuery(sql, null).use { c ->
|
db.rawQuery(sql, null).use { c ->
|
||||||
@@ -151,10 +161,12 @@ object Store {
|
|||||||
color = c.getInt(2),
|
color = c.getInt(2),
|
||||||
archived = c.getInt(3) == 1,
|
archived = c.getInt(3) == 1,
|
||||||
sort = c.getInt(4),
|
sort = c.getInt(4),
|
||||||
openTasks = c.getInt(5),
|
sortIndex = c.getInt(5),
|
||||||
doneTasks = c.getInt(6),
|
pinnedAt = c.getLong(6),
|
||||||
focusSeconds = c.getInt(7),
|
openTasks = c.getInt(7),
|
||||||
pomodoros = c.getInt(8),
|
doneTasks = c.getInt(8),
|
||||||
|
focusSeconds = c.getInt(9),
|
||||||
|
pomodoros = c.getInt(10),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -164,22 +176,34 @@ object Store {
|
|||||||
|
|
||||||
fun project(id: Long): Project? = projects(true).firstOrNull { it.id == id }
|
fun project(id: Long): Project? = projects(true).firstOrNull { it.id == id }
|
||||||
|
|
||||||
fun addProject(name: String, color: Int): Long {
|
fun addProject(name: String, color: Int, sortIndex: Int = 0, pinned: Boolean = false): Long {
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
val cv = ContentValues().apply {
|
val cv = ContentValues().apply {
|
||||||
put("name", name)
|
put("name", name)
|
||||||
put("color", color)
|
put("color", color)
|
||||||
put("archived", 0)
|
put("archived", 0)
|
||||||
put("sort", System.currentTimeMillis() / 1000)
|
put("sort", now / 1000)
|
||||||
put("created_at", System.currentTimeMillis())
|
put("sort_index", sortIndex)
|
||||||
|
put("pinned_at", if (pinned) now else 0L)
|
||||||
|
put("created_at", now)
|
||||||
}
|
}
|
||||||
return db.insert("projects", null, cv)
|
return db.insert("projects", null, cv)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateProject(id: Long, name: String, color: Int, archived: Boolean) {
|
/**
|
||||||
|
* pinnedAt 语义:pinned=true 且原值 0 → 取传入值(新建置顶时由调用方给 now);
|
||||||
|
* 已置顶保持置顶 → 保留原置顶时间(重复保存不刷新排序);取消置顶 → 归 0。
|
||||||
|
*/
|
||||||
|
fun updateProject(
|
||||||
|
id: Long, name: String, color: Int, archived: Boolean,
|
||||||
|
sortIndex: Int = 0, pinned: Boolean = false, pinnedAt: Long = 0,
|
||||||
|
) {
|
||||||
val cv = ContentValues().apply {
|
val cv = ContentValues().apply {
|
||||||
put("name", name)
|
put("name", name)
|
||||||
put("color", color)
|
put("color", color)
|
||||||
put("archived", if (archived) 1 else 0)
|
put("archived", if (archived) 1 else 0)
|
||||||
|
put("sort_index", sortIndex)
|
||||||
|
put("pinned_at", if (pinned) pinnedAt else 0L)
|
||||||
}
|
}
|
||||||
db.update("projects", cv, "_id = ?", arrayOf(id.toString()))
|
db.update("projects", cv, "_id = ?", arrayOf(id.toString()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ data class Project(
|
|||||||
val doneTasks: Int,
|
val doneTasks: Int,
|
||||||
val focusSeconds: Int,
|
val focusSeconds: Int,
|
||||||
val pomodoros: Int,
|
val pomodoros: Int,
|
||||||
|
/** 排序序号:非置顶项目按它升序排,数字越小越靠前 */
|
||||||
|
val sortIndex: Int = 0,
|
||||||
|
/** 置顶时间戳:0 未置顶;置顶项目排最前,多个置顶按它倒序(越近越靠前) */
|
||||||
|
val pinnedAt: Long = 0,
|
||||||
) {
|
) {
|
||||||
val totalTasks: Int get() = openTasks + doneTasks
|
val totalTasks: Int get() = openTasks + doneTasks
|
||||||
val progress: Float get() = if (totalTasks == 0) 0f else doneTasks.toFloat() / totalTasks
|
val progress: Float get() = if (totalTasks == 0) 0f else doneTasks.toFloat() / totalTasks
|
||||||
|
|||||||
129
src/main/java/com/focusbox/app/service/LockOverlay.kt
Normal file
129
src/main/java/com/focusbox/app/service/LockOverlay.kt
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
val lp = WindowManager.LayoutParams(
|
||||||
|
WindowManager.LayoutParams.MATCH_PARENT,
|
||||||
|
WindowManager.LayoutParams.MATCH_PARENT,
|
||||||
|
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.CENTER
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每秒刷新读数;横竖屏变化时重建窗口(悬浮窗不经过 Activity 重建,
|
||||||
|
* 只能自己检测 configuration 并换布局重新 inflate)。
|
||||||
|
*/
|
||||||
|
fun update(context: Context) {
|
||||||
|
val view = root ?: 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
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import android.os.IBinder
|
|||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.focusbox.app.ui.lockscreen.LockScreenActivity
|
||||||
import com.focusbox.app.util.Prefs
|
import com.focusbox.app.util.Prefs
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,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,
|
||||||
@@ -70,42 +73,86 @@ 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() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
Intent.ACTION_SCREEN_ON -> showLockPeek()
|
Intent.ACTION_SCREEN_ON -> onScreenOn()
|
||||||
Intent.ACTION_SCREEN_OFF -> Notif.cancelFullscreen(context)
|
Intent.ACTION_SCREEN_OFF -> onScreenOff()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showLockPeek() {
|
private val unlockReceiver = object : BroadcastReceiver() {
|
||||||
// 先补结算:EMUI 冻结进程后到点闹钟可能被推迟,用户按电源键亮屏
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
// 这一瞬进程已解冻,正好把过期的倒计时立刻结算掉,
|
if (intent.action == Intent.ACTION_USER_PRESENT) {
|
||||||
// 通知/锁屏卡片就不会再滚负数
|
LockOverlay.hide()
|
||||||
TimerCore.tick()
|
Notif.cancelFullscreen(this@TimerService)
|
||||||
if (!Prefs.lockFullscreen) return
|
}
|
||||||
if (!TimerCore.running) return
|
}
|
||||||
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
}
|
||||||
// 只有真在锁屏界面才拉全屏页;用户正在用手机时不打扰
|
|
||||||
if (!km.inKeyguardRestrictedInputMode()) return
|
/**
|
||||||
// 鸿蒙上全屏意图只在"锁屏且灭屏时投递"才会直接拉起 Activity,
|
* 悬浮窗显隐的总开关:锁屏中 + 计时未清零 + 开关打开 + 有悬浮窗权限。
|
||||||
// 亮屏后投递只会出横幅通知——所以直接从服务启动页面(鸿蒙允许
|
* 显示成功时顺手清掉抽屉里的全屏意图触发通知(不再需要)。
|
||||||
// 前台服务拉起自己的 Activity),全屏意图通知保留作兜底
|
*/
|
||||||
runCatching {
|
private fun syncLockOverlay() {
|
||||||
startActivity(
|
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||||
Intent(this, com.focusbox.app.ui.lockscreen.LockScreenActivity::class.java)
|
val want = Prefs.lockFullscreen
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
&& 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() {
|
||||||
|
TimerCore.tick()
|
||||||
|
syncLockOverlay()
|
||||||
|
if (LockOverlay.isShowing()) return
|
||||||
|
if (LockScreenActivity.showing) {
|
||||||
|
// 悬浮窗不可用但锁屏页已被全屏意图拉起,抽屉里的触发通知清掉
|
||||||
|
Notif.cancelFullscreen(this)
|
||||||
|
} else if (Prefs.lockFullscreen && TimerCore.running) {
|
||||||
|
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||||
|
if (km.isKeyguardLocked()) {
|
||||||
|
// 全兜底:先试服务直启,再留一条全屏意图通知让用户点进同一页面
|
||||||
|
runCatching {
|
||||||
|
startActivity(
|
||||||
|
Intent(this, LockScreenActivity::class.java)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Notif.updateFullscreen(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Notif.updateFullscreen(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val onStateChanged: () -> Unit = {
|
private val onStateChanged: () -> Unit = {
|
||||||
Notif.updateOngoing(this)
|
Notif.updateOngoing(this)
|
||||||
// 暂停/结束时同步停掉 1 秒轮询,别让 Handler 空转
|
// 计时结束/暂停时清掉锁屏触发通知,抽屉里不留垃圾
|
||||||
|
if (!TimerCore.running) Notif.cancelFullscreen(this)
|
||||||
|
syncLockOverlay()
|
||||||
syncTicker()
|
syncTicker()
|
||||||
syncWakeLock()
|
syncWakeLock()
|
||||||
}
|
}
|
||||||
@@ -217,7 +264,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()
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
package com.focusbox.app.ui.lockscreen
|
package com.focusbox.app.ui.lockscreen
|
||||||
|
|
||||||
import android.app.KeyguardManager
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.IntentFilter
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.text.format.DateFormat
|
import android.text.format.DateFormat
|
||||||
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import com.focusbox.app.R
|
import com.focusbox.app.R
|
||||||
import com.focusbox.app.data.Store
|
import com.focusbox.app.data.Store
|
||||||
|
import com.focusbox.app.service.Notif
|
||||||
import com.focusbox.app.service.TimerCore
|
import com.focusbox.app.service.TimerCore
|
||||||
import com.focusbox.app.util.Dates
|
import com.focusbox.app.util.Dates
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@@ -20,21 +26,31 @@ import java.util.Locale
|
|||||||
/**
|
/**
|
||||||
* 锁屏全屏倒计时页。
|
* 锁屏全屏倒计时页。
|
||||||
*
|
*
|
||||||
* 触发链路:计时中按电源键亮屏 → TimerService 收到 SCREEN_ON →
|
* 触发链路:计时中用户锁屏(灭屏)→ TimerService 灭屏瞬间发全屏意图通知 →
|
||||||
* 检查处于锁屏后发一条全屏意图通知 → 系统把本页直接盖在锁屏上展示。
|
* 鸿蒙直接把本页盖在锁屏上(屏幕保持熄灭,本页不设 turnScreenOn)→
|
||||||
|
* 用户按电源键亮屏即见倒计时,全程不出通知横幅。
|
||||||
*
|
*
|
||||||
* 交互极简:黑底上只有日期、时钟、大号倒计时和任务名,
|
* 交互极简:黑底上只有日期、时钟、大号倒计时和任务名,
|
||||||
* 点按任意处退出;倒计时本身在前台服务里走,退出/熄屏都不受影响,
|
* 点按任意处退出、解锁时自动退出;倒计时本身在前台服务里走,
|
||||||
* 计时结束后本页在下一次刷新时自动关闭。
|
* 退出/熄屏都不受影响,计时结束后本页在下一次刷新时自动关闭。
|
||||||
|
*
|
||||||
|
* 沉浸式:STATUS_BAR_HIDDEN + LAYOUT_NO_LIMITS 把顶部的时间/信号/电池
|
||||||
|
* 一起遮掉,整块屏幕只有页面内容。
|
||||||
*/
|
*/
|
||||||
class LockScreenActivity : AppCompatActivity() {
|
class LockScreenActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/** 服务用来判断页面是否已盖在锁屏上(避免重复拉起/多报通知) */
|
||||||
|
@Volatile
|
||||||
|
var showing: Boolean = false
|
||||||
|
private set
|
||||||
|
}
|
||||||
|
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
private lateinit var tvDate: TextView
|
private lateinit var tvDate: TextView
|
||||||
private lateinit var tvClock: TextView
|
private lateinit var tvClock: TextView
|
||||||
private lateinit var tvCountdown: TextView
|
private lateinit var tvCountdown: TextView
|
||||||
private lateinit var tvMode: TextView
|
|
||||||
private lateinit var tvTask: TextView
|
private lateinit var tvTask: TextView
|
||||||
|
|
||||||
private val clockFmt = SimpleDateFormat("HH:mm", Locale.getDefault())
|
private val clockFmt = SimpleDateFormat("HH:mm", Locale.getDefault())
|
||||||
@@ -46,40 +62,87 @@ class LockScreenActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 用户解锁(输密码/指纹进系统)后页面没有存在意义,立即退出 */
|
||||||
|
private val unlockReceiver = object : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
if (intent.action == Intent.ACTION_USER_PRESENT) finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
// 盖在锁屏上显示(API 27+ 用官方方法,清单里的 showWhenLocked/turnScreenOn 双保险)
|
// 盖在锁屏上显示(API 27+ 用官方方法,清单里的 showWhenLocked 双保险)。
|
||||||
|
// 注意不能开 turnScreenOn:灭屏投递拉起本页时屏幕要保持熄灭,
|
||||||
|
// 等用户按电源键才亮,否则每次锁屏都会自动亮屏耗电
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
||||||
setShowWhenLocked(true)
|
setShowWhenLocked(true)
|
||||||
setTurnScreenOn(true)
|
|
||||||
} else {
|
} else {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
window.addFlags(
|
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
|
||||||
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
|
||||||
or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
setContentView(R.layout.activity_lock_screen)
|
setContentView(R.layout.activity_lock_screen)
|
||||||
|
|
||||||
tvDate = findViewById(R.id.tvLockDate)
|
tvDate = findViewById(R.id.tvLockDate)
|
||||||
tvClock = findViewById(R.id.tvLockClock)
|
tvClock = findViewById(R.id.tvLockClock)
|
||||||
tvCountdown = findViewById(R.id.tvLockCountdown)
|
tvCountdown = findViewById(R.id.tvLockCountdown)
|
||||||
tvMode = findViewById(R.id.tvLockMode)
|
|
||||||
tvTask = findViewById(R.id.tvLockTask)
|
tvTask = findViewById(R.id.tvLockTask)
|
||||||
|
|
||||||
findViewById<android.view.View>(R.id.lockRoot).setOnClickListener { finish() }
|
findViewById<View>(R.id.lockRoot).setOnClickListener { finish() }
|
||||||
|
|
||||||
|
applyImmersive()
|
||||||
|
|
||||||
|
ContextCompat.registerReceiver(
|
||||||
|
this,
|
||||||
|
unlockReceiver,
|
||||||
|
IntentFilter(Intent.ACTION_USER_PRESENT),
|
||||||
|
ContextCompat.RECEIVER_NOT_EXPORTED,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
showing = true
|
||||||
|
// 页面已经实际盖到锁屏上了,抽屉里那条触发通知清掉
|
||||||
|
Notif.cancelFullscreen(this)
|
||||||
|
applyImmersive()
|
||||||
handler.post(tick)
|
handler.post(tick)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
|
showing = false
|
||||||
handler.removeCallbacks(tick)
|
handler.removeCallbacks(tick)
|
||||||
super.onStop()
|
super.onStop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
runCatching { unregisterReceiver(unlockReceiver) }
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 沉浸式全屏:状态栏/导航栏全隐藏,且布局延伸到状态栏底下(时间信号电池彻底不见) */
|
||||||
|
private fun applyImmersive() {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
window.setFlags(
|
||||||
|
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
|
||||||
|
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
|
||||||
|
)
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
window.decorView.systemUiVisibility = (
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
|
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
|
or View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||||
|
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 从别的窗口/通知横幅抢回焦点后,沉浸式标记会被系统清掉,重新套一遍 */
|
||||||
|
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||||
|
super.onWindowFocusChanged(hasFocus)
|
||||||
|
if (hasFocus) applyImmersive()
|
||||||
|
}
|
||||||
|
|
||||||
private fun render() {
|
private fun render() {
|
||||||
val now = TimerCore.displayNow()
|
val now = TimerCore.displayNow()
|
||||||
// 计时已结束且没有剩余读数:页面使命完成,自动关闭
|
// 计时已结束且没有剩余读数:页面使命完成,自动关闭
|
||||||
@@ -93,10 +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)
|
||||||
|
|
||||||
tvMode.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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ class ProjectSheet(
|
|||||||
|
|
||||||
private val root = LayoutInflater.from(context).inflate(R.layout.sheet_project, null)
|
private val root = LayoutInflater.from(context).inflate(R.layout.sheet_project, null)
|
||||||
private val etName: EditText = root.findViewById(R.id.etName)
|
private val etName: EditText = root.findViewById(R.id.etName)
|
||||||
|
private val etSortIndex: EditText = root.findViewById(R.id.etSortIndex)
|
||||||
|
private val swPinned: androidx.appcompat.widget.SwitchCompat = root.findViewById(R.id.swPinned)
|
||||||
private val colorRow: LinearLayout = root.findViewById(R.id.colorRow)
|
private val colorRow: LinearLayout = root.findViewById(R.id.colorRow)
|
||||||
|
|
||||||
private var color: Int = existing?.color ?: Palette.colorAt(0)
|
private var color: Int = existing?.color ?: Palette.colorAt(0)
|
||||||
@@ -38,6 +40,11 @@ class ProjectSheet(
|
|||||||
if (existing == null) R.string.add_project else R.string.edit
|
if (existing == null) R.string.add_project else R.string.edit
|
||||||
)
|
)
|
||||||
etName.setText(existing?.name ?: "")
|
etName.setText(existing?.name ?: "")
|
||||||
|
// 编辑已有序号才回填;未设置过序号显示空,保存时按 0 处理(同级按创建先后排)
|
||||||
|
if (existing != null && existing.sortIndex > 0) {
|
||||||
|
etSortIndex.setText(existing.sortIndex.toString())
|
||||||
|
}
|
||||||
|
swPinned.isChecked = (existing?.pinnedAt ?: 0L) > 0L
|
||||||
renderColors()
|
renderColors()
|
||||||
|
|
||||||
val btnDelete = root.findViewById<TextView>(R.id.btnDelete)
|
val btnDelete = root.findViewById<TextView>(R.id.btnDelete)
|
||||||
@@ -62,10 +69,20 @@ class ProjectSheet(
|
|||||||
etName.error = context.getString(R.string.project_name_hint)
|
etName.error = context.getString(R.string.project_name_hint)
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
val sortIndex = etSortIndex.text.toString().trim().toIntOrNull() ?: 0
|
||||||
|
val pinned = swPinned.isChecked
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
Store.addProject(name, color)
|
// 新建置顶:置顶时间取当下,排进置顶组
|
||||||
|
Store.addProject(name, color, sortIndex, pinned)
|
||||||
} else {
|
} else {
|
||||||
Store.updateProject(existing.id, name, color, existing.archived)
|
// 已置顶且保持置顶 → 保留原置顶时间(重复保存不刷新排序);
|
||||||
|
// 新勾置顶 → 以保存这一刻为置顶时间;取消置顶 → Store 里归 0
|
||||||
|
val pinnedAt = when {
|
||||||
|
!pinned -> 0L
|
||||||
|
existing.pinnedAt > 0L -> existing.pinnedAt
|
||||||
|
else -> System.currentTimeMillis()
|
||||||
|
}
|
||||||
|
Store.updateProject(existing.id, name, color, existing.archived, sortIndex, pinned, pinnedAt)
|
||||||
}
|
}
|
||||||
onSaved()
|
onSaved()
|
||||||
dismiss()
|
dismiss()
|
||||||
|
|||||||
@@ -128,7 +128,11 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
|||||||
when {
|
when {
|
||||||
which == 0 -> ProjectSheet(requireContext(), p) { reload() }.show()
|
which == 0 -> ProjectSheet(requireContext(), p) { reload() }.show()
|
||||||
which == 1 && !isInbox -> {
|
which == 1 && !isInbox -> {
|
||||||
Store.updateProject(p.id, p.name, p.color, !p.archived)
|
// 归档/取消归档只切 archived,序号与置顶状态原样保留
|
||||||
|
Store.updateProject(
|
||||||
|
p.id, p.name, p.color, !p.archived,
|
||||||
|
p.sortIndex, p.pinnedAt > 0, p.pinnedAt,
|
||||||
|
)
|
||||||
reload()
|
reload()
|
||||||
}
|
}
|
||||||
which == 2 && !isInbox -> confirmDelete(p)
|
which == 2 && !isInbox -> confirmDelete(p)
|
||||||
|
|||||||
@@ -94,7 +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 后台启动,悬浮窗不受限)
|
||||||
|
action(
|
||||||
|
getString(R.string.overlay_perm_title),
|
||||||
|
if (com.focusbox.app.service.LockOverlay.canShow(requireContext())) {
|
||||||
|
getString(R.string.perm_granted)
|
||||||
|
} else {
|
||||||
|
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() },
|
||||||
)
|
)
|
||||||
@@ -319,6 +328,20 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 悬浮窗权限:标准 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 +454,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val VERSION = "1.0"
|
const val VERSION = "1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
78
src/main/res/layout-land/activity_lock_screen.xml
Normal file
78
src/main/res/layout-land/activity_lock_screen.xml
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
锁屏全屏倒计时·横屏专属排版(区别于竖屏的纯纵向堆叠):
|
||||||
|
左右对称分栏 —— 左侧倒计时(大)+ 任务名,右侧时钟(大)+ 日期星期,
|
||||||
|
两侧主字号统一 96sp,视觉左右对应;无「工作中/休息中」提示。
|
||||||
|
-->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/lockRoot"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@android:color/black"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<!-- 左:倒计时 + 任务名 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvLockCountdown"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:includeFontPadding="false"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textSize="130sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvLockTask"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxWidth="320dp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="#99FFFFFF"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- 中:细分隔线 -->
|
||||||
|
<View
|
||||||
|
android:layout_width="1dp"
|
||||||
|
android:layout_height="180dp"
|
||||||
|
android:background="#26FFFFFF" />
|
||||||
|
|
||||||
|
<!-- 右:时钟(大)+ 日期星期在时钟下面 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvLockClock"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:includeFontPadding="false"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textSize="130sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvLockDate"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:textColor="#99FFFFFF"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -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"
|
||||||
|
|||||||
@@ -45,6 +45,45 @@
|
|||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
android:maxLines="1" />
|
android:maxLines="1" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="14dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etSortIndex"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_field"
|
||||||
|
android:paddingStart="14dp"
|
||||||
|
android:paddingEnd="14dp"
|
||||||
|
android:paddingTop="13dp"
|
||||||
|
android:paddingBottom="13dp"
|
||||||
|
android:hint="@string/sort_index_hint"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textColorHint="@color/text_tertiary"
|
||||||
|
android:textSize="15sp"
|
||||||
|
android:inputType="number"
|
||||||
|
android:maxLines="1" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:text="@string/project_pinned"
|
||||||
|
android:textSize="15sp"
|
||||||
|
android:textColor="@color/text" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
|
android:id="@+id/swPinned"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
@@ -190,7 +190,12 @@
|
|||||||
<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="sort_index_hint">序号,越小越靠前</string>
|
||||||
|
<string name="project_pinned">置顶</string>
|
||||||
<string name="lock_perm_hint">华为/鸿蒙默认拦截后台拉起页面,锁屏倒计时需要手动开启。路径:设置 → 应用 → 应用启动管理 → 时间简史 → 关闭「自动管理」,并允许「后台弹出界面」和「锁屏显示」。点「去设置」可直接打开对应页面。</string>
|
<string name="lock_perm_hint">华为/鸿蒙默认拦截后台拉起页面,锁屏倒计时需要手动开启。路径:设置 → 应用 → 应用启动管理 → 时间简史 → 关闭「自动管理」,并允许「后台弹出界面」和「锁屏显示」。点「去设置」可直接打开对应页面。</string>
|
||||||
<string name="lock_mode_focus">工作中</string>
|
<string name="lock_mode_focus">工作中</string>
|
||||||
<string name="lock_mode_break">休息中</string>
|
<string name="lock_mode_break">休息中</string>
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
<!-- 锁屏全屏倒计时页:纯黑底、白色字,不随深浅色主题切换 -->
|
<!-- 锁屏全屏倒计时页:纯黑底、白色字,不随深浅色主题切换 -->
|
||||||
<style name="LockScreenTheme" parent="Theme.AppCompat.NoActionBar">
|
<style name="LockScreenTheme" parent="Theme.AppCompat.NoActionBar">
|
||||||
<item name="android:windowBackground">@android:color/black</item>
|
<item name="android:windowBackground">@android:color/black</item>
|
||||||
|
<!-- 主题级全屏:横竖屏都把状态栏(时间/信号/电池)彻底拿掉,横屏同样生效 -->
|
||||||
|
<item name="android:windowFullscreen">true</item>
|
||||||
<item name="android:statusBarColor">@android:color/black</item>
|
<item name="android:statusBarColor">@android:color/black</item>
|
||||||
<item name="android:navigationBarColor">@android:color/black</item>
|
<item name="android:navigationBarColor">@android:color/black</item>
|
||||||
<item name="android:windowLightStatusBar">false</item>
|
<item name="android:windowLightStatusBar">false</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user