mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-12 19:31:17 +08:00
优化锁屏电流显示
This commit is contained in:
@@ -1,59 +1,30 @@
|
|||||||
package com.lt2333.simplicitytools.hook.app.systemui
|
package com.lt2333.simplicitytools.hook.app.systemui
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.BroadcastReceiver
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.IntentFilter
|
|
||||||
import android.graphics.Typeface
|
|
||||||
import android.view.Gravity
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.TextView
|
|
||||||
import cn.fkj233.ui.activity.dp2px
|
|
||||||
import com.github.kyuubiran.ezxhelper.init.InitFields
|
import com.github.kyuubiran.ezxhelper.init.InitFields
|
||||||
import com.lt2333.simplicitytools.R
|
import com.lt2333.simplicitytools.R
|
||||||
import com.lt2333.simplicitytools.util.findClass
|
import com.lt2333.simplicitytools.util.findClass
|
||||||
import com.lt2333.simplicitytools.util.hasEnable
|
import com.lt2333.simplicitytools.util.hasEnable
|
||||||
import com.lt2333.simplicitytools.util.hookAfterAllMethods
|
|
||||||
import com.lt2333.simplicitytools.util.hookAfterMethod
|
import com.lt2333.simplicitytools.util.hookAfterMethod
|
||||||
import com.microsoft.appcenter.utils.HandlerUtils.runOnUiThread
|
|
||||||
import de.robv.android.xposed.IXposedHookLoadPackage
|
import de.robv.android.xposed.IXposedHookLoadPackage
|
||||||
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.FileReader
|
import java.io.FileReader
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import java.util.*
|
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
class LockScreenCurrent(private var battery: String = "") : IXposedHookLoadPackage {
|
class LockScreenCurrent : IXposedHookLoadPackage {
|
||||||
|
|
||||||
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
|
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
|
||||||
hasEnable("lock_screen_current") {
|
hasEnable("lock_screen_current") {
|
||||||
val miuiPhoneStatusBarViewClass =
|
"com.android.keyguard.charge.ChargeUtils".findClass(lpparam.classLoader)
|
||||||
"com.android.systemui.statusbar.phone.KeyguardBottomAreaView".findClass(lpparam.classLoader)
|
.hookAfterMethod(
|
||||||
miuiPhoneStatusBarViewClass.hookAfterMethod("onFinishInflate") { param ->
|
"getChargingHintText",
|
||||||
val viewGroup = param.thisObject as ViewGroup
|
Context::class.java,
|
||||||
battery = getBatteryTemperature(viewGroup.context).toString()
|
Boolean::class.java,
|
||||||
val textView = TextView(viewGroup.context).also {
|
Int::class.java
|
||||||
it.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
|
) {
|
||||||
it.setTextSize(android.util.TypedValue.COMPLEX_UNIT_SP, 14f)
|
it.result = getCurrent() + "\n" + it.result
|
||||||
it.gravity = Gravity.CENTER or Gravity.BOTTOM
|
|
||||||
it.setPadding(0, 0, 0, dp2px(viewGroup.context, 5f))
|
|
||||||
}
|
|
||||||
Timer().schedule(object : TimerTask() {
|
|
||||||
override fun run() {
|
|
||||||
runOnUiThread {
|
|
||||||
textView.text = getCurrent()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}, 0, 1000)
|
|
||||||
val darkIconDispatcherClass =
|
|
||||||
"com.android.systemui.plugins.DarkIconDispatcher".findClass(lpparam.classLoader)
|
|
||||||
darkIconDispatcherClass.hookAfterAllMethods("getTint") {
|
|
||||||
val areaTint = it.args[2] as Int
|
|
||||||
textView.setTextColor(areaTint)
|
|
||||||
}
|
|
||||||
viewGroup.addView(textView)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,19 +43,12 @@ class LockScreenCurrent(private var battery: String = "") : IXposedHookLoadPacka
|
|||||||
if (platName.startsWith("mt") || platName.startsWith("MT")) {
|
if (platName.startsWith("mt") || platName.startsWith("MT")) {
|
||||||
val filePath =
|
val filePath =
|
||||||
"/sys/class/power_supply/battery/device/FG_Battery_CurrentConsumption"
|
"/sys/class/power_supply/battery/device/FG_Battery_CurrentConsumption"
|
||||||
result = "${(getMeanCurrentVal(filePath, 5, 0) / 1000.0f).roundToInt()} mA"
|
val current = (getMeanCurrentVal(filePath, 5, 0) / 1000.0f).roundToInt()
|
||||||
|
result = "${InitFields.moduleRes.getString(R.string.current_current)} ${current}mA"
|
||||||
} else if (platName.startsWith("qcom")) {
|
} else if (platName.startsWith("qcom")) {
|
||||||
val filePath = "/sys/class/power_supply/battery/current_now"
|
val filePath = "/sys/class/power_supply/battery/current_now"
|
||||||
val current = (getMeanCurrentVal(filePath, 5, 0) / 1000.0f).roundToInt()
|
val current = (getMeanCurrentVal(filePath, 5, 0) / 1000.0f).roundToInt()
|
||||||
result = if (current <= 0) {
|
result = "${InitFields.moduleRes.getString(R.string.current_current)} ${current}mA"
|
||||||
"${InitFields.moduleRes.getString(R.string.current_current)}$current mA,${
|
|
||||||
InitFields.moduleRes.getString(
|
|
||||||
R.string.temp
|
|
||||||
)
|
|
||||||
}$battery℃".replace("-", "").replace("${InitFields.moduleRes.getString(R.string.current_current)}0 mA,", "")
|
|
||||||
} else {
|
|
||||||
"${InitFields.moduleRes.getString(R.string.current_current)}-$current mA"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
@@ -130,11 +94,4 @@ class LockScreenCurrent(private var battery: String = "") : IXposedHookLoadPacka
|
|||||||
}
|
}
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getBatteryTemperature(context: Context): Int {
|
|
||||||
return context.registerReceiver(
|
|
||||||
null as BroadcastReceiver?,
|
|
||||||
IntentFilter("android.intent.action.BATTERY_CHANGED")
|
|
||||||
)!!.getIntExtra("temperature", 0) / 10
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -157,6 +157,5 @@
|
|||||||
<string name="participate_in_translation">Participate in translation</string>
|
<string name="participate_in_translation">Participate in translation</string>
|
||||||
<string name="participate_in_translation_summary">Help us translate the app into your language</string>
|
<string name="participate_in_translation_summary">Help us translate the app into your language</string>
|
||||||
<string name="lock_screen_current">Lock screen displays current information</string>
|
<string name="lock_screen_current">Lock screen displays current information</string>
|
||||||
<string name="current_current">current:</string>
|
<string name="current_current">Current</string>
|
||||||
<string name="temp">temp.</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user