mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-13 20:01:17 +08:00
新增时钟显秒
This commit is contained in:
@@ -10,8 +10,8 @@ android {
|
||||
applicationId "com.lt2333.simplicitytools"
|
||||
minSdk 30
|
||||
targetSdk 32
|
||||
versionCode 3
|
||||
versionName "1.0.2"
|
||||
versionCode 4
|
||||
versionName "1.0.3"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
package com.lt2333.simplicitytools.hook.app
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.provider.Settings
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.widget.TextView
|
||||
import com.lt2333.simplicitytools.BuildConfig
|
||||
import com.lt2333.simplicitytools.hook.MainHook
|
||||
import de.robv.android.xposed.*
|
||||
import de.robv.android.xposed.XC_MethodHook.MethodHookParam
|
||||
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam
|
||||
import java.lang.reflect.Method
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class SystemUI : IXposedHookLoadPackage {
|
||||
|
||||
@@ -241,5 +250,68 @@ class SystemUI : IXposedHookLoadPackage {
|
||||
XposedBridge.log(e)
|
||||
}
|
||||
|
||||
|
||||
//时钟显秒
|
||||
if (prefs.hasFileChanged()) {
|
||||
prefs.reload()
|
||||
}
|
||||
if (prefs.getBoolean("statusbar_time_seconds", 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
|
||||
)
|
||||
if (t == "24")
|
||||
textV.text =
|
||||
SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().time)
|
||||
else
|
||||
textV.text =
|
||||
textV.text.toString() + SimpleDateFormat(":ss").format(Calendar.getInstance().time)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user