From d998fcd415af656fbe2323eaa26c066ace6f628b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=8C=E5=A0=86=E5=B0=8F=E9=80=8F=E6=98=8E?= <841474544@qq.com> Date: Thu, 24 Feb 2022 21:05:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9B=B4=E5=A4=9A=E6=97=B6?= =?UTF-8?q?=E9=92=9F=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/SettingsActivity.kt | 18 +- .../simplicitytools/hook/app/SystemUI.kt | 4 +- .../systemui/StatusBarTimeCustomization.kt | 231 ++++++++++++++++++ .../hook/app/systemui/StatusBarTimeSeconds.kt | 141 ----------- 4 files changed, 250 insertions(+), 144 deletions(-) create mode 100644 app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeCustomization.kt delete mode 100644 app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeSeconds.kt 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 592a35d5..1228f5da 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt @@ -56,7 +56,7 @@ class SettingsActivity : MIUIActivity() { override fun mainItems(): ArrayList { return arrayListOf().apply { - add(TextWithSwitchV(TextV(resId = R.string.main_switch), SwitchV("main_switch"))) + add(TextWithSwitchV(TextV(resId = R.string.main_switch), SwitchV("main_switch",true))) add( TextWithSwitchV( TextV(resId = R.string.HideLauncherIcon), @@ -108,6 +108,10 @@ class SettingsActivity : MIUIActivity() { ) add(LineV()) add(TitleTextV(resId = R.string.status_bar_clock_format)) + add(TextWithSwitchV( + TextV(resId = R.string.custom_clock_switch), + SwitchV("custom_clock_switch") + )) add( TextWithSwitchV( TextV(resId = R.string.status_bar_time_year), @@ -132,6 +136,18 @@ class SettingsActivity : MIUIActivity() { SwitchV("status_bar_time_week") ) ) + add( + TextWithSwitchV( + TextV(resId = R.string.status_bar_time_double_hour), + SwitchV("status_bar_time_double_hour") + ) + ) + add( + TextWithSwitchV( + TextV(resId = R.string.status_bar_time_period), + SwitchV("status_bar_time_period",true) + ) + ) add( TextWithSwitchV( TextV(resId = R.string.status_bar_time_seconds), diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/SystemUI.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/SystemUI.kt index bfe7741f..8cc26737 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/SystemUI.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/SystemUI.kt @@ -47,8 +47,8 @@ class SystemUI : IXposedHookLoadPackage { RemoveTheMaximumNumberOfNotificationIcons().handleLoadPackage(lpparam) //状态栏网速秒刷新 StatusBarNetworkSpeedRefreshSpeed().handleLoadPackage(lpparam) - //状态栏时钟显秒 - StatusBarTimeSeconds().handleLoadPackage(lpparam) + //状态栏时钟自定义 + StatusBarTimeCustomization().handleLoadPackage(lpparam) } } diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeCustomization.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeCustomization.kt new file mode 100644 index 00000000..14249231 --- /dev/null +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeCustomization.kt @@ -0,0 +1,231 @@ +package com.lt2333.simplicitytools.hook.app.systemui + +import android.annotation.SuppressLint +import android.content.Context +import android.os.Handler +import android.provider.Settings +import android.util.AttributeSet +import android.widget.TextView +import com.lt2333.simplicitytools.util.XSPUtils +import de.robv.android.xposed.IXposedHookLoadPackage +import de.robv.android.xposed.XC_MethodHook +import de.robv.android.xposed.XposedHelpers +import de.robv.android.xposed.callbacks.XC_LoadPackage +import java.lang.reflect.Method +import java.text.SimpleDateFormat +import java.util.* + +class StatusBarTimeCustomization : IXposedHookLoadPackage { + + var now_time: Date? = null + + override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { + if (XSPUtils.getBoolean("custom_clock_switch", 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) + } + } + 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 + ) + now_time= Calendar.getInstance().time + textV.text = + getYear() + getMonth() + getDay() + getDateSpace() + getWeek() + getDoubleHour() + getTime( + t + ) + getSecond() + } + } + }) + } + } + + @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 "" + } + + @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 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 { + week += " " + } + } + return week + } + + @SuppressLint("SimpleDateFormat") + private fun getPeriod(): 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 = "凌晨" + } + "06", "07", "08", "09", "10", "11" -> { + period = "上午" + } + "12" -> { + period = "中午" + } + "13", "14", "15", "16", "17" -> { + period = "下午" + } + "18" -> { + period = "傍晚" + } + "19", "20", "21", "22", "23" -> { + period = "晚上" + } + } + } + return period + } + + @SuppressLint("SimpleDateFormat") + private fun getDoubleHour(): String { + var doubleHour = "" + if (XSPUtils.getBoolean("status_bar_time_double_hour", false)) { + var now = SimpleDateFormat("HH").format(now_time) + + when (now) { + "23", "00" -> { + doubleHour = "子时" + } + "01", "02" -> { + doubleHour = "丑时" + } + "03", "04" -> { + doubleHour = "寅时" + } + "05", "06" -> { + doubleHour = "卯时" + } + "07", "08" -> { + doubleHour = "辰时" + } + "09", "10" -> { + doubleHour = "巳时" + } + "11", "12" -> { + doubleHour = "午时" + } + "13", "14" -> { + doubleHour = "未时" + } + "15", "16" -> { + doubleHour = "申时" + } + "17", "18" -> { + doubleHour = "酉时" + } + "19", "20" -> { + doubleHour = "戌时" + } + "21", "22" -> { + doubleHour = "亥时" + } + } + + if (XSPUtils.getBoolean("status_bar_time_hide_space", false)) { + doubleHour += "" + } else { + 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 "" + } + +} \ No newline at end of file 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 deleted file mode 100644 index 428a7fe4..00000000 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarTimeSeconds.kt +++ /dev/null @@ -1,141 +0,0 @@ -package com.lt2333.simplicitytools.hook.app.systemui - -import android.annotation.SuppressLint -import android.content.Context -import android.os.Handler -import android.provider.Settings -import android.util.AttributeSet -import android.widget.TextView -import com.lt2333.simplicitytools.util.XSPUtils -import de.robv.android.xposed.IXposedHookLoadPackage -import de.robv.android.xposed.XC_MethodHook -import de.robv.android.xposed.XposedHelpers -import de.robv.android.xposed.callbacks.XC_LoadPackage -import java.lang.reflect.Method -import java.text.SimpleDateFormat -import java.util.* - -class StatusBarTimeSeconds : IXposedHookLoadPackage { - override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { - - 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 - ) - } - } - ) - 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() - } - } - }) - - - } - - @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