mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-12 11:21:18 +08:00
simplify NotificationWeather.kt
This commit is contained in:
@@ -6,110 +6,59 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.lt2333.simplicitytools.util.XSPUtils
|
import com.github.kyuubiran.ezxhelper.utils.loadClass
|
||||||
|
import com.lt2333.simplicitytools.util.*
|
||||||
import com.lt2333.simplicitytools.view.WeatherView
|
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.XposedHelpers
|
|
||||||
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
||||||
|
|
||||||
class NotificationWeather : IXposedHookLoadPackage {
|
class NotificationWeather : IXposedHookLoadPackage {
|
||||||
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
|
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
|
||||||
|
hasEnable("notification_weather") {
|
||||||
|
var mWeatherView: TextView? = null
|
||||||
|
val isDisplayCity = XSPUtils.getBoolean("notification_weather_city", false)
|
||||||
|
"com.android.systemui.qs.MiuiNotificationHeaderView".hookAfterMethod(lpparam.classLoader, "onFinishInflate") {
|
||||||
|
val viewGroup = it.thisObject as ViewGroup
|
||||||
|
val context = viewGroup.context
|
||||||
|
val layoutParam = loadClass("androidx.constraintlayout.widget.ConstraintLayout\$LayoutParams")
|
||||||
|
.getConstructor(Int::class.java, Int::class.java).newInstance(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
) as ViewGroup.MarginLayoutParams
|
||||||
|
layoutParam.setObjectField("bottomToTop", context.resources.getIdentifier("date_time", "id", context.packageName))
|
||||||
|
layoutParam.setObjectField("startToEnd", context.resources.getIdentifier("big_time", "id", context.packageName))
|
||||||
|
|
||||||
var mWeatherView: TextView? = null
|
layoutParam.marginStart = context.resources.getDimensionPixelSize(
|
||||||
|
context.resources.getIdentifier("notification_panel_time_date_space", "dimen", context.packageName)
|
||||||
if (!XSPUtils.getBoolean("notification_weather", false)) return
|
|
||||||
|
|
||||||
val isDisplayCity = XSPUtils.getBoolean("notification_weather_city", false)
|
|
||||||
|
|
||||||
val classIfExists = XposedHelpers.findClassIfExists(
|
|
||||||
"com.android.systemui.qs.MiuiNotificationHeaderView",
|
|
||||||
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(
|
mWeatherView = WeatherView(context, isDisplayCity).apply {
|
||||||
layout,
|
setTextAppearance(context.resources.getIdentifier("TextAppearance.QSControl.Date", "style", context.packageName))
|
||||||
"startToEnd",
|
layoutParams = layoutParam
|
||||||
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 = WeatherView(viewGroup.context, isDisplayCity).also {
|
|
||||||
it.setTextAppearance(
|
|
||||||
viewGroup.context.resources.getIdentifier(
|
|
||||||
"TextAppearance.QSControl.Date",
|
|
||||||
"style",
|
|
||||||
viewGroup.context.packageName
|
|
||||||
)
|
|
||||||
)
|
|
||||||
it.layoutParams = layout
|
|
||||||
}
|
}
|
||||||
viewGroup.addView(mWeatherView)
|
viewGroup.addView(mWeatherView)
|
||||||
|
|
||||||
(mWeatherView as WeatherView).setOnClickListener {
|
(mWeatherView as WeatherView).setOnClickListener {
|
||||||
try {
|
try {
|
||||||
val intent = Intent()
|
val intent = Intent().apply {
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
intent.component = ComponentName(
|
component = ComponentName("com.miui.weather2", "com.miui.weather2.ActivityWeatherMain")
|
||||||
"com.miui.weather2",
|
}
|
||||||
"com.miui.weather2.ActivityWeatherMain"
|
context.startActivity(intent)
|
||||||
)
|
|
||||||
viewGroup.context.startActivity(intent)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Toast.makeText(viewGroup.context, "启动失败", Toast.LENGTH_LONG).show()
|
Toast.makeText(context, "启动失败", Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
//解决横屏重叠
|
||||||
//解决横屏重叠
|
"com.android.systemui.qs.MiuiNotificationHeaderView".hookAfterMethod(lpparam.classLoader, "updateLayout") {
|
||||||
XposedHelpers.findAndHookMethod(classIfExists, "updateLayout", object : XC_MethodHook() {
|
val mOrientation = it.thisObject.getObjectField("mOrientation") as Int
|
||||||
override fun afterHookedMethod(param: MethodHookParam) {
|
|
||||||
super.afterHookedMethod(param)
|
|
||||||
val mOrientation =
|
|
||||||
XposedHelpers.getObjectField(param.thisObject, "mOrientation") as Int
|
|
||||||
if (mOrientation == 1) {
|
if (mOrientation == 1) {
|
||||||
mWeatherView!!.visibility = View.VISIBLE
|
mWeatherView!!.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
mWeatherView!!.visibility = View.GONE
|
mWeatherView!!.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user