From abb9c12d71e450d98dd7a2de5c4c0a42de18ab3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=8C=E5=A0=86=E5=B0=8F=E9=80=8F=E6=98=8E?= Date: Thu, 10 Mar 2022 01:23:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=A7=E7=89=88=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=A0=8F=E5=A4=A9=E6=B0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simplicitytools/hook/app/SystemUI.kt | 1 + .../app/systemui/OldNotificationWeather.kt | 97 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/OldNotificationWeather.kt diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/SystemUI.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/SystemUI.kt index 0c2f7fde..f545f380 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/SystemUI.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/SystemUI.kt @@ -59,6 +59,7 @@ class SystemUI : IXposedHookLoadPackage { RemoveLockScreenCamera().handleLoadPackage(lpparam) //通知面板天气 NotificationWeather().handleLoadPackage(lpparam) + OldNotificationWeather().handleLoadPackage(lpparam) //控制中心天气 ControlCenterWeather().handleLoadPackage(lpparam) //TODO:状态栏电流 diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/OldNotificationWeather.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/OldNotificationWeather.kt new file mode 100644 index 00000000..f982311b --- /dev/null +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/OldNotificationWeather.kt @@ -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 + } + } + }) + } +} +