优化锁屏电流显示

This commit is contained in:
乌堆小透明
2022-03-14 01:48:02 +08:00
parent df72a5f363
commit dc7e45e4ad
3 changed files with 17 additions and 5 deletions

View File

@@ -945,9 +945,10 @@ class SettingsActivity : MIUIActivity() {
add( add(
TextSummaryWithSwitchV( TextSummaryWithSwitchV(
TextSummaryV( TextSummaryV(
textId = R.string.lock_screen_current, textId = R.string.lock_screen_charging_current,
tipsId = R.string.only_official_default_themes_are_supported
), ),
SwitchV("lock_screen_current") SwitchV("lock_screen_charging_current")
) )
) )
} }

View File

@@ -2,12 +2,14 @@ package com.lt2333.simplicitytools.hook.app.systemui
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.widget.TextView
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.hookAfterMethod import com.lt2333.simplicitytools.util.hookAfterMethod
import de.robv.android.xposed.IXposedHookLoadPackage import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.XposedHelpers
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
@@ -26,6 +28,15 @@ class LockScreenCurrent : IXposedHookLoadPackage {
) { ) {
it.result = getCurrent() + "\n" + it.result it.result = getCurrent() + "\n" + it.result
} }
"com.android.systemui.statusbar.phone.KeyguardBottomAreaView".findClass(lpparam.classLoader)
.hookAfterMethod(
"onFinishInflate"
) {
(XposedHelpers.getObjectField(
it.thisObject,
"mIndicationText"
) as TextView).isSingleLine = false
}
} }
} }
@@ -43,11 +54,11 @@ class LockScreenCurrent : IXposedHookLoadPackage {
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"
val current = (getMeanCurrentVal(filePath, 5, 0) / 1000.0f).roundToInt() val current = (-getMeanCurrentVal(filePath, 5, 0) / 1000.0f).roundToInt()
result = "${InitFields.moduleRes.getString(R.string.current_current)} ${current}mA" 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 = "${InitFields.moduleRes.getString(R.string.current_current)} ${current}mA" result = "${InitFields.moduleRes.getString(R.string.current_current)} ${current}mA"
} }
} catch (e: Exception) { } catch (e: Exception) {

View File

@@ -156,6 +156,6 @@
<string name="current">Current:</string> <string name="current">Current:</string>
<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_charging_current">Display current information during charging</string>
<string name="current_current">Current</string> <string name="current_current">Current</string>
</resources> </resources>