mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-12 11:21:18 +08:00
优化状态栏时钟功能
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -18,11 +18,26 @@ import java.util.*
|
|||||||
|
|
||||||
class StatusBarTimeCustomization : IXposedHookLoadPackage {
|
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 now_time: Date? = null
|
||||||
var str = ""
|
var str = ""
|
||||||
|
|
||||||
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
|
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
|
||||||
if (XSPUtils.getBoolean("custom_clock_switch", false)) {
|
if (isOpen) {
|
||||||
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",
|
||||||
@@ -39,12 +54,12 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage {
|
|||||||
val textV = param.thisObject as TextView
|
val textV = param.thisObject as TextView
|
||||||
textV.isSingleLine = false
|
textV.isSingleLine = false
|
||||||
|
|
||||||
if (XSPUtils.getBoolean("status_bar_time_double_line", false)) {
|
if (isDoubleLine) {
|
||||||
str = "\n"
|
str = "\n"
|
||||||
var clock_double_line_size = 7F
|
var clock_double_line_size = 7F
|
||||||
if (XSPUtils.getInt("status_bar_clock_double_line_size", 0) != 0) {
|
if (getClockDoubleSize != 0) {
|
||||||
clock_double_line_size =
|
clock_double_line_size =
|
||||||
XSPUtils.getInt("status_bar_clock_double_line_size", 0)
|
getClockDoubleSize
|
||||||
.toFloat()
|
.toFloat()
|
||||||
}
|
}
|
||||||
textV.setTextSize(
|
textV.setTextSize(
|
||||||
@@ -52,9 +67,9 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage {
|
|||||||
clock_double_line_size
|
clock_double_line_size
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if (XSPUtils.getInt("status_bar_clock_size", 0) != 0) {
|
if (getClockSize != 0) {
|
||||||
val clock_size =
|
val clock_size =
|
||||||
XSPUtils.getInt("status_bar_clock_size", 0).toFloat()
|
getClockSize.toFloat()
|
||||||
textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clock_size)
|
textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clock_size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,10 +110,7 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage {
|
|||||||
)
|
)
|
||||||
now_time = Calendar.getInstance().time
|
now_time = Calendar.getInstance().time
|
||||||
|
|
||||||
textV.text =
|
textV.text = getDate(c!!, t) + str + getTime(c!!, t)
|
||||||
getYear() + getMonth() + getDay() + getDateSpace() + getWeek() + str + getDoubleHour() + getTime(
|
|
||||||
t
|
|
||||||
) + getSecond()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} 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")
|
@SuppressLint("SimpleDateFormat")
|
||||||
private fun getMonth(): String {
|
private fun getDate(context: Context, t: String): String {
|
||||||
if (XSPUtils.getBoolean("status_bar_time_month", false)) {
|
var DatePattern = ""
|
||||||
return SimpleDateFormat("M月").format(now_time)
|
val isZh = isZh(context)
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("SimpleDateFormat")
|
if (isYear) {
|
||||||
private fun getDay(): String {
|
if (isZh) {
|
||||||
if (XSPUtils.getBoolean("status_bar_time_day", false)) {
|
DatePattern += "YY年"
|
||||||
return SimpleDateFormat("d日").format(now_time)
|
// if (!isHideSpace) DatePattern = "$DatePattern "
|
||||||
}
|
|
||||||
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 += ""
|
|
||||||
} else {
|
} 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")
|
@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 = ""
|
var period = ""
|
||||||
if (XSPUtils.getBoolean("status_bar_time_period", true)) {
|
if (isPeriod) {
|
||||||
var now = SimpleDateFormat("HH").format(now_time)
|
if (isZh) {
|
||||||
when (now) {
|
val now = SimpleDateFormat("HH").format(now_time)
|
||||||
"00", "01", "02", "03", "04", "05" -> {
|
when (now) {
|
||||||
period = "凌晨"
|
"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" -> {
|
} else {
|
||||||
period = "上午"
|
period = SimpleDateFormat("a").format(now_time)
|
||||||
}
|
if (!isHideSpace) {
|
||||||
"12" -> {
|
period = " $period"
|
||||||
period = "中午"
|
|
||||||
}
|
|
||||||
"13", "14", "15", "16", "17" -> {
|
|
||||||
period = "下午"
|
|
||||||
}
|
|
||||||
"18" -> {
|
|
||||||
period = "傍晚"
|
|
||||||
}
|
|
||||||
"19", "20", "21", "22", "23" -> {
|
|
||||||
period = "晚上"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return period
|
return period
|
||||||
}
|
}
|
||||||
@@ -195,9 +221,8 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage {
|
|||||||
@SuppressLint("SimpleDateFormat")
|
@SuppressLint("SimpleDateFormat")
|
||||||
private fun getDoubleHour(): String {
|
private fun getDoubleHour(): String {
|
||||||
var doubleHour = ""
|
var doubleHour = ""
|
||||||
if (XSPUtils.getBoolean("status_bar_time_double_hour", false)) {
|
if (isDoubleHour) {
|
||||||
var now = SimpleDateFormat("HH").format(now_time)
|
val now = SimpleDateFormat("HH").format(now_time)
|
||||||
|
|
||||||
when (now) {
|
when (now) {
|
||||||
"23", "00" -> {
|
"23", "00" -> {
|
||||||
doubleHour = "子时"
|
doubleHour = "子时"
|
||||||
@@ -236,30 +261,17 @@ class StatusBarTimeCustomization : IXposedHookLoadPackage {
|
|||||||
doubleHour = "亥时"
|
doubleHour = "亥时"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!isHideSpace) {
|
||||||
if (XSPUtils.getBoolean("status_bar_time_hide_space", false)) {
|
|
||||||
doubleHour += ""
|
|
||||||
} else {
|
|
||||||
doubleHour += " "
|
doubleHour += " "
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return doubleHour
|
return doubleHour
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDateSpace(): String {
|
fun isZh(context: Context): Boolean {
|
||||||
if (XSPUtils.getBoolean("status_bar_time_year", false) ||
|
val locale = context.resources.configuration.locale
|
||||||
XSPUtils.getBoolean("status_bar_time_month", false) ||
|
val language = locale.language
|
||||||
XSPUtils.getBoolean("status_bar_time_day", false)
|
return language.endsWith("zh")
|
||||||
) {
|
|
||||||
if (XSPUtils.getBoolean("status_bar_time_hide_space", false)) {
|
|
||||||
return ""
|
|
||||||
} else {
|
|
||||||
return " "
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
<string name="status_bar_time_hide_space">Hide space</string>
|
<string name="status_bar_time_hide_space">Hide space</string>
|
||||||
<string name="allow_screenshots">Allow screenshot</string>
|
<string name="allow_screenshots">Allow screenshot</string>
|
||||||
<string name="lock_max">Lock current limit</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="custom_clock_switch">Custom Clock Switch</string>
|
||||||
<string name="status_bar_time_period">Display AM/PM</string>
|
<string name="status_bar_time_period">Display AM/PM</string>
|
||||||
<string name="status_bar_time_double_line">Dual row</string>
|
<string name="status_bar_time_double_line">Dual row</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user