修复通知中心天气横屏重叠

This commit is contained in:
乌堆小透明
2022-03-06 02:46:57 +08:00
parent bcddf96980
commit 5f24f611d2

View File

@@ -2,6 +2,7 @@ package com.lt2333.simplicitytools.hook.app.systemui
import android.database.Cursor import android.database.Cursor
import android.net.Uri import android.net.Uri
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import com.lt2333.simplicitytools.util.XSPUtils import com.lt2333.simplicitytools.util.XSPUtils
@@ -14,6 +15,8 @@ import java.util.*
class NotificationWeather : IXposedHookLoadPackage { class NotificationWeather : IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
var mWeatherView: TextView? = null
if (!XSPUtils.getBoolean("notification_weather", false)) return if (!XSPUtils.getBoolean("notification_weather", false)) return
var display_city = XSPUtils.getBoolean("notification_weather_city", false) var display_city = XSPUtils.getBoolean("notification_weather_city", false)
@@ -22,6 +25,7 @@ class NotificationWeather : IXposedHookLoadPackage {
"com.android.systemui.qs.MiuiNotificationHeaderView", "com.android.systemui.qs.MiuiNotificationHeaderView",
lpparam.classLoader lpparam.classLoader
) )
XposedHelpers.findAndHookMethod(classIfExists, "onFinishInflate", object : XC_MethodHook() { XposedHelpers.findAndHookMethod(classIfExists, "onFinishInflate", object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) { override fun afterHookedMethod(param: MethodHookParam) {
val viewGroup = param.thisObject as ViewGroup val viewGroup = param.thisObject as ViewGroup
@@ -62,7 +66,7 @@ class NotificationWeather : IXposedHookLoadPackage {
) )
) )
val textView = TextView(viewGroup.context).also { mWeatherView = TextView(viewGroup.context).also {
it.setTextAppearance( it.setTextAppearance(
viewGroup.context.resources.getIdentifier( viewGroup.context.resources.getIdentifier(
"TextAppearance.QSControl.Date", "TextAppearance.QSControl.Date",
@@ -73,7 +77,7 @@ class NotificationWeather : IXposedHookLoadPackage {
it.layoutParams = layout it.layoutParams = layout
} }
viewGroup.addView(textView) viewGroup.addView(mWeatherView)
val query: Cursor? = viewGroup.context.contentResolver val query: Cursor? = viewGroup.context.contentResolver
.query(Uri.parse("content://weather/weather"), null, null, null, null) .query(Uri.parse("content://weather/weather"), null, null, null, null)
@@ -98,7 +102,7 @@ class NotificationWeather : IXposedHookLoadPackage {
} }
query.close() query.close()
} }
textView.text = str mWeatherView!!.text = str
} catch (e: Exception) { } catch (e: Exception) {
} }
} }
@@ -112,5 +116,18 @@ class NotificationWeather : IXposedHookLoadPackage {
} }
}) })
//解决横屏重叠
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
}
}
})
} }
} }