完成任务删除线只画任务名;置顶改圆圈箭头图标;饼图中心删小字居中;悬浮窗权限已开启不可点;每日目标可输入去上限,版本 1.6
This commit is contained in:
@@ -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.keep_screen_on), Prefs.keepScreenOn) { Prefs.keepScreenOn = 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)
|
||||
// 悬浮窗权限:锁屏倒计时主链路(鸿蒙拦 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 {
|
||||
getString(R.string.go_set)
|
||||
},
|
||||
) { openOverlayPerm() },
|
||||
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() },
|
||||
@@ -113,6 +114,8 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
stepper(
|
||||
getString(R.string.daily_goal),
|
||||
getString(R.string.value_minutes, Prefs.dailyGoalMinutes),
|
||||
// 数值支持直接点击输入;步进用于微调。Prefs 里没有上限
|
||||
onEdit = { inputDailyGoal() },
|
||||
) { delta ->
|
||||
Prefs.dailyGoalMinutes += delta * 15
|
||||
build()
|
||||
@@ -184,7 +187,8 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
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 row = LinearLayout(ctx).apply {
|
||||
orientation = LinearLayout.HORIZONTAL
|
||||
@@ -205,6 +209,7 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
gravity = Gravity.CENTER
|
||||
setTextColor(col(R.color.title))
|
||||
layoutParams = LinearLayout.LayoutParams(dpi(74f), LinearLayout.LayoutParams.WRAP_CONTENT)
|
||||
if (onEdit != null) setOnClickListener { onEdit() }
|
||||
})
|
||||
row.addView(stepButton("+") { onChange(1) })
|
||||
return row
|
||||
@@ -246,13 +251,19 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
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 row = LinearLayout(ctx).apply {
|
||||
orientation = LinearLayout.HORIZONTAL
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
minimumHeight = dpi(54f)
|
||||
setOnClickListener { onClick() }
|
||||
if (onClick != null) setOnClickListener { onClick() }
|
||||
}
|
||||
row.addView(TextView(ctx).apply {
|
||||
text = title
|
||||
@@ -268,11 +279,13 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
setPadding(0, 0, dpi(6f), 0)
|
||||
})
|
||||
}
|
||||
row.addView(android.widget.ImageView(ctx).apply {
|
||||
setImageResource(R.drawable.ic_chevron_right)
|
||||
tint(col(R.color.text_tertiary))
|
||||
layoutParams = LinearLayout.LayoutParams(dpi(15f), dpi(15f))
|
||||
})
|
||||
if (showArrow) {
|
||||
row.addView(android.widget.ImageView(ctx).apply {
|
||||
setImageResource(R.drawable.ic_chevron_right)
|
||||
tint(col(R.color.text_tertiary))
|
||||
layoutParams = LinearLayout.LayoutParams(dpi(15f), dpi(15f))
|
||||
})
|
||||
}
|
||||
return row
|
||||
}
|
||||
|
||||
@@ -328,6 +341,78 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
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()
|
||||
@@ -454,6 +539,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val VERSION = "1.5"
|
||||
const val VERSION = "1.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,8 +205,6 @@ class PeriodDistributionCard @JvmOverloads constructor(
|
||||
}
|
||||
)
|
||||
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)
|
||||
applySegments()
|
||||
|
||||
@@ -116,23 +116,26 @@ class TaskAdapter(
|
||||
)
|
||||
title.setSpan(RelativeSizeSpan(0.95f), title.length - stars.length, title.length, 0)
|
||||
|
||||
// 「随时」任务:标题后带品牌蓝上箭头表示置顶,列表里排在未完成最前面。
|
||||
// ↑ 字形窄、两侧留白大,全角空格会显得左边距比五角星宽,
|
||||
// 改用细空格(U+2009)让两侧间隙与星标一致。
|
||||
// 「随时」任务:标题后带品牌蓝圆圈上箭头表示置顶,列表里排在未完成最前面。
|
||||
// 图标与重要度圆圈数字同规格(0.85 倍字号,圆圈里画向上箭头),
|
||||
// 圆圈与箭头同色(品牌蓝);前面的细空格(U+2009)保持与星标的间距一致。
|
||||
if (task.repeatType == com.focusbox.app.model.Repeat.ANYTIME && !task.done) {
|
||||
title.append("\u2009↑")
|
||||
title.append("\u2009 ")
|
||||
title.setSpan(
|
||||
android.text.style.ForegroundColorSpan(ctx.col(R.color.brand)),
|
||||
title.length - 2, title.length, 0
|
||||
PinIconSpan(ctx.col(R.color.brand), tvTitle.textSize * 0.85f),
|
||||
title.length - 1, title.length, 0,
|
||||
)
|
||||
title.setSpan(RelativeSizeSpan(0.85f), title.length - 2, title.length, 0)
|
||||
}
|
||||
|
||||
tvTitle.text = title
|
||||
tvTitle.paintFlags = if (task.done) {
|
||||
tvTitle.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
|
||||
} else {
|
||||
tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
||||
// 完成横线只画任务名本身(StrikethroughSpan 限定区间),
|
||||
// 后面的重要度/紧急度/置顶图标不跟着划线
|
||||
tvTitle.paintFlags = 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.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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 置顶图标:圆圈内向上箭头。
|
||||
* 自绘而不是用字体字形——常用字体里没有"圆圈+箭头"的组合字符,
|
||||
* 画出来才能精确控制圆圈与箭头同色、且和重要度圆圈数字(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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user