mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-13 03:41:19 +08:00
修复状态栏天气不更新
This commit is contained in:
@@ -1,16 +1,14 @@
|
|||||||
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.View
|
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
|
||||||
|
import com.lt2333.simplicitytools.view.WeatherView
|
||||||
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 ControlCenterWeather : IXposedHookLoadPackage {
|
class ControlCenterWeather : IXposedHookLoadPackage {
|
||||||
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
|
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
|
||||||
@@ -19,7 +17,7 @@ class ControlCenterWeather : IXposedHookLoadPackage {
|
|||||||
|
|
||||||
if (!XSPUtils.getBoolean("control_center_weather", false)) return
|
if (!XSPUtils.getBoolean("control_center_weather", false)) return
|
||||||
|
|
||||||
var display_city = XSPUtils.getBoolean("control_center_weather_city", false)
|
val isDisplayCity = XSPUtils.getBoolean("control_center_weather_city", false)
|
||||||
|
|
||||||
val classIfExists = XposedHelpers.findClassIfExists(
|
val classIfExists = XposedHelpers.findClassIfExists(
|
||||||
"com.android.systemui.controlcenter.phone.widget.QSControlCenterHeaderView",
|
"com.android.systemui.controlcenter.phone.widget.QSControlCenterHeaderView",
|
||||||
@@ -66,7 +64,7 @@ class ControlCenterWeather : IXposedHookLoadPackage {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
mWeatherView = TextView(viewGroup.context).also {
|
mWeatherView = WeatherView(viewGroup.context, isDisplayCity).also {
|
||||||
it.setTextAppearance(
|
it.setTextAppearance(
|
||||||
viewGroup.context.resources.getIdentifier(
|
viewGroup.context.resources.getIdentifier(
|
||||||
"TextAppearance.QSControl.Date",
|
"TextAppearance.QSControl.Date",
|
||||||
@@ -78,42 +76,6 @@ class ControlCenterWeather : IXposedHookLoadPackage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
viewGroup.addView(mWeatherView)
|
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
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
//解决横屏重叠
|
//解决横屏重叠
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
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.View
|
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
|
||||||
|
import com.lt2333.simplicitytools.view.WeatherView
|
||||||
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) {
|
||||||
@@ -19,7 +17,7 @@ class NotificationWeather : IXposedHookLoadPackage {
|
|||||||
|
|
||||||
if (!XSPUtils.getBoolean("notification_weather", false)) return
|
if (!XSPUtils.getBoolean("notification_weather", false)) return
|
||||||
|
|
||||||
var display_city = XSPUtils.getBoolean("notification_weather_city", false)
|
val isDisplayCity = XSPUtils.getBoolean("notification_weather_city", false)
|
||||||
|
|
||||||
val classIfExists = XposedHelpers.findClassIfExists(
|
val classIfExists = XposedHelpers.findClassIfExists(
|
||||||
"com.android.systemui.qs.MiuiNotificationHeaderView",
|
"com.android.systemui.qs.MiuiNotificationHeaderView",
|
||||||
@@ -66,7 +64,7 @@ class NotificationWeather : IXposedHookLoadPackage {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
mWeatherView = TextView(viewGroup.context).also {
|
mWeatherView = WeatherView(viewGroup.context,isDisplayCity).also {
|
||||||
it.setTextAppearance(
|
it.setTextAppearance(
|
||||||
viewGroup.context.resources.getIdentifier(
|
viewGroup.context.resources.getIdentifier(
|
||||||
"TextAppearance.QSControl.Date",
|
"TextAppearance.QSControl.Date",
|
||||||
@@ -76,44 +74,7 @@ class NotificationWeather : IXposedHookLoadPackage {
|
|||||||
)
|
)
|
||||||
it.layoutParams = layout
|
it.layoutParams = layout
|
||||||
}
|
}
|
||||||
|
|
||||||
viewGroup.addView(mWeatherView)
|
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
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
//解决横屏重叠
|
//解决横屏重叠
|
||||||
@@ -131,3 +92,4 @@ class NotificationWeather : IXposedHookLoadPackage {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package com.lt2333.simplicitytools.view
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.database.ContentObserver
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.os.Message
|
||||||
|
import android.text.TextUtils
|
||||||
|
import android.widget.TextView
|
||||||
|
|
||||||
|
class WeatherView(context: Context?, private val showCity: Boolean) : TextView(context) {
|
||||||
|
|
||||||
|
private val mContext: Context
|
||||||
|
private val WEATHER_URI = Uri.parse("content://weather/weather")
|
||||||
|
private val mHandler: Handler
|
||||||
|
private val mWeatherObserver: ContentObserver?
|
||||||
|
private val mWeatherRunnable: WeatherRunnable
|
||||||
|
|
||||||
|
init {
|
||||||
|
mHandler =
|
||||||
|
object : Handler(Looper.getMainLooper()) {
|
||||||
|
override fun handleMessage(message: Message) {
|
||||||
|
val str = message.obj as String
|
||||||
|
this@WeatherView.text = if (TextUtils.isEmpty(str)) " " else str
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mWeatherObserver = WeatherContentObserver(mHandler)
|
||||||
|
mContext = context!!
|
||||||
|
mWeatherRunnable = WeatherRunnable()
|
||||||
|
context.contentResolver.registerContentObserver(WEATHER_URI, true, mWeatherObserver)
|
||||||
|
updateWeatherInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class WeatherContentObserver(handler: Handler?) : ContentObserver(handler) {
|
||||||
|
override fun onChange(z: Boolean) {
|
||||||
|
updateWeatherInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class WeatherRunnable : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
var str = ""
|
||||||
|
try {
|
||||||
|
val query = mContext.contentResolver.query(WEATHER_URI, null, null, null, null)
|
||||||
|
if (query != null) {
|
||||||
|
if (query.moveToFirst()) {
|
||||||
|
if (showCity) {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
|
||||||
|
}
|
||||||
|
val obtainMessage2 = mHandler.obtainMessage()
|
||||||
|
obtainMessage2.what = 100
|
||||||
|
obtainMessage2.obj = str
|
||||||
|
mHandler.sendMessage(obtainMessage2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateWeatherInfo() {
|
||||||
|
mHandler.removeCallbacks(mWeatherRunnable)
|
||||||
|
mHandler.postDelayed(mWeatherRunnable, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow()
|
||||||
|
if (mWeatherObserver != null) {
|
||||||
|
mContext.contentResolver.unregisterContentObserver(mWeatherObserver)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user