修复歌词位置显示问题

This commit is contained in:
lyswhut 2021-08-07 09:57:52 +08:00
parent ff4790b534
commit a2e64dbda3
2 changed files with 21 additions and 19 deletions

View File

@ -17,13 +17,7 @@ public class Lyric extends LyricPlayer {
ReactApplicationContext reactAppContext;
boolean isShowLyric = false;
boolean isLock = false;
String themeColor = "#07c556";
String lastText = "LX Music ^-^";
int lyricViewX = 0;
int lyricViewY = 0;
String textX = "LEFT";
String textY = "TOP";
Lyric(ReactApplicationContext reactContext) {
this.reactAppContext = reactContext;
@ -77,7 +71,7 @@ public class Lyric extends LyricPlayer {
lyricView.runOnUiThread(new Runnable() {
@Override
public void run() {
lyricView.showLyricView(isLock, themeColor, lyricViewX, lyricViewY, textX, textY);
lyricView.showLyricView();
lyricView.setLyric(lastText);
setTempPause(false);
}
@ -87,12 +81,6 @@ public class Lyric extends LyricPlayer {
public void showLyric(boolean isLock, String themeColor, int lyricViewX, int lyricViewY, String textX, String textY) {
if (lyricEvent == null) lyricEvent = new LyricEvent(reactAppContext);
if (lyricView == null) lyricView = new LyricView(reactAppContext, lyricEvent);
this.isLock = isLock;
this.themeColor = themeColor;
this.lyricViewX = lyricViewX;
this.lyricViewY = lyricViewY;
this.textX = textX;
this.textY = textY;
lyricView.showLyricView(isLock, themeColor, lyricViewX, lyricViewY, textX, textY);
isShowLyric = true;
}
@ -129,13 +117,11 @@ public class Lyric extends LyricPlayer {
public void lockLyric() {
if (lyricView == null) return;
this.isLock = true;
lyricView.lockView();
}
public void unlockLyric() {
if (lyricView == null) return;
this.isLock = false;
lyricView.unlockView();
}
@ -145,12 +131,9 @@ public class Lyric extends LyricPlayer {
public void setColor(String color) {
lyricView.setColor(color);
this.themeColor = color;
}
public void setLyricTextPosition(String positionX, String positionY) {
this.textX = positionX;
this.textY = positionY;
lyricView.setLyricTextPosition(positionX, positionY);
}
}

View File

@ -43,12 +43,18 @@ public class LyricView extends Activity implements View.OnTouchListener {
private float preY = 0;
// private static boolean isVibrated = false;
private boolean isLock = false;
private String themeColor = "#07c556";
private String lastText = "LX Music ^-^";
private String textX = "LEFT";
private String textY = "TOP";
LyricView(ReactApplicationContext reactContext, LyricEvent lyricEvent) {
this.reactContext = reactContext;
this.lyricEvent = lyricEvent;
}
private void sendPositionEvent(int x, int y) {
public void sendPositionEvent(int x, int y) {
WritableMap params = Arguments.createMap();
params.putInt("x", x);
params.putInt("y", y);
@ -76,6 +82,19 @@ public class LyricView extends Activity implements View.OnTouchListener {
// }
public void showLyricView(boolean isLock, String themeColor, int lyricViewX, int lyricViewY, String textX, String textY) {
this.isLock = isLock;
this.themeColor = themeColor;
this.prevViewX = lyricViewX;
this.prevViewY = lyricViewY;
this.textX = textX;
this.textY = textY;
handleShowLyric(isLock, themeColor, lyricViewX, lyricViewY, textX, textY);
}
public void showLyricView() {
handleShowLyric(isLock, themeColor, prevViewX, prevViewY, textX, textY);
}
private void handleShowLyric(boolean isLock, String themeColor, int lyricViewX, int lyricViewY, String textX, String textY) {
if (windowManager == null) {
windowManager = (WindowManager) reactContext.getSystemService(Context.WINDOW_SERVICE);
//设置TextView的属性