From 58bb21884fd1282ccc36f3e3bdad77ff68185017 Mon Sep 17 00:00:00 2001
From: LittleTurtle2333 <841474544@qq.com>
Date: Tue, 22 Feb 2022 22:52:03 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=8A=B6=E6=80=81=E6=A0=8F?=
=?UTF-8?q?=E6=97=A5=E6=9C=9F=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../activity/SettingsActivity.kt | 44 ++++-
.../hook/app/systemui/StatusBarTimeSeconds.kt | 167 ++++++++++++------
app/src/main/res/values/strings.xml | 8 +-
3 files changed, 161 insertions(+), 58 deletions(-)
diff --git a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt
index fb922cfd..592a35d5 100644
--- a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt
+++ b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt
@@ -82,12 +82,6 @@ class SettingsActivity : MIUIActivity() {
)
add(LineV())
add(TitleTextV(resId = R.string.statusbar))
- add(
- TextWithSwitchV(
- TextV(resId = R.string.status_bar_time_seconds),
- SwitchV("status_bar_time_seconds")
- )
- )
add(
TextWithSwitchV(
TextV(resId = R.string.status_bar_network_speed_refresh_speed),
@@ -113,6 +107,44 @@ class SettingsActivity : MIUIActivity() {
)
)
add(LineV())
+ add(TitleTextV(resId = R.string.status_bar_clock_format))
+ add(
+ TextWithSwitchV(
+ TextV(resId = R.string.status_bar_time_year),
+ SwitchV("status_bar_time_year")
+ )
+ )
+ add(
+ TextWithSwitchV(
+ TextV(resId = R.string.status_bar_time_month),
+ SwitchV("status_bar_time_month")
+ )
+ )
+ add(
+ TextWithSwitchV(
+ TextV(resId = R.string.status_bar_time_day),
+ SwitchV("status_bar_time_day")
+ )
+ )
+ add(
+ TextWithSwitchV(
+ TextV(resId = R.string.status_bar_time_week),
+ SwitchV("status_bar_time_week")
+ )
+ )
+ add(
+ TextWithSwitchV(
+ TextV(resId = R.string.status_bar_time_seconds),
+ SwitchV("status_bar_time_seconds")
+ )
+ )
+ add(
+ TextWithSwitchV(
+ TextV(resId = R.string.status_bar_time_hide_space),
+ SwitchV("status_bar_time_hide_space")
+ )
+ )
+ add(LineV())
add(TitleTextV(resId = R.string.status_bar_icon))
add(
TextWithSwitchV(
diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeSeconds.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeSeconds.kt
index f85bcf83..428a7fe4 100644
--- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeSeconds.kt
+++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeSeconds.kt
@@ -15,62 +15,127 @@ import java.lang.reflect.Method
import java.text.SimpleDateFormat
import java.util.*
-class StatusBarTimeSeconds :IXposedHookLoadPackage {
+class StatusBarTimeSeconds : IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
- if (XSPUtils.getBoolean("status_bar_time_seconds", false)) {
- var c: Context? = null
- val classIfExists = XposedHelpers.findClassIfExists(
- "com.android.systemui.statusbar.views.MiuiClock",
- lpparam.classLoader
- )
- XposedHelpers.findAndHookConstructor(classIfExists,
- Context::class.java,
- AttributeSet::class.java,
- Integer.TYPE,
- object : XC_MethodHook() {
- override fun afterHookedMethod(param: MethodHookParam) {
- c = param.args[0] as Context
- val textV = param.thisObject as TextView
- val d: Method = textV.javaClass.getDeclaredMethod("updateTime")
- val r = Runnable {
- d.isAccessible = true
- d.invoke(textV)
- }
- class T : TimerTask() {
- override fun run() {
- Handler(textV.context.mainLooper).post(r)
- }
+ var c: Context? = null
+ val classIfExists = XposedHelpers.findClassIfExists(
+ "com.android.systemui.statusbar.views.MiuiClock",
+ lpparam.classLoader
+ )
+ XposedHelpers.findAndHookConstructor(classIfExists,
+ Context::class.java,
+ AttributeSet::class.java,
+ Integer.TYPE,
+ object : XC_MethodHook() {
+ override fun afterHookedMethod(param: MethodHookParam) {
+ c = param.args[0] as Context
+ val textV = param.thisObject as TextView
+ val d: Method = textV.javaClass.getDeclaredMethod("updateTime")
+ val r = Runnable {
+ d.isAccessible = true
+ d.invoke(textV)
+ }
+
+ class T : TimerTask() {
+ override fun run() {
+ Handler(textV.context.mainLooper).post(r)
}
- if (textV.resources.getResourceEntryName(textV.id) == "clock")
- Timer().scheduleAtFixedRate(
- T(),
- 1000 - System.currentTimeMillis() % 1000,
- 1000
- )
+ }
+ if (textV.resources.getResourceEntryName(textV.id) == "clock")
+ Timer().scheduleAtFixedRate(
+ T(),
+ 1000 - System.currentTimeMillis() % 1000,
+ 1000
+ )
+ }
+ }
+ )
+ XposedHelpers.findAndHookMethod(classIfExists, "updateTime",
+ object : XC_MethodHook() {
+ @SuppressLint("SetTextI18n", "SimpleDateFormat")
+ override fun afterHookedMethod(param: MethodHookParam) {
+ val textV = param.thisObject as TextView
+ if (textV.resources.getResourceEntryName(textV.id) == "clock") {
+ val t = Settings.System.getString(
+ c!!.contentResolver,
+ Settings.System.TIME_12_24
+ )
+ if (t == "24")
+ textV.text =
+ getYear() + getMonth() + getDay() + getDateSpace() + getWeek() + SimpleDateFormat(
+ "HH:mm"
+ ).format(Calendar.getInstance().time)+getSecond()
+ else
+ textV.text =
+ getYear() + getMonth() + getDay() + getDateSpace() + getWeek() +textV.text.toString() + getSecond()
}
}
- )
- XposedHelpers.findAndHookMethod(classIfExists, "updateTime",
- object : XC_MethodHook() {
- @SuppressLint("SetTextI18n", "SimpleDateFormat")
- override fun afterHookedMethod(param: MethodHookParam) {
- val textV = param.thisObject as TextView
- if (textV.resources.getResourceEntryName(textV.id) == "clock") {
- val t = Settings.System.getString(
- c!!.contentResolver,
- Settings.System.TIME_12_24
- )
- if (t == "24")
- textV.text =
- SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().time)
- else
- textV.text =
- textV.text.toString() + SimpleDateFormat(":ss").format(Calendar.getInstance().time)
- }
- }
- })
+ })
+
- }
}
+
+ @SuppressLint("SimpleDateFormat")
+ private fun getYear(): String {
+ if (XSPUtils.getBoolean("status_bar_time_year", false)) {
+ return SimpleDateFormat("YY年").format(Calendar.getInstance().time)
+ }
+ return ""
+ }
+
+ @SuppressLint("SimpleDateFormat")
+ private fun getMonth(): String {
+ if (XSPUtils.getBoolean("status_bar_time_month", false)) {
+ return SimpleDateFormat("M月").format(Calendar.getInstance().time)
+ }
+ return ""
+ }
+
+ @SuppressLint("SimpleDateFormat")
+ private fun getDay(): String {
+ if (XSPUtils.getBoolean("status_bar_time_day", false)) {
+ return SimpleDateFormat("d日").format(Calendar.getInstance().time)
+ }
+ return ""
+ }
+
+ @SuppressLint("SimpleDateFormat")
+ private fun getSecond(): String {
+ if (XSPUtils.getBoolean("status_bar_time_seconds", false)) {
+ return SimpleDateFormat(":ss").format(Calendar.getInstance().time)
+ }
+ return ""
+ }
+
+ @SuppressLint("SimpleDateFormat")
+ private fun getWeek(): String {
+ var week = ""
+ if (XSPUtils.getBoolean("status_bar_time_week", false)) {
+ week = SimpleDateFormat("E").format(Calendar.getInstance().time)
+ if (XSPUtils.getBoolean("status_bar_time_hide_space", false)) {
+ week += ""
+ } else {
+ week += " "
+ }
+ }
+ return week
+ }
+
+ private fun getDateSpace(): String {
+ if (XSPUtils.getBoolean("status_bar_time_year", false) ||
+ XSPUtils.getBoolean("status_bar_time_month", false) ||
+ XSPUtils.getBoolean("status_bar_time_day", false)
+ ) {
+ if (XSPUtils.getBoolean("status_bar_time_hide_space", false)) {
+ return ""
+ } else {
+ return " "
+ }
+ }
+
+ return ""
+ }
+
+
}
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9b5efa5f..1d1f1973 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -43,7 +43,7 @@
点击查看GitHub Issues
基于 MIUI13(Android 12) 适配的自定义工具
状态栏(重启作用域生效)
- 时钟显秒
+ 显示秒数
网速秒刷新
解除通知图标个数上限
总开关
@@ -57,5 +57,11 @@
隐藏桌面图标
隐藏电量(%)
隐藏 电池 图标
+ 状态栏时钟格式
+ 显示年份
+ 显示月份
+ 显示日期
+ 显示星期
+ 隐藏间隔
\ No newline at end of file