更新时钟自定义极客模式

This commit is contained in:
LittleTurtle2333
2022-06-29 16:44:19 +08:00
parent 479251fb67
commit 72ad0479df

View File

@@ -18,6 +18,9 @@ import java.util.*
object StatusBarTimeCustomization : HookRegister() { object StatusBarTimeCustomization : HookRegister() {
private val getMode = XSPUtils.getInt("custom_clock_mode", 0)
private val getClockSize = XSPUtils.getInt("status_bar_clock_size", 0)
private val getClockDoubleSize = XSPUtils.getInt("status_bar_clock_double_line_size", 0)
private val isYear = XSPUtils.getBoolean("status_bar_time_year", false) private val isYear = XSPUtils.getBoolean("status_bar_time_year", false)
private val isMonth = XSPUtils.getBoolean("status_bar_time_month", false) private val isMonth = XSPUtils.getBoolean("status_bar_time_month", false)
private val isDay = XSPUtils.getBoolean("status_bar_time_day", false) private val isDay = XSPUtils.getBoolean("status_bar_time_day", false)
@@ -27,85 +30,160 @@ object StatusBarTimeCustomization : HookRegister() {
private val isSecond = XSPUtils.getBoolean("status_bar_time_seconds", false) private val isSecond = XSPUtils.getBoolean("status_bar_time_seconds", false)
private val isDoubleHour = XSPUtils.getBoolean("status_bar_time_double_hour", false) private val isDoubleHour = XSPUtils.getBoolean("status_bar_time_double_hour", false)
private val isPeriod = XSPUtils.getBoolean("status_bar_time_period", true) private val isPeriod = XSPUtils.getBoolean("status_bar_time_period", true)
private val getClockSize = XSPUtils.getInt("status_bar_clock_size", 0)
private val isOpen = XSPUtils.getBoolean("custom_clock_switch", false)
private val isCenterAlign = private val isCenterAlign =
XSPUtils.getBoolean("status_bar_time_double_line_center_align", false) XSPUtils.getBoolean("status_bar_time_double_line_center_align", false)
private val getClockDoubleSize = XSPUtils.getInt("status_bar_clock_double_line_size", 0)
//极客模式
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 lateinit var nowTime: Date private lateinit var nowTime: Date
private var str = "" private var str = ""
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun init() { override fun init() {
if (isOpen) { when (getMode) {
var c: Context? = null //预设模式
1 -> {
var c: Context? = null
findConstructor("com.android.systemui.statusbar.views.MiuiClock") { findConstructor("com.android.systemui.statusbar.views.MiuiClock") {
paramCount == 3 paramCount == 3
}.hookAfter { }.hookAfter {
try { try {
c = it.args[0] as Context c = it.args[0] as Context
val textV = it.thisObject as TextView val textV = it.thisObject as TextView
if (textV.resources.getResourceEntryName(textV.id) != "clock") return@hookAfter if (textV.resources.getResourceEntryName(textV.id) != "clock") return@hookAfter
textV.isSingleLine = false textV.isSingleLine = false
if (isDoubleLine) { if (isDoubleLine) {
str = "\n" str = "\n"
var clockDoubleLineSize = 7F var clockDoubleLineSize = 7F
if (getClockDoubleSize != 0) { if (getClockDoubleSize != 0) {
clockDoubleLineSize = getClockDoubleSize.toFloat() clockDoubleLineSize = getClockDoubleSize.toFloat()
}
textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clockDoubleLineSize)
textV.setLineSpacing(0F, 0.8F)
} else {
if (getClockSize != 0) {
val clockSize = getClockSize.toFloat()
textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clockSize)
}
} }
textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clockDoubleLineSize) 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)
}
}
Timer().scheduleAtFixedRate(
T(),
1000 - System.currentTimeMillis() % 1000,
1000
)
} catch (_: Exception) {
}
}
findMethod("com.android.systemui.statusbar.views.MiuiClock") {
name == "updateTime"
}.hookAfter {
try {
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
)
val is24 = t == "24"
nowTime = Calendar.getInstance().time
textV.text = getDate(c!!) + str + getTime(c!!, is24)
}
} catch (_: Exception) {
}
}
if (isCenterAlign) {
findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") {
name == "onViewCreated" && parameterCount == 2
}.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
}
}
}
//极客模式
2 -> {
var c: Context? = null
findConstructor("com.android.systemui.statusbar.views.MiuiClock") {
paramCount == 3
}.hookAfter {
try {
c = it.args[0] as Context
val textV = it.thisObject as TextView
if (textV.resources.getResourceEntryName(textV.id) != "clock") return@hookAfter
textV.isSingleLine = false
textV.setLineSpacing(0F, 0.8F) textV.setLineSpacing(0F, 0.8F)
} else { if (getGeekClockSize != 0) {
if (getClockSize != 0) { val clockSize = getGeekClockSize.toFloat()
val clockSize = getClockSize.toFloat()
textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clockSize) textV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, clockSize)
} }
}
val d: Method = textV.javaClass.getDeclaredMethod("updateTime")
val r = Runnable {
d.isAccessible = true
d.invoke(textV)
}
class T : TimerTask() { val d: Method = textV.javaClass.getDeclaredMethod("updateTime")
override fun run() { val r = Runnable {
Handler(textV.context.mainLooper).post(r) d.isAccessible = true
d.invoke(textV)
} }
}
Timer().scheduleAtFixedRate(T(), 1000 - System.currentTimeMillis() % 1000, 1000)
} catch (_: Exception) {
}
}
findMethod("com.android.systemui.statusbar.views.MiuiClock") { class T : TimerTask() {
name == "updateTime" override fun run() {
}.hookAfter { Handler(textV.context.mainLooper).post(r)
try { }
val textV = it.thisObject as TextView }
if (textV.resources.getResourceEntryName(textV.id) == "clock") { Timer().scheduleAtFixedRate(
val t = Settings.System.getString( T(),
c!!.contentResolver, 1000 - System.currentTimeMillis() % 1000,
Settings.System.TIME_12_24 1000
) )
val is24 = t == "24" } catch (_: Exception) {
nowTime = Calendar.getInstance().time
textV.text = getDate(c!!) + str + getTime(c!!, is24)
} }
} catch (_: Exception) {
} }
}
if (isCenterAlign) { findMethod("com.android.systemui.statusbar.views.MiuiClock") {
findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") { name == "updateTime"
name == "onViewCreated" && parameterCount == 2
}.hookAfter { }.hookAfter {
val miuiPhoneStatusBarView = try {
it.thisObject.getObject("mStatusBar") as ViewGroup val textV = it.thisObject as TextView
val res: Resources = miuiPhoneStatusBarView.resources if (textV.resources.getResourceEntryName(textV.id) == "clock") {
val clockId: Int = res.getIdentifier("clock", "id", "com.android.systemui") nowTime = Calendar.getInstance().time
val clock: TextView = miuiPhoneStatusBarView.findViewById(clockId) textV.text = SimpleDateFormat(getGeekFormat).format(nowTime)
clock.gravity = Gravity.CENTER }
} catch (_: Exception) {
}
}
if (isGeekCenterAlign) {
findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") {
name == "onViewCreated" && parameterCount == 2
}.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
}
} }
} }
} }