Skip to content

Commit

Permalink
修复开关图标导致滚动距离不正确
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Sep 19, 2024
1 parent c15b4c8 commit eaa3ab9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
14 changes: 9 additions & 5 deletions app/src/main/java/statusbar/lyric/hook/module/SystemUILyric.kt
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ class SystemUILyric : BaseHook() {
targetView.addView(lyricLayout)
}
if (config.lyricWidth == 0) {
lyricView.maxLyricWidth(targetView.width.toFloat())
lyricView.setMaxLyricViewWidth(targetView.width.toFloat())
} else {
lyricView.maxLyricWidth(scaleWidth().toFloat() + config.lyricEndMargins + config.lyricStartMargins)
lyricView.setMaxLyricViewWidth(scaleWidth().toFloat() + config.lyricEndMargins + config.lyricStartMargins)
}
if (isHyperOS() && config.mHyperOSTexture) {
val blurRadio = config.mHyperOSTextureRadio
Expand Down Expand Up @@ -533,7 +533,6 @@ class SystemUILyric : BaseHook() {
}

private fun changeIcon(it: ExtraData) {
lyricView.iconWidth(iconView.width.toFloat())
if (!iconSwitch) return
if (config.changeAllIcons.isNotEmpty()) {
lastBase64Icon = config.changeAllIcons
Expand All @@ -545,6 +544,11 @@ class SystemUILyric : BaseHook() {
config.getDefaultIcon(it.packageName)
}
}
if (config.lyricWidth == 0) {
lyricView.setMaxLyricViewWidth(targetView.width.toFloat())
} else {
lyricView.setMaxLyricViewWidth(scaleWidth().toFloat() + config.lyricEndMargins + config.lyricStartMargins)
}
}

private fun hideLyric(anim: Boolean = true) {
Expand Down Expand Up @@ -584,9 +588,9 @@ class SystemUILyric : BaseHook() {
}
}
if (config.lyricWidth == 0) {
maxLyricWidth(targetView.width.toFloat())
lyricView.setMaxLyricViewWidth(targetView.width.toFloat())
} else {
maxLyricWidth(scaleWidth().toFloat() + config.lyricEndMargins + config.lyricStartMargins)
lyricView.setMaxLyricViewWidth(scaleWidth().toFloat() + config.lyricEndMargins + config.lyricStartMargins)
}
setLetterSpacings(config.lyricLetterSpacing / 100f)
strokeWidth(config.lyricStrokeWidth / 100f)
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/java/statusbar/lyric/view/LyricSwitchView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ open class LyricSwitchView(context: Context) : TextSwitcher(context) {
}
}

fun maxLyricWidth(width: Float) {
applyToAllViews { it.maxViewWidth(width) }
fun setMaxLyricViewWidth(width: Float) {
applyToAllViews { it.setMaxViewWidth(width) }
}

fun setWidth(width: Int) {
Expand All @@ -65,10 +65,6 @@ open class LyricSwitchView(context: Context) : TextSwitcher(context) {
}
}

fun iconWidth(width: Float) {
applyToAllViews { it.iconWidth(width) }
}

fun setTextColor(color: Int) {
applyToAllViews { it.setTextColor(color) }
}
Expand Down
13 changes: 2 additions & 11 deletions app/src/main/java/statusbar/lyric/view/LyricTextView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ class LyricTextView(context: Context) : TextView(context), Choreographer.FrameCa
private var isScrolling = false
private var textLength = 0f
private var viewWidth = 0f
private var iconWidth = 0f
private var scrollSpeed = 4f
private var currentX = 0f
private val iconSwitch = config.iconSwitch
private val lyricStartMargins = config.lyricStartMargins
private val lyricEndMargins = config.lyricEndMargins
private val iconStartMargins = config.iconStartMargins
private val startScrollRunnable = Runnable { Choreographer.getInstance().postFrameCallback(this) }

init {
Expand Down Expand Up @@ -81,7 +78,7 @@ class LyricTextView(context: Context) : TextView(context), Choreographer.FrameCa

private fun updateScrollPosition() {
val realTextLength = textLength + lyricEndMargins + lyricStartMargins
val realLyricWidth = viewWidth - if (iconSwitch) iconWidth + iconStartMargins else 0f
val realLyricWidth = viewWidth
if (realTextLength <= realLyricWidth) {
currentX = 0f
stopScroll()
Expand Down Expand Up @@ -120,13 +117,7 @@ class LyricTextView(context: Context) : TextView(context), Choreographer.FrameCa
this.scrollSpeed = speed
}

fun maxViewWidth(float: Float) {
fun setMaxViewWidth(float: Float) {
viewWidth = float
}

fun iconWidth(width: Float) {
if (config.iconSwitch) {
iconWidth = width
}
}
}

0 comments on commit eaa3ab9

Please sign in to comment.