mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-12 19:31:17 +08:00
新增控制中心天气
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -59,9 +59,10 @@ class SystemUI : IXposedHookLoadPackage {
|
||||
RemoveTheLeftSideOfTheLockScreen().handleLoadPackage(lpparam)
|
||||
//移除锁屏相机功能
|
||||
RemoveLockScreenCamera().handleLoadPackage(lpparam)
|
||||
|
||||
//TODO:状态栏天气
|
||||
//通知面板天气
|
||||
NotificationWeather().handleLoadPackage(lpparam)
|
||||
//控制中心天气
|
||||
ControlCenterWeather().handleLoadPackage(lpparam)
|
||||
//TODO:状态栏电流
|
||||
//StatusBarCurrent().handleLoadPackage(lpparam)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.lt2333.simplicitytools.hook.app.systemui
|
||||
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import com.lt2333.simplicitytools.util.XSPUtils
|
||||
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
|
||||
import java.util.*
|
||||
|
||||
class ControlCenterWeather : IXposedHookLoadPackage {
|
||||
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
|
||||
|
||||
var mWeatherView: TextView? = null
|
||||
|
||||
if (!XSPUtils.getBoolean("control_center_weather", false)) return
|
||||
|
||||
var display_city = XSPUtils.getBoolean("control_center_weather_city", false)
|
||||
|
||||
val classIfExists = XposedHelpers.findClassIfExists(
|
||||
"com.android.systemui.controlcenter.phone.widget.QSControlCenterHeaderView",
|
||||
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,
|
||||
"bottomToTop",
|
||||
viewGroup.context.resources.getIdentifier(
|
||||
"date_time",
|
||||
"id",
|
||||
viewGroup.context.packageName
|
||||
)
|
||||
)
|
||||
|
||||
XposedHelpers.setObjectField(
|
||||
layout,
|
||||
"startToEnd",
|
||||
viewGroup.context.resources.getIdentifier(
|
||||
"big_time",
|
||||
"id",
|
||||
viewGroup.context.packageName
|
||||
)
|
||||
)
|
||||
|
||||
layout.marginStart = viewGroup.context.resources.getDimensionPixelSize(
|
||||
viewGroup.context.resources.getIdentifier(
|
||||
"notification_panel_time_date_space",
|
||||
"dimen",
|
||||
viewGroup.context.packageName
|
||||
)
|
||||
)
|
||||
|
||||
mWeatherView = TextView(viewGroup.context).also {
|
||||
it.setTextAppearance(
|
||||
viewGroup.context.resources.getIdentifier(
|
||||
"TextAppearance.QSControl.Date",
|
||||
"style",
|
||||
viewGroup.context.packageName
|
||||
)
|
||||
)
|
||||
it.layoutParams = layout
|
||||
}
|
||||
|
||||
viewGroup.addView(mWeatherView)
|
||||
|
||||
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()
|
||||
}
|
||||
mWeatherView!!.text = str
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
//每小时刷新一次
|
||||
Timer().scheduleAtFixedRate(
|
||||
T(),
|
||||
0,
|
||||
3600000
|
||||
)
|
||||
|
||||
}
|
||||
})
|
||||
//解决横屏重叠
|
||||
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
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -118,9 +118,11 @@
|
||||
<string name="hide_wifi_activity_icon">隐藏 WIFI箭头 图标</string>
|
||||
<string name="hide_mobile_activity_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>
|
||||
<string name="lock_max_fps_summary">支持添加下拉控制中心快速开关,实时切换</string>
|
||||
<string name="show_city">显示城市</string>
|
||||
<string name="control_center">控制中心</string>
|
||||
<string name="show_weather_main_switch">显示天气-总开关</string>
|
||||
<string name="control_center_weather_summary">暂不支持妙想版控制中心</string>
|
||||
</resources>
|
||||
|
||||
@@ -118,9 +118,11 @@
|
||||
<string name="hide_wifi_activity_icon">Hide WIFI activity icon</string>
|
||||
<string name="hide_mobile_activity_icon">Hide mobile activity icon</string>
|
||||
<string name="hide_mobile_type_icon">Hide mobile type icon</string>
|
||||
<string name="notification_weather">Show Weather - Master Switch</string>
|
||||
<string name="show_weather_main_switch">Show Weather - Main Switch</string>
|
||||
<string name="lock_screen">Lock screen</string>
|
||||
<string name="notification_center">Notification Center</string>
|
||||
<string name="notification_weather_city">Show the city</string>
|
||||
<string name="show_city">Show the city</string>
|
||||
<string name="lock_max_fps_summary">Support adding drop-down control center quick switch, real-time switching</string>
|
||||
<string name="control_center">Control Center</string>
|
||||
<string name="control_center_weather_summary">The Mi Smart Hub version is not currently supported</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user