新增旧版通知栏天气

This commit is contained in:
乌堆小透明
2022-03-10 01:23:24 +08:00
parent ac5fb9ca0b
commit abb9c12d71
2 changed files with 98 additions and 0 deletions

View File

@@ -59,6 +59,7 @@ class SystemUI : IXposedHookLoadPackage {
RemoveLockScreenCamera().handleLoadPackage(lpparam)
//通知面板天气
NotificationWeather().handleLoadPackage(lpparam)
OldNotificationWeather().handleLoadPackage(lpparam)
//控制中心天气
ControlCenterWeather().handleLoadPackage(lpparam)
//TODO状态栏电流

View File

@@ -0,0 +1,97 @@
package com.lt2333.simplicitytools.hook.app.systemui
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.lt2333.simplicitytools.util.XSPUtils
import com.lt2333.simplicitytools.view.WeatherView
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.XC_MethodHook
import de.robv.android.xposed.XposedHelpers
import de.robv.android.xposed.callbacks.XC_LoadPackage
class OldNotificationWeather : IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
var mWeatherView: TextView? = null
if (!XSPUtils.getBoolean("notification_weather", false)) return
val isDisplayCity = XSPUtils.getBoolean("notification_weather_city", false)
val classIfExists = XposedHelpers.findClassIfExists(
"com.android.systemui.qs.MiuiQSHeaderView",
lpparam.classLoader
)
XposedHelpers.findAndHookMethod(classIfExists, "onFinishInflate", object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) {
val viewGroup = param.thisObject as ViewGroup
val layout = XposedHelpers.findClass(
"androidx.constraintlayout.widget.ConstraintLayout\$LayoutParams",
lpparam.classLoader
).getConstructor(Int::class.java, Int::class.java).newInstance(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
) as ViewGroup.MarginLayoutParams
XposedHelpers.setObjectField(
layout,
"endToStart",
viewGroup.context.resources.getIdentifier(
"notification_shade_shortcut",
"id",
viewGroup.context.packageName
)
)
XposedHelpers.setObjectField(
layout,
"topToTop",
viewGroup.context.resources.getIdentifier(
"notification_shade_shortcut",
"id",
viewGroup.context.packageName
)
)
XposedHelpers.setObjectField(
layout,
"bottomToBottom",
viewGroup.context.resources.getIdentifier(
"notification_shade_shortcut",
"id",
viewGroup.context.packageName
)
)
mWeatherView = WeatherView(viewGroup.context,isDisplayCity).also {
it.setTextAppearance(
viewGroup.context.resources.getIdentifier(
"TextAppearance.StatusBar.Expanded.Clock.QuickSettingDate",
"style",
viewGroup.context.packageName
)
)
it.layoutParams = layout
}
viewGroup.addView(mWeatherView)
}
})
//解决横屏重叠
XposedHelpers.findAndHookMethod(classIfExists, "updateLayout", object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) {
super.afterHookedMethod(param)
val mOrientation =
XposedHelpers.getObjectField(param.thisObject, "mOrientation") as Int
if (mOrientation == 1) {
mWeatherView!!.visibility = View.VISIBLE
} else {
mWeatherView!!.visibility = View.GONE
}
}
})
}
}