Skip to content

Commit

Permalink
fix: 修复固定歌词宽度滚动不到位问题
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Dec 31, 2024
1 parent 17333a1 commit 17fdb8a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/src/main/kotlin/statusbar/lyric/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Config {
}
var outLog: Boolean
get() {
return if (BuildConfig.DEBUG) true else config.opt("outlog", true)
return if (BuildConfig.DEBUG) true else config.opt("outlog", false)
}
set(value) {
config.put("outlog", value)
Expand Down
83 changes: 49 additions & 34 deletions app/src/main/kotlin/statusbar/lyric/hook/module/SystemUILyric.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class SystemUILyric : BaseHook() {
private lateinit var mNotificationIconArea: View
private lateinit var mCarrierLabel: View
private lateinit var mPadClockView: View
private val realTargetWidth by lazy { targetView.width.toFloat() - if (config.iconSwitch) config.iconStartMargins.toFloat() + iconView.width else 0f }
private val lyricView: LyricSwitchView by lazy {
object : LyricSwitchView(context) {
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
Expand All @@ -204,7 +205,10 @@ class SystemUILyric : BaseHook() {
} else if (colors.size < 2) {
setTextColor(colors[0])
} else {
val textShader = LinearGradient(0f, 0f, width.toFloat(), 0f, colors.toIntArray(), null, Shader.TileMode.CLAMP)
val textShader = LinearGradient(
0f, 0f, width.toFloat(),
0f, colors.toIntArray(), null, Shader.TileMode.CLAMP
)
setLinearGradient(textShader)
}
}
Expand All @@ -225,7 +229,10 @@ class SystemUILyric : BaseHook() {
LinearLayout(context).apply {
orientation = LinearLayout.HORIZONTAL
gravity = Gravity.CENTER
layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)
layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT
)
addView(iconView)
addView(lyricView)
visibility = View.GONE
Expand Down Expand Up @@ -391,7 +398,8 @@ class SystemUILyric : BaseHook() {
}

MotionEvent.ACTION_UP -> {
val isMove = abs(point.y - motionEvent.rawY.toInt()) > 50 || abs(point.x - motionEvent.rawX.toInt()) > 50
val isMove =
abs(point.y - motionEvent.rawY.toInt()) > 50 || abs(point.x - motionEvent.rawX.toInt()) > 50
val isLongChick = motionEvent.eventTime - motionEvent.downTime > 500
when (isMove) {
true -> {
Expand Down Expand Up @@ -511,9 +519,10 @@ class SystemUILyric : BaseHook() {
}
}

val shouldShowMethod = loadClassOrNull("com.android.systemui.statusbar.phone.FocusedNotifPromptController").ifNotNull {
it.declaredMethods.firstOrNull { method -> method.name == "shouldShow" }
}
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 {
Expand Down Expand Up @@ -663,12 +672,10 @@ class SystemUILyric : BaseHook() {
shouldIgnore = false
}
} else {
!(focusedNotify!!.getObjectField("mIsHeadsUpShowing") as Boolean
|| mCurrentNotifyBean == null || mCurrentNotifyBean.getObjectField("headsUp") as Boolean ||
(TextUtils.equals(
mCurrentNotifyBean.getObjectField("packageName") as CharSequence,
focusedNotify!!.getObjectField("mTopActivityPackageName") as CharSequence
) && !(focusedNotify!!.getObjectField("mRequestHide") as Boolean)))
!(focusedNotify!!.getObjectField("mIsHeadsUpShowing") as Boolean || mCurrentNotifyBean.getObjectField("headsUp") as Boolean || (TextUtils.equals(
mCurrentNotifyBean.getObjectField("packageName") as CharSequence,
focusedNotify!!.getObjectField("mTopActivityPackageName") as CharSequence
) && !(focusedNotify!!.getObjectField("mRequestHide") as Boolean)))
}
}

Expand Down Expand Up @@ -741,17 +748,16 @@ class SystemUILyric : BaseHook() {
val blurRadio = config.mHyperOSTextureRadio
val cornerRadius = cornerRadius(config.mHyperOSTextureCorner.toFloat())
val blendModes = arrayOf(
intArrayOf(106, Color.parseColor(config.mHyperOSTextureBgColor)), intArrayOf(3, Color.parseColor(config.mHyperOSTextureBgColor))
intArrayOf(106, Color.parseColor(config.mHyperOSTextureBgColor)),
intArrayOf(3, Color.parseColor(config.mHyperOSTextureBgColor))
)
lyricLayout.setBackgroundBlur(blurRadio, cornerRadius, blendModes)
}
if (config.lyricWidth == 0) {
lyricView.setMaxLyricViewWidth(targetView.width.toFloat() - if (config.iconSwitch) config.iconStartMargins.toFloat() + iconView.width else 0f)
lyricView.setMaxLyricViewWidth(realTargetWidth)
} else {
var width = scaleWidth().toFloat() + config.lyricEndMargins + config.lyricStartMargins
if (width > targetView.width) {
width = targetView.width.toFloat()
}
if (width > realTargetWidth) width = realTargetWidth
lyricView.setMaxLyricViewWidth(width)
}
themeMode = (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK)
Expand Down Expand Up @@ -876,9 +882,6 @@ class SystemUILyric : BaseHook() {
config.getDefaultIcon(it.packageName)
}
}
if (config.lyricWidth == 0) {
lyricView.setMaxLyricViewWidth(targetView.width.toFloat() - if (config.iconSwitch) config.iconStartMargins.toFloat() + iconView.width else 0f)
}
}

private fun hideLyric(anim: Boolean = true) {
Expand Down Expand Up @@ -906,8 +909,16 @@ class SystemUILyric : BaseHook() {
config.update()
goMainThread(delay) {
lyricView.apply {
setTextSize(TypedValue.COMPLEX_UNIT_SHIFT, if (config.lyricSize == 0) clockView.textSize else config.lyricSize.toFloat())
setPadding(config.lyricStartMargins, config.lyricTopMargins, config.lyricEndMargins, config.lyricBottomMargins)
setTextSize(
TypedValue.COMPLEX_UNIT_SHIFT,
if (config.lyricSize == 0) clockView.textSize else config.lyricSize.toFloat()
)
setPadding(
config.lyricStartMargins,
config.lyricTopMargins,
config.lyricEndMargins,
config.lyricBottomMargins
)
if (config.lyricGradientColor.isEmpty()) {
if (config.lyricColor.isEmpty()) {
when (config.lyricColorScheme) {
Expand All @@ -919,12 +930,10 @@ class SystemUILyric : BaseHook() {
}
}
if (config.lyricWidth == 0) {
lyricView.setMaxLyricViewWidth(targetView.width.toFloat() - if (config.iconSwitch) config.iconStartMargins.toFloat() + iconView.width else 0f)
lyricView.setMaxLyricViewWidth(realTargetWidth)
} else {
var width = scaleWidth().toFloat() + config.lyricEndMargins + config.lyricStartMargins
if (width > targetView.width) {
width = targetView.width.toFloat()
}
if (width > realTargetWidth) width = realTargetWidth
lyricView.setMaxLyricViewWidth(width)
}
setLetterSpacings(config.lyricLetterSpacing / 100f)
Expand All @@ -942,14 +951,17 @@ class SystemUILyric : BaseHook() {
setBackgroundColor(Color.parseColor(config.lyricBackgroundColor))
}
} else {
config.lyricBackgroundColor.trim().split(",").map { Color.parseColor(it.trim()) }.let { colors ->
val gradientDrawable = GradientDrawable(
GradientDrawable.Orientation.LEFT_RIGHT, colors.toIntArray()
).apply {
if (config.lyricBackgroundRadius != 0) cornerRadius = config.lyricBackgroundRadius.toFloat()
config.lyricBackgroundColor.trim().split(",").map { Color.parseColor(it.trim()) }
.let { colors ->
val gradientDrawable = GradientDrawable(
GradientDrawable.Orientation.LEFT_RIGHT, colors.toIntArray()
).apply {
if (config.lyricBackgroundRadius != 0) {
cornerRadius = config.lyricBackgroundRadius.toFloat()
}
}
background = gradientDrawable
}
background = gradientDrawable
}
}
}

Expand All @@ -975,7 +987,10 @@ class SystemUILyric : BaseHook() {
iconView.showView()
iconSwitch = true
iconView.apply {
layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT).apply {
layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT
).apply {
setMargins(config.iconStartMargins, config.iconTopMargins, 0, config.iconBottomMargins)
if (config.iconSize == 0) {
width = clockView.height / 2
Expand Down
5 changes: 2 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
androidGradlePlugin = "8.7.3"
androidx-coreKtx = "1.15.0"
androidx-activity-compose = "1.9.3"
androidx-compose-foundation = "1.7.5"
androidx-navigation-compose = "2.8.4"
androidx-compose-foundation = "1.7.6"
androidx-navigation-compose = "2.8.5"
ezXHelper = "2.2.0"
haze = "1.1.1"
kotlin = "2.1.0"
lyricGetterApi = "6.0.0"
miuix = "0.3.2"
xposed = "82"


[libraries]
androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation", version.ref = "androidx-compose-foundation" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-coreKtx" }
Expand Down

0 comments on commit 17fdb8a

Please sign in to comment.