diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/statusbar/clock/StatusBarClockNew.kt b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/statusbar/clock/StatusBarClockNew.kt index cfe70502d3..7b40ef89fa 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/statusbar/clock/StatusBarClockNew.kt +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/statusbar/clock/StatusBarClockNew.kt @@ -25,7 +25,8 @@ import android.util.* import android.view.* import android.widget.* import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass -import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook +import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createAfterHook +import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createBeforeHook import com.github.kyuubiran.ezxhelper.finders.ConstructorFinder.`-Static`.constructorFinder import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder import com.sevtinge.hyperceiler.module.base.* @@ -50,13 +51,13 @@ object StatusBarClockNew : BaseHook() { mPrefsMap.getBoolean("system_ui_disable_clock_synch") } private val clockSizeS by lazy { - mPrefsMap.getInt("system_ui_statusbar_clock_size_1", 5) + mPrefsMap.getInt("system_ui_statusbar_clock_size_1", 12) } private val clockSizeB by lazy { - mPrefsMap.getInt("system_ui_statusbar_clock_size_2", 20) + mPrefsMap.getInt("system_ui_statusbar_clock_size_2", 54) } private val clockSizeN by lazy { - mPrefsMap.getInt("system_ui_statusbar_clock_size_3", 9) + mPrefsMap.getInt("system_ui_statusbar_clock_size_3", 12) } private val clockTextSpacing by lazy { mPrefsMap.getInt("system_ui_statusbar_clock_double_spacing_margin_1", 16) @@ -105,82 +106,79 @@ object StatusBarClockNew : BaseHook() { override fun init() { statusBarClass.constructorFinder() .filterByParamCount(3) - .first().createHook { - after { - try { - val miuiClock = it.thisObject as TextView - val miuiClockName = miuiClock.resources.getResourceEntryName(miuiClock.id) ?: return@after - - setMiuiClockStyle(miuiClockName, miuiClock) - - val isSec = - miuiClockName in setOf("clock", "big_time", "horizontal_time", "date_time") - // miuiClockName 内部标签分类如下 - // clock 竖屏状态栏时钟 - // big_time 通知中心时钟 - // horizontal_time 横屏通知中心时钟 - // date_time 通知中心日期时钟 - - if (getClockStyle != 0 && miuiClockName == "clock") - miuiClock.isSingleLine = false - - if (isSec) { - val d: Method = miuiClock.javaClass.getDeclaredMethod("updateTime") - val r = Runnable { - d.isAccessible = true - d.invoke(miuiClock) - } + .first().createAfterHook { + try { + val miuiClock = it.thisObject as TextView + val miuiClockName = miuiClock.resources.getResourceEntryName(miuiClock.id) + ?: return@createAfterHook + + setMiuiClockStyle(miuiClockName, miuiClock) + + val isSec = + miuiClockName in setOf("clock", "big_time", "horizontal_time", "date_time") + // miuiClockName 内部标签分类如下 + // clock 竖屏状态栏时钟 + // big_time 通知中心时钟 + // horizontal_time 横屏通知中心时钟 + // date_time 通知中心日期时钟 + + if (getClockStyle != 0 && miuiClockName == "clock") + miuiClock.isSingleLine = false + + if (isSec) { + val d: Method = miuiClock.javaClass.getDeclaredMethod("updateTime") + val r = Runnable { + d.isAccessible = true + d.invoke(miuiClock) + } - class T : TimerTask() { - override fun run() { - Handler(miuiClock.context.mainLooper).post(r) - } + class T : TimerTask() { + override fun run() { + Handler(miuiClock.context.mainLooper).post(r) } - Timer().schedule( - T(), 1000 - System.currentTimeMillis() % 1000, 1000 - ) } - } catch (_: Exception) { + Timer().schedule( + T(), 1000 - System.currentTimeMillis() % 1000, 1000 + ) } + } catch (_: Exception) { } } // 设置格式 statusBarClass.methodFinder() .filterByName("updateTime") - .single().createHook { - before { - try { - val textV = it.thisObject as TextView - val context = textV.context - val miuiClockName = textV.resources.getResourceEntryName(textV.id) ?: return@before - if (miuiClockName in setOf("clock", "big_time", "horizontal_time", "date_time")) { - setMiuiClockStyle(miuiClockName, textV) - - if ((isSync && miuiClockName == "big_time") || (getFormatN.isEmpty() && miuiClockName in setOf("date_time", "horizontal_time"))) return@before - setMiuiClockFormat(context, miuiClockName, textV) - it.result = null - } - } catch (_: Exception) { + .single().createBeforeHook { + try { + val textV = it.thisObject as TextView + val context = textV.context + val miuiClockName = + textV.resources.getResourceEntryName(textV.id) ?: return@createBeforeHook + if (miuiClockName in setOf("clock", "big_time", "horizontal_time", "date_time")) { + setMiuiClockStyle(miuiClockName, textV) + + if ((isSync && miuiClockName == "big_time") || (getFormatN.isEmpty() && miuiClockName in setOf("date_time", "horizontal_time"))) return@createBeforeHook + setMiuiClockFormat(context, miuiClockName, textV) + it.result = null } + } catch (_: Exception) { } } mNewClockClass.methodFinder() .filterByName("updateTime") - .single().createHook { - before { - try { - val textV = it.thisObject as TextView - val context = textV.context - val miuiClockName = textV.resources.getResourceEntryName(textV.id) ?: return@before - setMiuiClockStyle(miuiClockName, textV) - - if ((isSync && miuiClockName == "big_time") || (getFormatN.isEmpty() && miuiClockName in setOf("date_time", "horizontal_time"))) return@before - setMiuiClockFormat(context, miuiClockName, textV) - it.result = null - } catch (_: Exception) { - } + .single().createBeforeHook { + try { + val textV = it.thisObject as TextView + val context = textV.context + val miuiClockName = + textV.resources.getResourceEntryName(textV.id) ?: return@createBeforeHook + setMiuiClockStyle(miuiClockName, textV) + + if ((isSync && miuiClockName == "big_time") || (getFormatN.isEmpty() && miuiClockName in setOf("date_time", "horizontal_time"))) return@createBeforeHook + setMiuiClockFormat(context, miuiClockName, textV) + it.result = null + } catch (_: Exception) { } } } @@ -223,15 +221,15 @@ object StatusBarClockNew : BaseHook() { private fun setStatusBarClock(name: String, text: TextView) { when { - clockSizeS != 5 && name == "clock" -> { + clockSizeS != 12 && name == "clock" -> { text.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clockSizeS.toFloat()) } - clockSizeB != 20 && name == "big_time" -> { + clockSizeB != 54 && name == "big_time" -> { text.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clockSizeB.toFloat()) } - clockSizeN != 9 && name in setOf("date_time", "horizontal_time") -> { + clockSizeN != 12 && name in setOf("date_time", "horizontal_time") -> { text.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clockSizeN.toFloat()) } } @@ -253,6 +251,9 @@ object StatusBarClockNew : BaseHook() { } private fun setMiuiClockFormat(context: Context?, name: String, textV: TextView) { + val textSb: StringBuilder + val formatSb: StringBuilder + // 因为输入对话框限制,所以里面部分内容会比较抽象 val sClockName = if (getFormatN.isEmpty()) { when (getClockStyle) { @@ -280,33 +281,27 @@ object StatusBarClockNew : BaseHook() { when (name) { "clock" -> { - val textSb = StringBuilder() - val formatSb = StringBuilder(sClockName) - mCalendar?.callMethod("format", context, textSb, formatSb) - textV.text = textSb.toString() + textSb = StringBuilder() + formatSb = StringBuilder(sClockName) } "big_time" -> { - val textSb = StringBuilder() - val formatSb = StringBuilder(getFormatS.split("\n")[0]) - mCalendar?.callMethod("format", context, textSb, formatSb) - textV.text = textSb.toString() + textSb = StringBuilder() + formatSb = StringBuilder(getFormatS.split("\n")[0]) } "horizontal_time" -> { - val textSb = StringBuilder() - val formatSb = + textSb = StringBuilder() + formatSb = StringBuilder("${getFormatN.split("\n")[0]} ${getFormatS.split("\n")[0]}") - mCalendar?.callMethod("format", context, textSb, formatSb) - textV.text = textSb.toString() } else -> { - val textSb = StringBuilder() - val formatSb = StringBuilder(getFormatN.split("\n")[0]) - mCalendar?.callMethod("format", context, textSb, formatSb) - textV.text = textSb.toString() + textSb = StringBuilder() + formatSb = StringBuilder(getFormatN.split("\n")[0]) } } + mCalendar?.callMethod("format", context, textSb, formatSb) + textV.text = textSb.toString() } } \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 2aa80e7919..c42970e57c 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -326,9 +326,9 @@ 上下行网速单行显示 上下行网速双排显示 - 单行显示 (仅状态栏时钟) - 双行显示 (状态栏时钟在上, 通知中心迷你时钟在下) - 双行显示 (通知中心迷你时钟在上, 状态栏时钟在下) + 单行显示\n\n仅状态栏时钟 + 双行显示\n\n状态栏时钟在上\n通知中心迷你时钟在下 + 双行显示\n\n通知中心迷你时钟在上\n状态栏时钟在下 米老鼠 草莓熊 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c058f042f4..ef346b0eba 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -326,9 +326,9 @@ Values and units are displayed in two rows The uplink and downlink network speed is displayed in a single line Dual-row display of uplink and downlink network speeds - Single line status bar clock - Status bar clock\nNotification bar mini clock - Notification bar mini clock\nStatus bar clock + Single line display\n\nStatus bar clock only + Two-line display\n\nStatus bar clock on top\nNotification bar mini clock on bottom + Two-line display\n\nNotification bar mini clock on top\nStatus bar clock on bottom Mickey Mouse Strawberry Bear diff --git a/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_1.xml b/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_1.xml index 3c7b91ed62..0e742a2267 100644 --- a/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_1.xml +++ b/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_1.xml @@ -10,13 +10,13 @@ app:entryValues="@array/system_ui_status_bar_clock_double_mode_value" /> diff --git a/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_2.xml b/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_2.xml index def37abbd8..2129b34b36 100644 --- a/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_2.xml +++ b/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_2.xml @@ -3,12 +3,12 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> diff --git a/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_3.xml b/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_3.xml index f30e379de4..02cc5cd6f7 100644 --- a/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_3.xml +++ b/app/src/main/res/xml/system_ui_status_bar_new_clock_indicator_3.xml @@ -5,7 +5,7 @@