优化状态栏时钟功能

This commit is contained in:
乌堆小透明
2022-03-09 00:17:39 +08:00
parent c0e9c67d5e
commit 47948c4121
3 changed files with 112 additions and 100 deletions

File diff suppressed because one or more lines are too long

View File

@@ -18,11 +18,26 @@ import java.util.*
class StatusBarTimeCustomization : IXposedHookLoadPackage {
val isYear = XSPUtils.getBoolean("status_bar_time_year", false)
val isMonth = XSPUtils.getBoolean("status_bar_time_month", false)
val isDay = XSPUtils.getBoolean("status_bar_time_day", false)
val isWeek = XSPUtils.getBoolean("status_bar_time_week", false)
val isHideSpace = XSPUtils.getBoolean("status_bar_time_hide_space", false)
val isDoubleLine = XSPUtils.getBoolean("status_bar_time_double_line", false)
val isSecond = XSPUtils.getBoolean("status_bar_time_seconds", false)
val isDoubleHour = XSPUtils.getBoolean("status_bar_time_double_hour", false)
val isPeriod = XSPUtils.getBoolean("status_bar_time_period", true)
val getClockSize = XSPUtils.getInt("status_bar_clock_size", 0)
val isOpen = XSPUtils.getBoolean("custom_clock_switch", false)
val getClockDoubleSize = XSPUtils.getInt("status_bar_clock_double_line_size", 0)
var now_time: Date? = null
var str = ""
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
if (XSPUtils.getBoolean("custom_clock_switch", false)) {
if (isOpen) {
var c: Context? = null
val classIfExists = XposedHelpers.findClassIfExists(
"com.android.systemui.statusbar.views.MiuiClock",
@@ -39,12 +54,12 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage {
val textV = param.thisObject as TextView
textV.isSingleLine = false
if (XSPUtils.getBoolean("status_bar_time_double_line", false)) {
if (isDoubleLine) {
str = "\n"
var clock_double_line_size = 7F
if (XSPUtils.getInt("status_bar_clock_double_line_size", 0) != 0) {
if (getClockDoubleSize != 0) {
clock_double_line_size =
XSPUtils.getInt("status_bar_clock_double_line_size", 0)
getClockDoubleSize
.toFloat()
}
textV.setTextSize(
@@ -52,9 +67,9 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage {
clock_double_line_size
)
} else {
if (XSPUtils.getInt("status_bar_clock_size", 0) != 0) {
if (getClockSize != 0) {
val clock_size =
XSPUtils.getInt("status_bar_clock_size", 0).toFloat()
getClockSize.toFloat()
textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clock_size)
}
}
@@ -95,10 +110,7 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage {
)
now_time = Calendar.getInstance().time
textV.text =
getYear() + getMonth() + getDay() + getDateSpace() + getWeek() + str + getDoubleHour() + getTime(
t
) + getSecond()
textV.text = getDate(c!!, t) + str + getTime(c!!, t)
}
} catch (e: Exception) {
@@ -108,86 +120,100 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage {
}
}
@SuppressLint("SimpleDateFormat")
private fun getYear(): String {
if (XSPUtils.getBoolean("status_bar_time_year", false)) {
return SimpleDateFormat("YY年").format(now_time)
}
return ""
}
@SuppressLint("SimpleDateFormat")
private fun getMonth(): String {
if (XSPUtils.getBoolean("status_bar_time_month", false)) {
return SimpleDateFormat("M月").format(now_time)
}
return ""
}
private fun getDate(context: Context, t: String): String {
var DatePattern = ""
val isZh = isZh(context)
@SuppressLint("SimpleDateFormat")
private fun getDay(): String {
if (XSPUtils.getBoolean("status_bar_time_day", false)) {
return SimpleDateFormat("d日").format(now_time)
}
return ""
}
@SuppressLint("SimpleDateFormat")
private fun getSecond(): String {
if (XSPUtils.getBoolean("status_bar_time_seconds", false)) {
return SimpleDateFormat(":ss").format(now_time)
}
return ""
}
@SuppressLint("SimpleDateFormat")
private fun getTime(t: String): String {
if (t == "24") {
return getPeriod() + SimpleDateFormat("HH:mm").format(now_time)
} else {
return getPeriod() + SimpleDateFormat("h:mm").format(now_time)
}
}
@SuppressLint("SimpleDateFormat")
private fun getWeek(): String {
var week = ""
if (XSPUtils.getBoolean("status_bar_time_week", false)) {
week = SimpleDateFormat("E").format(now_time)
if (XSPUtils.getBoolean("status_bar_time_hide_space", false)) {
week += ""
if (isYear) {
if (isZh) {
DatePattern += "YY年"
// if (!isHideSpace) DatePattern = "$DatePattern "
} else {
week += " "
DatePattern += "YY"
if (isMonth || isDay) DatePattern += "/"
}
}
return week
if (isMonth) {
if (isZh) {
DatePattern += "M月"
// if (!isHideSpace) DatePattern = "$DatePattern "
} else {
DatePattern += "M"
if (isDay) DatePattern += "/"
}
}
if (isDay) {
if (isZh) {
DatePattern += "d日"
} else {
DatePattern += "d"
}
}
if (isWeek) {
if (!isHideSpace) DatePattern = "$DatePattern "
DatePattern += "E"
if (!isDoubleLine && isDoubleHour) {
if (!isHideSpace) DatePattern = "$DatePattern "
}
}
DatePattern = SimpleDateFormat(DatePattern).format(now_time)
return DatePattern
}
@SuppressLint("SimpleDateFormat")
private fun getPeriod(): String {
private fun getTime(context: Context, t: String): String {
var timePattern = ""
val isZh = isZh(context)
timePattern += if (t == "24") "HH:mm" else "h:mm"
if (isSecond) timePattern += ":ss"
timePattern = SimpleDateFormat(timePattern).format(now_time)
if (isZh) timePattern = getPeriod(isZh) + timePattern else timePattern += getPeriod(isZh)
timePattern = getDoubleHour() + timePattern
return timePattern
}
@SuppressLint("SimpleDateFormat")
private fun getPeriod(isZh: Boolean): String {
var period = ""
if (XSPUtils.getBoolean("status_bar_time_period", true)) {
var now = SimpleDateFormat("HH").format(now_time)
when (now) {
"00", "01", "02", "03", "04", "05" -> {
period = "凌晨"
if (isPeriod) {
if (isZh) {
val now = SimpleDateFormat("HH").format(now_time)
when (now) {
"00", "01", "02", "03", "04", "05" -> {
period = "凌晨"
}
"06", "07", "08", "09", "10", "11" -> {
period = "上午"
}
"12" -> {
period = "中午"
}
"13", "14", "15", "16", "17" -> {
period = "下午"
}
"18" -> {
period = "傍晚"
}
"19", "20", "21", "22", "23" -> {
period = "晚上"
}
}
"06", "07", "08", "09", "10", "11" -> {
period = "上午"
}
"12" -> {
period = "中午"
}
"13", "14", "15", "16", "17" -> {
period = "下午"
}
"18" -> {
period = "傍晚"
}
"19", "20", "21", "22", "23" -> {
period = "晚上"
} else {
period = SimpleDateFormat("a").format(now_time)
if (!isHideSpace) {
period = " $period"
}
}
}
return period
}
@@ -195,9 +221,8 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage {
@SuppressLint("SimpleDateFormat")
private fun getDoubleHour(): String {
var doubleHour = ""
if (XSPUtils.getBoolean("status_bar_time_double_hour", false)) {
var now = SimpleDateFormat("HH").format(now_time)
if (isDoubleHour) {
val now = SimpleDateFormat("HH").format(now_time)
when (now) {
"23", "00" -> {
doubleHour = "子时"
@@ -236,30 +261,17 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage {
doubleHour = "亥时"
}
}
if (XSPUtils.getBoolean("status_bar_time_hide_space", false)) {
doubleHour += ""
} else {
if (!isHideSpace) {
doubleHour += " "
}
}
return doubleHour
}
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 ""
fun isZh(context: Context): Boolean {
val locale = context.resources.configuration.locale
val language = locale.language
return language.endsWith("zh")
}
}

View File

@@ -65,7 +65,7 @@
<string name="status_bar_time_hide_space">Hide space</string>
<string name="allow_screenshots">Allow screenshot</string>
<string name="lock_max">Lock current limit</string>
<string name="status_bar_time_double_hour">Display hour</string>
<string name="status_bar_time_double_hour">Display chinese twelve hour</string>
<string name="custom_clock_switch">Custom Clock Switch</string>
<string name="status_bar_time_period">Display AM/PM</string>
<string name="status_bar_time_double_line">Dual row</string>