|
@@ -6,6 +6,7 @@ import android.graphics.Canvas
|
|
|
import android.graphics.Color
|
|
|
import android.graphics.Path
|
|
|
import android.util.AttributeSet
|
|
|
+import android.util.Log
|
|
|
import android.view.animation.LinearInterpolator
|
|
|
|
|
|
/**
|
|
@@ -34,6 +35,8 @@ class SongLyricTextView @JvmOverloads constructor(
|
|
|
* */
|
|
|
private var consumeWidth: Float = 0f
|
|
|
|
|
|
+ private var normalWidth:Float = 0f;
|
|
|
+
|
|
|
/**
|
|
|
* 是否正在播放中
|
|
|
* */
|
|
@@ -56,6 +59,7 @@ class SongLyricTextView @JvmOverloads constructor(
|
|
|
animator.interpolator = LinearInterpolator()
|
|
|
animator.addUpdateListener {
|
|
|
consumeWidth = it.animatedValue as Float
|
|
|
+ normalWidth = oldStartWidth
|
|
|
invalidate()
|
|
|
}
|
|
|
animator
|
|
@@ -74,27 +78,32 @@ class SongLyricTextView @JvmOverloads constructor(
|
|
|
path.reset()
|
|
|
val lineCount = layout.lineCount
|
|
|
val content = text.toString()
|
|
|
+
|
|
|
for (i in 0 until lineCount) {
|
|
|
// 计算一行文字的宽度
|
|
|
val lineWidth = mPaint.measureText(
|
|
|
content.substring(layout.getLineStart(i), layout.getLineEnd(i))
|
|
|
)
|
|
|
-
|
|
|
- if (lineWidth <= consumeWidth) {
|
|
|
+ if (lineWidth < consumeWidth) {
|
|
|
// 如果是之前已经变色区域,直接添加到path中
|
|
|
+ if (normalWidth<lineWidth&&normalWidth>0){
|
|
|
+ path.addRect(
|
|
|
+ layout.getLineLeft(i)+normalWidth,
|
|
|
+ layout.getLineTop(i).toFloat(),
|
|
|
+ layout.getLineRight(i),
|
|
|
+ layout.getLineBottom(i).toFloat(),
|
|
|
+ Path.Direction.CCW
|
|
|
+ )
|
|
|
+ normalWidth = 0f;
|
|
|
+ }
|
|
|
consumeWidth -= lineWidth
|
|
|
-// path.addRect(
|
|
|
-// layout.getLineLeft(i),
|
|
|
-// layout.getLineTop(i).toFloat(),
|
|
|
-// layout.getLineRight(i),
|
|
|
-// layout.getLineBottom(i).toFloat(),
|
|
|
-// Path.Direction.CCW
|
|
|
-// )
|
|
|
+ if (normalWidth>0f)normalWidth -= lineWidth
|
|
|
+// if(oldStartWidth<0f) oldStartWidth = 0f
|
|
|
} else {
|
|
|
// 如果该行正好是要变色的行,直接改变颜色
|
|
|
// 把需要的consumeWidth放入path中
|
|
|
path.addRect(
|
|
|
- layout.getLineLeft(i),
|
|
|
+ layout.getLineLeft(i)+normalWidth,
|
|
|
layout.getLineTop(i).toFloat(),
|
|
|
layout.getLineLeft(i) + consumeWidth,
|
|
|
layout.getLineBottom(i).toFloat(),
|
|
@@ -201,4 +210,14 @@ class SongLyricTextView @JvmOverloads constructor(
|
|
|
// invalidate()
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 重置
|
|
|
+ */
|
|
|
+ fun release(){
|
|
|
+ isPlaying = false
|
|
|
+ isNormal = false
|
|
|
+ animator.cancel()
|
|
|
+ invalidate()
|
|
|
+ }
|
|
|
+
|
|
|
}
|