mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-12 19:31:17 +08:00
A12自定义时钟极客模式支持更多内容(未测试)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.lt2333.simplicitytools.activity.pages.s
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.view.View
|
||||
import android.widget.Switch
|
||||
import android.widget.Toast
|
||||
@@ -11,6 +13,7 @@ import cn.fkj233.ui.activity.view.SwitchV
|
||||
import cn.fkj233.ui.activity.view.TextSummaryV
|
||||
import cn.fkj233.ui.activity.view.TextV
|
||||
import cn.fkj233.ui.dialog.MIUIDialog
|
||||
import cn.fkj233.ui.dialog.NewDialog
|
||||
import com.lt2333.simplicitytools.R
|
||||
|
||||
|
||||
@@ -210,27 +213,37 @@ class SystemUIPageForS : BasePage() {
|
||||
|
||||
//极客模式起始
|
||||
TextSummaryWithArrow(TextSummaryV(textId = R.string.custom_clock_format_geek) {
|
||||
MIUIDialog(activity) {
|
||||
NewDialog(activity) {
|
||||
setTitle(R.string.custom_clock_format_geek)
|
||||
setEditText(
|
||||
MIUIActivity.safeSP.getString("custom_clock_format_geek", "HH:mm:ss"),
|
||||
"",
|
||||
isSingleLine = false
|
||||
MIUIActivity.safeSP.getString("custom_clock_format_geek", "HH:mm:ss"), "", isSingleLine = false
|
||||
)
|
||||
setLButton(textId = R.string.cancel) {
|
||||
dismiss()
|
||||
Button(getString(R.string.click_to_view_use_cases)) {
|
||||
val locale = context.resources.configuration.locale
|
||||
val language = locale.language
|
||||
if (language.endsWith("zh")) {
|
||||
val uri = Uri.parse("https://zhuti.designer.xiaomi.com/docs/grammar/#%E6%97%B6%E9%97%B4%E6%97%A5%E6%9C%9F")
|
||||
val intent = Intent(Intent.ACTION_VIEW, uri)
|
||||
activity.startActivity(intent)
|
||||
} else {
|
||||
val uri = Uri.parse("https://docs.google.com/spreadsheets/d/1ghkT2iFbxB3bT4TKCiKAfmEdGt6kTVKFU3dm4Nz1or8/edit?usp=sharing")
|
||||
val intent = Intent(Intent.ACTION_VIEW, uri)
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
setRButton(textId = R.string.Done) {
|
||||
}
|
||||
Button(getString(R.string.Done)) {
|
||||
if (getEditText().isNotEmpty()) {
|
||||
try {
|
||||
MIUIActivity.safeSP.putAny("custom_clock_format_geek", getEditText())
|
||||
dismiss()
|
||||
return@setRButton
|
||||
return@Button
|
||||
} catch (_: Throwable) {
|
||||
}
|
||||
}
|
||||
Toast.makeText(activity, R.string.input_error, Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
Toast.makeText(activity, R.string.input_error, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
Button(getString(R.string.cancel), cancelStyle = true) {
|
||||
dismiss()
|
||||
}
|
||||
}.show()
|
||||
}, dataBindingRecv = customClockGeekBinding.binding.getRecv(2))
|
||||
|
||||
@@ -2,12 +2,10 @@ package com.lt2333.simplicitytools.hooks.rules.s.systemui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.os.Handler
|
||||
import android.provider.Settings
|
||||
import android.util.TypedValue
|
||||
import android.view.Gravity
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import com.github.kyuubiran.ezxhelper.utils.*
|
||||
import com.lt2333.simplicitytools.utils.XSPUtils
|
||||
@@ -16,6 +14,7 @@ import java.lang.reflect.Method
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
|
||||
object StatusBarTimeCustomizationForS : HookRegister() {
|
||||
|
||||
private val getMode = XSPUtils.getInt("custom_clock_mode", 0)
|
||||
@@ -30,14 +29,12 @@ object StatusBarTimeCustomizationForS : HookRegister() {
|
||||
private val isSecond = XSPUtils.getBoolean("status_bar_time_seconds", false)
|
||||
private val isDoubleHour = XSPUtils.getBoolean("status_bar_time_double_hour", false)
|
||||
private val isPeriod = XSPUtils.getBoolean("status_bar_time_period", true)
|
||||
private val isCenterAlign =
|
||||
XSPUtils.getBoolean("status_bar_time_double_line_center_align", false)
|
||||
private val isCenterAlign = XSPUtils.getBoolean("status_bar_time_double_line_center_align", false)
|
||||
|
||||
//极客模式
|
||||
private val getGeekClockSize = XSPUtils.getInt("status_bar_clock_size_geek", 0)
|
||||
private val getGeekFormat = XSPUtils.getString("custom_clock_format_geek", "HH:mm:ss")
|
||||
private val isGeekCenterAlign =
|
||||
XSPUtils.getBoolean("status_bar_time_center_align_geek", false)
|
||||
private val isGeekCenterAlign = XSPUtils.getBoolean("status_bar_time_center_align_geek", false)
|
||||
|
||||
private lateinit var nowTime: Date
|
||||
private var str = ""
|
||||
@@ -83,9 +80,7 @@ object StatusBarTimeCustomizationForS : HookRegister() {
|
||||
}
|
||||
}
|
||||
Timer().scheduleAtFixedRate(
|
||||
T(),
|
||||
1000 - System.currentTimeMillis() % 1000,
|
||||
1000
|
||||
T(), 1000 - System.currentTimeMillis() % 1000, 1000
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
@@ -98,8 +93,7 @@ object StatusBarTimeCustomizationForS : HookRegister() {
|
||||
val textV = it.thisObject as TextView
|
||||
if (textV.resources.getResourceEntryName(textV.id) == "clock") {
|
||||
val t = Settings.System.getString(
|
||||
c!!.contentResolver,
|
||||
Settings.System.TIME_12_24
|
||||
c!!.contentResolver, Settings.System.TIME_12_24
|
||||
)
|
||||
val is24 = t == "24"
|
||||
nowTime = Calendar.getInstance().time
|
||||
@@ -110,15 +104,18 @@ object StatusBarTimeCustomizationForS : HookRegister() {
|
||||
}
|
||||
|
||||
if (isCenterAlign) {
|
||||
findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") {
|
||||
name == "onViewCreated" && parameterCount == 2
|
||||
findConstructor("com.android.systemui.statusbar.views.MiuiClock") {
|
||||
paramCount == 3
|
||||
}.hookAfter {
|
||||
val miuiPhoneStatusBarView =
|
||||
it.thisObject.getObject("mStatusBar") as ViewGroup
|
||||
val res: Resources = miuiPhoneStatusBarView.resources
|
||||
val clockId: Int = res.getIdentifier("clock", "id", "com.android.systemui")
|
||||
val clock: TextView = miuiPhoneStatusBarView.findViewById(clockId)
|
||||
clock.gravity = Gravity.CENTER
|
||||
try {
|
||||
val textV = it.thisObject as TextView
|
||||
if (textV.resources.getResourceEntryName(textV.id) == "clock") {
|
||||
c = it.args[0] as Context
|
||||
val textV = it.thisObject as TextView
|
||||
textV.gravity = Gravity.CENTER
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,9 +149,7 @@ object StatusBarTimeCustomizationForS : HookRegister() {
|
||||
}
|
||||
}
|
||||
Timer().scheduleAtFixedRate(
|
||||
T(),
|
||||
1000 - System.currentTimeMillis() % 1000,
|
||||
1000
|
||||
T(), 1000 - System.currentTimeMillis() % 1000, 1000
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
@@ -162,27 +157,38 @@ object StatusBarTimeCustomizationForS : HookRegister() {
|
||||
|
||||
findMethod("com.android.systemui.statusbar.views.MiuiClock") {
|
||||
name == "updateTime"
|
||||
}.hookAfter {
|
||||
}.hookBefore {
|
||||
try {
|
||||
val textV = it.thisObject as TextView
|
||||
if (textV.resources.getResourceEntryName(textV.id) == "clock") {
|
||||
nowTime = Calendar.getInstance().time
|
||||
textV.text = SimpleDateFormat(getGeekFormat).format(nowTime)
|
||||
val mMiuiStatusBarClockController = textV.getObject("mMiuiStatusBarClockController")
|
||||
val mCalendar = mMiuiStatusBarClockController.invokeMethodAuto("getCalendar")
|
||||
mCalendar?.invokeMethodAuto(
|
||||
"setTimeInMillis", System.currentTimeMillis()
|
||||
)
|
||||
val textSb = StringBuilder()
|
||||
val formatSb = StringBuilder(getGeekFormat.toString())
|
||||
mCalendar?.invokeMethodAuto("format", c, textSb, formatSb)
|
||||
textV.text = textSb.toString()
|
||||
it.result = null
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
if (isGeekCenterAlign) {
|
||||
findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") {
|
||||
name == "onViewCreated" && parameterCount == 2
|
||||
findConstructor("com.android.systemui.statusbar.views.MiuiClock") {
|
||||
paramCount == 3
|
||||
}.hookAfter {
|
||||
val miuiPhoneStatusBarView =
|
||||
it.thisObject.getObject("mStatusBar") as ViewGroup
|
||||
val res: Resources = miuiPhoneStatusBarView.resources
|
||||
val clockId: Int = res.getIdentifier("clock", "id", "com.android.systemui")
|
||||
val clock: TextView = miuiPhoneStatusBarView.findViewById(clockId)
|
||||
clock.gravity = Gravity.CENTER
|
||||
try {
|
||||
val textV = it.thisObject as TextView
|
||||
if (textV.resources.getResourceEntryName(textV.id) == "clock") {
|
||||
c = it.args[0] as Context
|
||||
val textV = it.thisObject as TextView
|
||||
textV.gravity = Gravity.CENTER
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,7 +203,6 @@ object StatusBarTimeCustomizationForS : HookRegister() {
|
||||
if (isYear) {
|
||||
if (isZh) {
|
||||
datePattern += "YY年"
|
||||
// if (!isHideSpace) datePattern = "$datePattern "
|
||||
} else {
|
||||
datePattern += "YY"
|
||||
if (isMonth || isDay) datePattern += "/"
|
||||
@@ -206,7 +211,6 @@ object StatusBarTimeCustomizationForS : HookRegister() {
|
||||
if (isMonth) {
|
||||
if (isZh) {
|
||||
datePattern += "M月"
|
||||
// if (!isHideSpace) datePattern = "$datePattern "
|
||||
} else {
|
||||
datePattern += "M"
|
||||
if (isDay) datePattern += "/"
|
||||
|
||||
Reference in New Issue
Block a user