Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重构移动网络类型图标显示逻辑 && 为通知中心的天气文本添加动画 #1009

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,10 @@
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.icon.all.WifiNetworkIndicator;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.icon.v.FocusNotifLyric;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.icon.v.HideFakeStatusBar;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.layout.StatusBarLayout;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.model.DualRowSignalHook;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.model.DualRowSignalHookV;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.model.MobileNetwork;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.model.MobilePublicHook;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.model.MobileTypeTextCustom;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.model.MobileTypeSingle2Hook;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.model.MobilePublicHookV;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.network.NetworkSpeedSec;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.network.NetworkSpeedSpacing;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.network.news.NewNetworkSpeed;
Expand Down Expand Up @@ -172,8 +169,8 @@ public void handleLoadPackage() {
mPrefsMap.getBoolean("system_ui_status_bar_mobile_indicator") ||
mPrefsMap.getStringAsInt("system_ui_status_bar_icon_small_hd", 0) != 0 ||
mPrefsMap.getStringAsInt("system_ui_status_bar_icon_big_hd", 0) != 0;
// initHook(new DualRowSignalHook(), mPrefsMap.getBoolean("system_ui_statusbar_network_icon_enable"));
initHook(new DualRowSignalHookV(), mPrefsMap.getBoolean("system_ui_statusbar_network_icon_enable"));
initHook(new MobilePublicHookV(), true);
initHook(MobileTypeSingle2Hook.INSTANCE, isEnableMobilePublic);
initHook(MobileTypeTextCustom.INSTANCE, !Objects.equals(mPrefsMap.getString("system_ui_status_bar_mobile_type_custom", ""), ""));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.sevtinge.hyperceiler.module.hook.systemui

import com.github.kyuubiran.ezxhelper.*
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.model.MobileTypeSingle2Hook.findClass
import com.sevtinge.hyperceiler.utils.*

@Suppress("MemberVisibilityCanBePrivate")
object Dependency {

Check warning on line 8 in app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/Dependency.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/Dependency.kt#L8

Dependency is missing required documentation.
private const val DEPENDENCY = "com.android.systemui.Dependency"
val sDependency by lazy {
findClass(DEPENDENCY, EzXHelper.classLoader).getStaticObjectField("sDependency")
}
val mMiuiLegacyDependency : Any?
get() = sDependency?.getObjectField("mMiuiLegacyDependency")
val mDependencies : Map<*, *>?
get() = sDependency?.getObjectField("mDependencies") as Map<*, *>?

fun getDependencyInner(depClz: Class<*>): Any? {

Check warning on line 18 in app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/Dependency.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/Dependency.kt#L18

The function getDependencyInner is missing documentation.
return sDependency?.callMethod("getDependencyInner", depClz)
}

fun getDependencyInner(depClzName: String): Any? {

Check warning on line 22 in app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/Dependency.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/Dependency.kt#L22

The function getDependencyInner is missing documentation.
return getDependencyInner(findClass(depClzName, EzXHelper.classLoader))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,173 @@
import android.widget.*
import androidx.constraintlayout.widget.*
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClassOrNull
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.utils.*
import com.sevtinge.hyperceiler.utils.api.*
import com.sevtinge.hyperceiler.utils.devicesdk.*
import com.sevtinge.hyperceiler.utils.devicesdk.DisplayUtils.*
import com.sevtinge.hyperceiler.view.*


@SuppressLint("DiscouragedApi", "ServiceCast", "StaticFieldLeak")
object NotificationWeather : BaseHook() {
@SuppressLint("DiscouragedApi", "ServiceCast")
private var mWeatherView: TextView? = null
private var mWeatherViewFolme: Any? = null
private var mConstraintLayout: ConstraintLayout? = null
private val isDisplayCity by lazy {
mPrefsMap.getBoolean("system_ui_control_center_show_weather_city")
}

override fun init() {
var mWeatherView: TextView? = null
var mConstraintLayout: ConstraintLayout? = null
val isDisplayCity = mPrefsMap.getBoolean("system_ui_control_center_show_weather_city")
if (isMoreHyperOSVersion(2f)) {
newNotificationWeather()
} else {
oldNotificationWeather()
}

}

private fun newNotificationWeather() {

Check warning on line 55 in app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/NotificationWeather.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/NotificationWeather.kt#L55

The function newNotificationWeather is too long (127). The maximum length is 60.
loadClass("com.android.systemui.controlcenter.shade.CombinedHeaderController").constructors
.single().createHook {
after { param ->
val headerController = param.thisObject
val notificationDateTime =
headerController.getObjectFieldAs<View>("notificationDateTime")

Check warning on line 61 in app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/NotificationWeather.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/NotificationWeather.kt#L61

Multiple occurrences of the same string literal within a single file detected. Prefer extracting the string literal into a property or constant.
val context = notificationDateTime.context

val layoutParam = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)

layoutParam.gravity = Gravity.BOTTOM
layoutParam.marginStart = context.resources.getDimensionPixelSize(
context.resources.getIdentifier(
"notification_panel_time_date_space",
"dimen",
context.packageName
)
) + dp2px(5f)

mWeatherView = WeatherView(context, isDisplayCity).apply {
setTextAppearance(
context.resources.getIdentifier(
"TextAppearance.QSControl.Date",
"style",
context.packageName
)
)
layoutParams = layoutParam
}

val dateTimeParent = notificationDateTime.parent as ViewGroup
dateTimeParent.addView(mWeatherView)

mWeatherView?.let {
it.setOnClickListener {
try {
val intent = Intent().apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
component = ComponentName(
"com.miui.weather2",
"com.miui.weather2.ActivityWeatherMain"
)
}
context.startActivity(intent)
} catch (e: Exception) {
Toast.makeText(context, "启动失败", Toast.LENGTH_LONG).show()
}
}

mWeatherViewFolme = loadClass("miuix.animation.Folme")
.callStaticMethod("useAt", arrayOf<View>(it))
}
}
}

loadClass("com.android.systemui.controlcenter.shade.CombinedHeaderController").methodFinder()
.filterByName("onSwitchProgressChanged")
.filterByParamTypes(Float::class.java)
.first().createHook {
after { param ->
val headerController = param.thisObject
val dateTime = headerController.getObjectFieldAs<View>("notificationDateTime")
mWeatherView?.translationX = dateTime.translationX
mWeatherView?.translationY = dateTime.translationY
mWeatherView?.visibility = dateTime.visibility
}
}

val expandControllerClz = loadClass(
"com.android.systemui.controlcenter.shade.NotificationHeaderExpandController"
)
expandControllerClz.constructors
.single().createHook {
after { param ->
val expandController = param.thisObject
expandController.getObjectFieldAs<Any>("notificationCallback")::class.java
.methodFinder()
.filterByName("onExpansionChanged")
.first()
.createHook {
after {
val dateTime =
expandController.getObjectFieldAs<Any>("headerController")
.callMethodAs<Any>("get")
.getObjectFieldAs<View>("notificationDateTime")

mWeatherView?.translationX = dateTime.translationX
mWeatherView?.translationY = dateTime.translationY
}
}
}
}
expandControllerClz.methodFinder()
.filterByName("access\$startFolmeAnimationAlpha")
.filterByParamCount(5)
.single().createHook {
before { param ->
val view = param.args[1] as View
val context = view.context
val id = context.resources.getIdentifier("date_time", "id", context.packageName)

Check warning on line 158 in app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/NotificationWeather.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/NotificationWeather.kt#L158

Multiple occurrences of the same string literal within a single file detected. Prefer extracting the string literal into a property or constant.
if (view.id == id) {
expandControllerClz.callStaticMethod(
"access\$startFolmeAnimationAlpha",
param.args[0],
mWeatherView,
mWeatherViewFolme,
param.args[3],
param.args[4],
)
}
}
}

expandControllerClz.methodFinder()
.filterByName("access\$startFolmeAnimationTranslationX")
.single().createHook {
before { param ->
val view = param.args[1] as View
val context = view.context
val id = context.resources.getIdentifier("date_time", "id", context.packageName)
if (view.id == id) {
expandControllerClz.callStaticMethod(
"access\$startFolmeAnimationTranslationX",
param.args[0],
mWeatherView,
mWeatherViewFolme,
param.args[3],
param.args[4],
)
}
}
}
}

private fun oldNotificationWeather() {

Check warning on line 193 in app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/NotificationWeather.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/NotificationWeather.kt#L193

The function oldNotificationWeather is too long (101). The maximum length is 60.
loadClass("com.android.systemui.qs.MiuiNotificationHeaderView").methodFinder()
.filterByName("onFinishInflate")
.single().createHook {
Expand All @@ -47,18 +199,22 @@
val context = viewGroup.context

// MIUI编译时间大于 2022-03-12 00:00:00 且为内测版
if ((PropUtils.getProp(context, "ro.build.date.utc").toInt() >= 1647014400 &&
!PropUtils.getProp(context, "ro.build.version.incremental")
.endsWith("XM")) &&
!isMoreHyperOSVersion(1f)
) {
if (!isMoreHyperOSVersion(1f)) {
// 获取原组件
val bigTimeId =
context.resources.getIdentifier("big_time", "id", context.packageName)
context.resources.getIdentifier(
"big_time",
"id",
context.packageName
)
val bigTime: TextView = viewGroup.findViewById(bigTimeId)

val dateTimeId =
context.resources.getIdentifier("date_time", "id", context.packageName)
context.resources.getIdentifier(
"date_time",
"id",
context.packageName
)
val dateTime: TextView = viewGroup.findViewById(dateTimeId)

// 创建新布局
Expand All @@ -76,7 +232,9 @@
}

mConstraintLayout =
ConstraintLayout(context).also { it.layoutParams = mConstraintLayoutLp }
ConstraintLayout(context).also {
it.layoutParams = mConstraintLayoutLp
}

(bigTime.parent as ViewGroup).addView(mConstraintLayout, 0)

Expand Down Expand Up @@ -139,56 +297,6 @@

(mWeatherView as WeatherView).layoutParams = mweatherviewLp

} else {
val layoutParam = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)

layoutParam.marginStart = context.resources.getDimensionPixelSize(
context.resources.getIdentifier(
"notification_panel_time_date_space",
"dimen",
context.packageName
)
) + dp2px(5f)

mWeatherView = WeatherView(context, isDisplayCity).apply {
setTextAppearance(
context.resources.getIdentifier(
"TextAppearance.QSControl.Date",
"style",
context.packageName
)
)
layoutParams = layoutParam
}

val dateTime = viewGroup.findViewById<View>(
context.resources.getIdentifier(
"date_time",
"id",
context.packageName
)
)

val dateTimeParent = dateTime.parent as ViewGroup
dateTimeParent.addView(mWeatherView)
}

(mWeatherView as WeatherView).setOnClickListener {
try {
val intent = Intent().apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
component = ComponentName(
"com.miui.weather2",
"com.miui.weather2.ActivityWeatherMain"
)
}
context.startActivity(intent)
} catch (e: Exception) {
Toast.makeText(context, "启动失败", Toast.LENGTH_LONG).show()
}
}
}
}
Expand All @@ -198,26 +306,12 @@
.single().createHook {
after {
val viewGroup = it.thisObject as ViewGroup
val context = viewGroup.context
val mOrientation = viewGroup.getObjectField("mOrientation") as Int
// MIUI编译时间大于 2022-03-12 00:00:00 且为内测版
if (PropUtils.getProp(context, "ro.build.date.utc").toInt() >= 1647014400 &&
!PropUtils.getProp(context, "ro.build.version.incremental").endsWith(
"DEV"
) &&
!PropUtils.getProp(context, "ro.build.version.incremental").endsWith("XM")
) {
if (mOrientation == 1) {
mConstraintLayout!!.visibility = View.VISIBLE
} else {
mConstraintLayout!!.visibility = View.GONE
}

if (mOrientation == 1) {
mWeatherView!!.visibility = View.VISIBLE
} else {
if (mOrientation == 1) {
mWeatherView!!.visibility = View.VISIBLE
} else {
mWeatherView!!.visibility = View.GONE
}
mWeatherView!!.visibility = View.GONE
}
}
}
Expand Down
Loading