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

fix:尝试修复歌词滚动过头问题 #513

Closed
wants to merge 1 commit into from
Closed
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
40 changes: 40 additions & 0 deletions app/src/main/kotlin/statusbar/lyric/hook/module/SystemUILyric.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class SystemUILyric : BaseHook() {
}
private var theoreticalWidth: Int = 0
private lateinit var point: Point
private var lyricwidthmax : Float = 0f


private val displayMetrics: DisplayMetrics by lazy { context.resources.displayMetrics }
Expand Down Expand Up @@ -247,6 +248,7 @@ class SystemUILyric : BaseHook() {
private var defaultDisplay: Any? = null
private var mCentralSurfacesImpl: Any? = null
private var notificationBigTime: View? = null
private var status_barLayout: LinearLayout? = null

@SuppressLint("DiscouragedApi", "NewApi")
override fun init() {
Expand Down Expand Up @@ -827,6 +829,14 @@ class SystemUILyric : BaseHook() {
if (lyric.isEmpty()) return
if (isHiding || isScreenLock) return

/** 左状态栏ViewGroup 获取*/
val rootView = clockView.parent.parentForAccessibility as ViewGroup
val container = context.resources.getIdentifier("status_bar_contents", "id", context.packageName)
status_barLayout = rootView.findViewById<LinearLayout>(container)
targetView = (clockView.parent as LinearLayout).apply {
gravity = Gravity.CENTER
}

"lyric:$lyric".log()
isStop = false
isPlaying = true
Expand Down Expand Up @@ -866,6 +876,36 @@ class SystemUILyric : BaseHook() {
outAnimation = LyricViewTools.switchViewOutAnima(animation, duration)
}
setText(lyric)

if (status_barLayout != null){
val lywidth = status_barLayout!!.width.toFloat()
val maxtest = ((lywidth / 2 ) - 90f )
if (maxtest <= targetView.width.toFloat()){
lyricwidthmax = maxtest
} else {
lyricwidthmax = targetView.width.toFloat() + 9f
}
"lyricwidthmax: ${lyricwidthmax} abc${lywidth} ccc $maxtest,".log()
if (config.lyricWidth == 0) {
lyricView.setMaxLyricViewWidth(lyricwidthmax - if (config.iconSwitch) config.iconStartMargins.toFloat() + iconView.width else 0f)
} else {
var width = scaleWidth().toFloat() + config.lyricEndMargins + config.lyricStartMargins
if (width > lyricwidthmax ) {
width = lyricwidthmax
}
lyricView.setMaxLyricViewWidth(width)
}
} else {
if (config.lyricWidth == 0) {
lyricView.setMaxLyricViewWidth(targetView.width.toFloat() - if (config.iconSwitch) config.iconStartMargins.toFloat() + iconView.width else 0f)
} else {
var width = scaleWidth().toFloat() + config.lyricEndMargins + config.lyricStartMargins
if (width > targetView.width) {
width = targetView.width.toFloat()
}
lyricView.setMaxLyricViewWidth(width)
}
}
}
}
}
Expand Down
Loading