新增下拉通知天气

This commit is contained in:
乌堆小透明
2022-03-05 22:14:15 +08:00
parent e5130e3491
commit bd70382d2b
4 changed files with 61 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@@ -61,7 +61,7 @@ class SystemUI : IXposedHookLoadPackage {
RemoveLockScreenCamera().handleLoadPackage(lpparam) RemoveLockScreenCamera().handleLoadPackage(lpparam)
//TODO:状态栏天气 //TODO:状态栏天气
//NotificationWeather().handleLoadPackage(lpparam) NotificationWeather().handleLoadPackage(lpparam)
//TODO状态栏电流 //TODO状态栏电流
//StatusBarCurrent().handleLoadPackage(lpparam) //StatusBarCurrent().handleLoadPackage(lpparam)
} }

View File

@@ -1,14 +1,23 @@
package com.lt2333.simplicitytools.hook.app.systemui package com.lt2333.simplicitytools.hook.app.systemui
import android.database.Cursor
import android.net.Uri
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import com.lt2333.simplicitytools.util.XSPUtils
import de.robv.android.xposed.IXposedHookLoadPackage import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.XC_MethodHook import de.robv.android.xposed.XC_MethodHook
import de.robv.android.xposed.XposedHelpers import de.robv.android.xposed.XposedHelpers
import de.robv.android.xposed.callbacks.XC_LoadPackage import de.robv.android.xposed.callbacks.XC_LoadPackage
import java.util.*
class NotificationWeather : IXposedHookLoadPackage { class NotificationWeather : IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
if (!XSPUtils.getBoolean("notification_weather", false)) return
var display_city = XSPUtils.getBoolean("notification_weather_city", false)
val classIfExists = XposedHelpers.findClassIfExists( val classIfExists = XposedHelpers.findClassIfExists(
"com.android.systemui.qs.MiuiNotificationHeaderView", "com.android.systemui.qs.MiuiNotificationHeaderView",
lpparam.classLoader lpparam.classLoader
@@ -17,7 +26,6 @@ class NotificationWeather :IXposedHookLoadPackage {
override fun afterHookedMethod(param: MethodHookParam) { override fun afterHookedMethod(param: MethodHookParam) {
val viewGroup = param.thisObject as ViewGroup val viewGroup = param.thisObject as ViewGroup
val layout = XposedHelpers.findClass( val layout = XposedHelpers.findClass(
"androidx.constraintlayout.widget.ConstraintLayout\$LayoutParams", "androidx.constraintlayout.widget.ConstraintLayout\$LayoutParams",
lpparam.classLoader lpparam.classLoader
@@ -35,6 +43,7 @@ class NotificationWeather :IXposedHookLoadPackage {
viewGroup.context.packageName viewGroup.context.packageName
) )
) )
XposedHelpers.setObjectField( XposedHelpers.setObjectField(
layout, layout,
"startToEnd", "startToEnd",
@@ -44,6 +53,7 @@ class NotificationWeather :IXposedHookLoadPackage {
viewGroup.context.packageName viewGroup.context.packageName
) )
) )
layout.marginStart = viewGroup.context.resources.getDimensionPixelSize( layout.marginStart = viewGroup.context.resources.getDimensionPixelSize(
viewGroup.context.resources.getIdentifier( viewGroup.context.resources.getIdentifier(
"notification_panel_time_date_space", "notification_panel_time_date_space",
@@ -52,15 +62,54 @@ class NotificationWeather :IXposedHookLoadPackage {
) )
) )
val textView = TextView(viewGroup.context).also { val textView = TextView(viewGroup.context).also {
it.setTextAppearance(viewGroup.context.resources.getIdentifier("TextAppearance.QSControl.Date","style",viewGroup.context.packageName)) it.setTextAppearance(
it.text = "This is a TextView" viewGroup.context.resources.getIdentifier(
"TextAppearance.QSControl.Date",
"style",
viewGroup.context.packageName
)
)
it.layoutParams = layout it.layoutParams = layout
} }
viewGroup.addView(textView) viewGroup.addView(textView)
val query: Cursor? = viewGroup.context.contentResolver
.query(Uri.parse("content://weather/weather"), null, null, null, null)
var str = "未找到天气"
class T : TimerTask() {
override fun run() {
try {
if (query != null) {
if (query.moveToFirst()) {
if (display_city) {
str =
query.getString(query.getColumnIndexOrThrow("city_name")) + " " +
query.getString(query.getColumnIndexOrThrow("description")) + " " +
query.getString(query.getColumnIndexOrThrow("temperature"))
} else {
str =
query.getString(query.getColumnIndexOrThrow("description")) + " " +
query.getString(query.getColumnIndexOrThrow("temperature"))
}
}
query.close()
}
textView.text = str
} catch (e: Exception) {
}
}
}
//每小时刷新一次
Timer().scheduleAtFixedRate(
T(),
0,
3600000
)
} }
}) })
} }

View File

@@ -118,4 +118,8 @@
<string name="hide_wifi_activity_icon">隐藏 WIFI箭头 图标</string> <string name="hide_wifi_activity_icon">隐藏 WIFI箭头 图标</string>
<string name="hide_mobile_activity_icon">隐藏 移动箭头 图标</string> <string name="hide_mobile_activity_icon">隐藏 移动箭头 图标</string>
<string name="hide_mobile_type_icon">隐藏 移动类型 图标</string> <string name="hide_mobile_type_icon">隐藏 移动类型 图标</string>
<string name="notification_weather">显示天气-总开关</string>
<string name="lock_screen">锁屏</string>
<string name="notification_center">通知中心</string>
<string name="notification_weather_city">显示城市</string>
</resources> </resources>