新增状态栏日期功能

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(LineV())
add(TitleTextV(resId = R.string.statusbar)) add(TitleTextV(resId = R.string.statusbar))
add(
TextWithSwitchV(
TextV(resId = R.string.status_bar_time_seconds),
SwitchV("status_bar_time_seconds")
)
)
add( add(
TextWithSwitchV( TextWithSwitchV(
TextV(resId = R.string.status_bar_network_speed_refresh_speed), TextV(resId = R.string.status_bar_network_speed_refresh_speed),
@@ -113,6 +107,44 @@ class SettingsActivity : MIUIActivity() {
) )
) )
add(LineV()) 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(TitleTextV(resId = R.string.status_bar_icon))
add( add(
TextWithSwitchV( TextWithSwitchV(

View File

@@ -15,9 +15,9 @@ import java.lang.reflect.Method
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
class StatusBarTimeSeconds :IXposedHookLoadPackage { class StatusBarTimeSeconds : IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
if (XSPUtils.getBoolean("status_bar_time_seconds", false)) {
var c: Context? = null var c: Context? = null
val classIfExists = XposedHelpers.findClassIfExists( val classIfExists = XposedHelpers.findClassIfExists(
"com.android.systemui.statusbar.views.MiuiClock", "com.android.systemui.statusbar.views.MiuiClock",
@@ -63,14 +63,79 @@ class StatusBarTimeSeconds :IXposedHookLoadPackage {
) )
if (t == "24") if (t == "24")
textV.text = textV.text =
SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().time) getYear() + getMonth() + getDay() + getDateSpace() + getWeek() + SimpleDateFormat(
"HH:mm"
).format(Calendar.getInstance().time)+getSecond()
else else
textV.text = textV.text =
textV.text.toString() + SimpleDateFormat(":ss").format(Calendar.getInstance().time) getYear() + getMonth() + getDay() + getDateSpace() + getWeek() +textV.text.toString() + getSecond()
} }
} }
}) })
}
@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="issues_url">点击查看GitHub Issues</string>
<string name="xposeddescription">基于 MIUI13(Android 12) 适配的自定义工具</string> <string name="xposeddescription">基于 MIUI13(Android 12) 适配的自定义工具</string>
<string name="statusbar">状态栏(重启作用域生效)</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="status_bar_network_speed_refresh_speed">网速秒刷新</string>
<string name="remove_the_maximum_number_of_notification_icons">解除通知图标个数上限</string> <string name="remove_the_maximum_number_of_notification_icons">解除通知图标个数上限</string>
<string name="main_switch">总开关</string> <string name="main_switch">总开关</string>
@@ -57,5 +57,11 @@
<string name="HideLauncherIcon">隐藏桌面图标</string> <string name="HideLauncherIcon">隐藏桌面图标</string>
<string name="hide_battery_percentage_icon">隐藏电量(%</string> <string name="hide_battery_percentage_icon">隐藏电量(%</string>
<string name="hide_battery_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> </resources>