Skip to content

Commit

Permalink
opt: 优化焦点通知 隐藏/显示 效果 (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX authored Nov 19, 2024
1 parent 1c3bca2 commit 4011513
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
60 changes: 31 additions & 29 deletions app/src/main/kotlin/statusbar/lyric/hook/module/SystemUILyric.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class SystemUILyric : BaseHook() {
private var isRandomAnima: Boolean = false
private var focusedNotify: Any? = null
private var canHideFocusNotify = false
private var isOS1FocusNotifyShowing = false // OS1 不要支持隐藏焦点通知
val isReally by lazy { this@SystemUILyric::clockView.isInitialized }

private var themeMode: Int by observableChange(0) { oldValue, _ ->
Expand Down Expand Up @@ -381,16 +382,16 @@ class SystemUILyric : BaseHook() {

false -> {
if (config.clickStatusBarToHideLyric) {
if (isOS1FocusNotifyShowing) return@before
if (shouldControlFocusNotify()) {
if (isHiding && shouldOpenFocusNotify(motionEvent)) {
if (!isHideFocusNotify && shouldOpenFocusNotify(motionEvent)) {
"should open focus notify".log()
return@before
}
}
val isClick = motionEvent.eventTime - motionEvent.downTime < 200
if (isClick && isPlaying) {
moduleRes.getString(R.string.click_status_bar_to_hide_lyric).log()
isHiding.log()
if (isHiding && lastLyric.isNotEmpty()) {
isHiding = false
hookParam.result = true
Expand All @@ -410,6 +411,7 @@ class SystemUILyric : BaseHook() {
showFocusNotifyIfNeed()
}
}
"change to hide: $isHiding".log()
}
}
}
Expand All @@ -429,11 +431,9 @@ class SystemUILyric : BaseHook() {
val mode = hook.result as Int
val mIsFullscreen = hook.thisObject.getObjectField("mIsFullscreen") as Boolean
if (mIsFullscreen && (mode == 0 || mode == 6)) {
if (!isHiding) {
if (isPlaying) {
shouldHiding(true)
hideLyric()
}
if (isPlaying) {
shouldHiding(true)
hideLyric()
}
} else if ((!mIsFullscreen && mode == 0) || (mIsFullscreen && mode == 1))
shouldHiding(false)
Expand All @@ -450,54 +450,57 @@ class SystemUILyric : BaseHook() {
}
}
}
}
loadClassOrNull("com.android.systemui.statusbar.phone.FocusedNotifPromptController").isNotNull {
it.methodFinder().filterByName("updateVisibility\$1").firstOrNull().ifNotNull { method ->
method.createHook {
before { hook ->
if (isHideFocusNotify && canHideFocusNotify) {
hook.result = null
"update visibility isHiding!".log()

it.declaredMethods.filter { method ->
(method.name == "updateVisibility\$1" || method.name == "showImmediately" || method.name == "hideImmediately" ||
method.name == "cancelFolme" || method.name == "setIsFocusedNotifPromptShowing")
}
.forEach { method ->
method.createHook {
before { hook ->
if (isHideFocusNotify) {
hook.result = null
"update focus notify visibility is hiding!".log()
}
}
}
}
}
}

val shouldShowMethod = loadClassOrNull("com.android.systemui.statusbar.phone.FocusedNotifPromptController").ifNotNull {
it.declaredMethods.firstOrNull { method -> method.name == "shouldShow" }
}
if (shouldShowMethod != null) {
canHideFocusNotify = true
(shouldShowMethod as Method).createHook {
after { hook ->
val show = hook.result as Boolean
if (show) {
if (!isHiding) {
if (isPlaying) {
shouldHiding(true)
hideLyric()
}
if (isPlaying && !isHideFocusNotify) {
shouldHiding(true)
hideLyric()
}
} else
shouldHiding(false)
"new focus notify is ${if (show) "show" else "hide"}".log()
}
}
} else {
canHideFocusNotify = false
loadClassOrNull("com.android.systemui.statusbar.phone.FocusedNotifPromptController\$2").isNotNull {
it.methodFinder().filterByName("handleMessage").first().createHook {
before { hook ->
val message = hook.args[0] as Message
if (message.what == 1003) {
val show = shouldShow()
if (show) {
if (!isHiding) {
if (isPlaying) {
shouldHiding(true)
hideLyric()
}
if (isPlaying) {
isOS1FocusNotifyShowing = true
shouldHiding(true)
hideLyric()
}
} else {
isOS1FocusNotifyShowing = false
shouldHiding(false)
}
"focus notify is ${if (show) "show" else "hide"}".log()
Expand Down Expand Up @@ -528,11 +531,11 @@ class SystemUILyric : BaseHook() {
val mIcon = focusedNotify!!.getObjectField("mIcon")
val mContent = focusedNotify!!.getObjectField("mContent")
if (mIcon == null || mContent == null) return
isHideFocusNotify = false
focusedNotify!!.callMethod("cancelFolme")
focusedNotify!!.callMethod("showImmediately", mIcon)
focusedNotify!!.callMethod("showImmediately", mContent)
focusedNotify!!.callMethod("setIsFocusedNotifPromptShowing", true)
isHideFocusNotify = false
"show focus notify!".log()
}

Expand All @@ -544,10 +547,8 @@ class SystemUILyric : BaseHook() {
val mCurrentNotifyBean = focusedNotify!!.getObjectField("mCurrentNotifBean") ?: return false
val mIsHeadsUpShowing = focusedNotify!!.getObjectField("mIsHeadsUpShowing") as Boolean
return if (focusedNotify!!.javaClass.declaredMethods.firstOrNull { it.name == "shouldShow" } != null) {
canHideFocusNotify = true
focusedNotify!!.callMethod("shouldShow", mCurrentNotifyBean, mIsHeadsUpShowing) as Boolean
} else {
canHideFocusNotify = false
!(focusedNotify!!.getObjectField("mIsHeadsUpShowing") as Boolean
|| mCurrentNotifyBean == null || mCurrentNotifyBean.getObjectField("headsUp") as Boolean ||
(TextUtils.equals(
Expand All @@ -559,6 +560,7 @@ class SystemUILyric : BaseHook() {

private fun shouldOpenFocusNotify(motionEvent: MotionEvent): Boolean {
if (!shouldControlFocusNotify()) return false
if (!shouldShow()) return false
val focusedNotifyPromptView = focusedNotify!!.getObjectField("mView") ?: return false

val x = motionEvent.rawX
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/kotlin/statusbar/lyric/tools/Tools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ object Tools {
return XposedHelpers.getObjectField(this, fieldName)
}

fun Any?.callMethod(methodName: String, vararg args: Any): Any? {
fun Any.setObjectField(fieldName: String, value: Any?) {
XposedHelpers.setObjectField(this, fieldName, value)
}

fun Any.callMethod(methodName: String, vararg args: Any): Any? {
return XposedHelpers.callMethod(this, methodName, *args)
}

Expand Down

0 comments on commit 4011513

Please sign in to comment.