新增状态栏日期功能

This commit is contained in:
LittleTurtle2333
2022-02-22 22:52:03 +08:00
parent bfe67dc5b4
commit 58bb21884f
3 changed files with 161 additions and 58 deletions

View File

@@ -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(

View File

@@ -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 ""
}
}

View File

@@ -43,7 +43,7 @@
<string name="issues_url">点击查看GitHub Issues</string>
<string name="xposeddescription">基于 MIUI13(Android 12) 适配的自定义工具</string>
<string name="statusbar">状态栏(重启作用域生效)</string>
<string name="status_bar_time_seconds">时钟显秒</string>
<string name="status_bar_time_seconds">显示秒数</string>
<string name="status_bar_network_speed_refresh_speed">网速秒刷新</string>
<string name="remove_the_maximum_number_of_notification_icons">解除通知图标个数上限</string>
<string name="main_switch">总开关</string>
@@ -57,5 +57,11 @@
<string name="HideLauncherIcon">隐藏桌面图标</string>
<string name="hide_battery_percentage_icon">隐藏电量(%</string>
<string name="hide_battery_icon">隐藏 电池 图标</string>
<string name="status_bar_clock_format">状态栏时钟格式</string>
<string name="status_bar_time_year">显示年份</string>
<string name="status_bar_time_month">显示月份</string>
<string name="status_bar_time_day">显示日期</string>
<string name="status_bar_time_week">显示星期</string>
<string name="status_bar_time_hide_space">隐藏间隔</string>
</resources>