mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-03 09:02:10 +08:00
修复桌面歌词问题
This commit is contained in:
parent
4d46b47599
commit
4975c4c725
@ -164,11 +164,6 @@ public class Lyric extends LyricPlayer {
|
||||
lyricView.unlockView();
|
||||
}
|
||||
|
||||
public void fixViewPosition() {
|
||||
if (lyricView == null) return;
|
||||
lyricView.fixViewPosition();
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
if (lyricView == null) return;
|
||||
lyricView.setPosition(x, y);
|
||||
|
@ -120,9 +120,6 @@ public class LyricModule extends ReactContextBaseJavaModule {
|
||||
@ReactMethod
|
||||
public void setTextSize(float size) { lyric.setTextSize(size); }
|
||||
|
||||
@ReactMethod
|
||||
public void fixViewPosition() { lyric.fixViewPosition(); }
|
||||
|
||||
@ReactMethod
|
||||
public void setPosition(int x, int y) { lyric.setPosition(x, y); }
|
||||
|
||||
|
@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Point;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
@ -13,6 +14,7 @@ import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.OrientationEventListener;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
@ -60,11 +62,43 @@ public class LyricView extends Activity implements View.OnTouchListener {
|
||||
private int maxLineNum = 5;
|
||||
// private float lineHeight = 1;
|
||||
|
||||
private int mLastRotation;
|
||||
private OrientationEventListener orientationEventListener = null;
|
||||
|
||||
LyricView(ReactApplicationContext reactContext, LyricEvent lyricEvent) {
|
||||
this.reactContext = reactContext;
|
||||
this.lyricEvent = lyricEvent;
|
||||
}
|
||||
|
||||
private void listenOrientationEvent() {
|
||||
if (orientationEventListener == null) {
|
||||
orientationEventListener = new OrientationEventListener(reactContext, SensorManager.SENSOR_DELAY_NORMAL) {
|
||||
@Override
|
||||
public void onOrientationChanged(int orientation) {
|
||||
Display display = windowManager.getDefaultDisplay();
|
||||
int rotation = display.getRotation();
|
||||
if(rotation != mLastRotation){
|
||||
//rotation changed
|
||||
// if (rotation == Surface.ROTATION_90){} // check rotations here
|
||||
// if (rotation == Surface.ROTATION_270){} //
|
||||
// Log.d("Lyric", "rotation: " + rotation);
|
||||
fixViewPosition();
|
||||
}
|
||||
mLastRotation = rotation;
|
||||
}
|
||||
};
|
||||
}
|
||||
// Log.d("Lyric", "orientationEventListener: " + orientationEventListener.canDetectOrientation());
|
||||
if (orientationEventListener.canDetectOrientation()) {
|
||||
orientationEventListener.enable();
|
||||
}
|
||||
}
|
||||
private void removeOrientationEvent() {
|
||||
if (orientationEventListener == null) return;
|
||||
orientationEventListener.disable();
|
||||
// orientationEventListener = null;
|
||||
}
|
||||
|
||||
private int getLayoutParamsFlags() {
|
||||
int flag = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
|
||||
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
|
||||
@ -86,6 +120,33 @@ public class LyricView extends Activity implements View.OnTouchListener {
|
||||
maxHeight = size.y;
|
||||
}
|
||||
|
||||
private void fixViewPosition() {
|
||||
updateWH();
|
||||
|
||||
int width = (int)(maxWidth * widthPercentage);
|
||||
if (layoutParams.width != width) layoutParams.width = width;
|
||||
|
||||
layoutParams.x = (int)(maxWidth * prevViewPercentageX);
|
||||
layoutParams.y = (int)(maxHeight * prevViewPercentageY);
|
||||
|
||||
// int maxX = this.maxWidth - layoutParams.width;
|
||||
// int maxY = this.maxHeight - layoutParams.height;
|
||||
// int x = layoutParams.x;
|
||||
// int y = layoutParams.y;
|
||||
// if (x < 0) x = 0;
|
||||
// else if (x > maxX) x = maxX;
|
||||
// if (y < 0) y = 0;
|
||||
// else if (y > maxY) y = maxY;
|
||||
|
||||
// layoutParams.x = x;
|
||||
// layoutParams.y = y;
|
||||
// Log.d("Lyric", "widthPercentage: " + widthPercentage + " prevViewPercentageX: " + prevViewPercentageX);
|
||||
// Log.d("Lyric", "prevViewPercentageY: " + prevViewPercentageY + " layoutParams.x: " + layoutParams.x);
|
||||
// Log.d("Lyric", "layoutParams.y: " + layoutParams.y + " layoutParams.width: " + layoutParams.width);
|
||||
|
||||
windowManager.updateViewLayout(textView, layoutParams);
|
||||
}
|
||||
|
||||
public void sendPositionEvent(int x, int y) {
|
||||
WritableMap params = Arguments.createMap();
|
||||
params.putInt("x", x);
|
||||
@ -116,24 +177,27 @@ public class LyricView extends Activity implements View.OnTouchListener {
|
||||
public void showLyricView(Bundle options) {
|
||||
isLock = options.getBoolean("isLock", isLock);
|
||||
themeColor = options.getString("themeColor", themeColor);
|
||||
prevViewPercentageX = (int) options.getDouble("lyricViewX", prevViewPercentageX) / 100f;
|
||||
prevViewPercentageY = (int) options.getDouble("lyricViewY", prevViewPercentageY) / 100f;
|
||||
prevViewPercentageX = (int) options.getDouble("lyricViewX", 0) / 100f;
|
||||
prevViewPercentageY = (int) options.getDouble("lyricViewY", 0) / 100f;
|
||||
textX = options.getString("textX", textX);
|
||||
textY = options.getString("textY", textY);
|
||||
alpha = (float) options.getDouble("alpha", alpha);
|
||||
textSize = (float) options.getDouble("textSize", textSize);
|
||||
widthPercentage = (int) options.getDouble("width", widthPercentage) / 100f;
|
||||
widthPercentage = (int) options.getDouble("width", 100) / 100f;
|
||||
maxLineNum = (int) options.getDouble("maxLineNum", maxLineNum);
|
||||
handleShowLyric();
|
||||
fixViewPosition();
|
||||
listenOrientationEvent();
|
||||
}
|
||||
public void showLyricView() {
|
||||
try {
|
||||
handleShowLyric();
|
||||
} catch (Exception e) {
|
||||
Log.e("Lyric", e.getMessage());
|
||||
return;
|
||||
}
|
||||
fixViewPosition();
|
||||
listenOrientationEvent();
|
||||
}
|
||||
|
||||
private void handleShowLyric() {
|
||||
@ -227,12 +291,12 @@ public class LyricView extends Activity implements View.OnTouchListener {
|
||||
// FLAG_NOT_TOUCH_MODAL不阻塞事件传递到后面的窗口
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.START; //显示在屏幕上中部
|
||||
|
||||
updateWH();
|
||||
|
||||
//显示位置与指定位置的相对位置差
|
||||
layoutParams.x = (int)(maxWidth * prevViewPercentageX);
|
||||
layoutParams.y = (int)(maxHeight * prevViewPercentageY);
|
||||
|
||||
updateWH();
|
||||
|
||||
//悬浮窗的宽高
|
||||
// layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
// layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
@ -363,33 +427,6 @@ public class LyricView extends Activity implements View.OnTouchListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void fixViewPosition() {
|
||||
updateWH();
|
||||
|
||||
int width = (int)(maxWidth * widthPercentage);
|
||||
if (layoutParams.width != width) layoutParams.width = width;
|
||||
|
||||
layoutParams.x = (int)(maxWidth * prevViewPercentageX);
|
||||
layoutParams.y = (int)(maxHeight * prevViewPercentageY);
|
||||
|
||||
// int maxX = this.maxWidth - layoutParams.width;
|
||||
// int maxY = this.maxHeight - layoutParams.height;
|
||||
// int x = layoutParams.x;
|
||||
// int y = layoutParams.y;
|
||||
// if (x < 0) x = 0;
|
||||
// else if (x > maxX) x = maxX;
|
||||
// if (y < 0) y = 0;
|
||||
// else if (y > maxY) y = maxY;
|
||||
|
||||
// layoutParams.x = x;
|
||||
// layoutParams.y = y;
|
||||
Log.d("Lyric", "widthPercentage: " + widthPercentage + " prevViewPercentageX: " + prevViewPercentageX);
|
||||
Log.d("Lyric", "prevViewPercentageY: " + prevViewPercentageY + " layoutParams.x: " + layoutParams.x);
|
||||
Log.d("Lyric", "layoutParams.y: " + layoutParams.y + " layoutParams.width: " + layoutParams.width);
|
||||
|
||||
windowManager.updateViewLayout(textView, layoutParams);
|
||||
}
|
||||
|
||||
public void lockView() {
|
||||
isLock = true;
|
||||
if (windowManager == null || textView == null) return;
|
||||
@ -480,5 +517,6 @@ public class LyricView extends Activity implements View.OnTouchListener {
|
||||
destroyView();
|
||||
windowManager = null;
|
||||
layoutParams = null;
|
||||
removeOrientationEvent();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
从现在起,有了一个显示状态栏歌词的方式:通过调用第三方Xposed模块【墨•状态栏歌词】的API支持来状态栏歌词(感谢@ftevxk)。
|
||||
但考虑到要依赖第三方应用,并且是Xposed模块,预计用的人会比较少,所以暂不考虑将此特性包含在正式版中,如你满足使用条件并需要此特性,可以看项目的置顶issue
|
||||
从这个版本起,你可以将桌面歌词拖动到状态栏上,然后将歌词字体调小后配合新增的歌词窗口宽度、行数设置,模拟出状态栏歌词的效果。
|
||||
|
||||
如果你的设备装有Xposed框架,可以使用状态栏版(详情看GitHub置顶issue),它通过调用第三方Xposed模块【墨•状态栏歌词】的API支持来状态栏歌词(感谢@ftevxk)。
|
||||
但考虑到要依赖第三方应用,并且是Xposed模块,预计用的人会比较少,所以暂不考虑将此特性包含在正式版中。
|
||||
|
||||
### 新增
|
||||
|
||||
|
@ -836,6 +836,8 @@ export const toggleDesktopLyric = isShow => async(dispatch, getState) => {
|
||||
themeId: desktopLyric.theme,
|
||||
opacity: desktopLyric.style.opacity,
|
||||
textSize: desktopLyric.style.fontSize,
|
||||
width: desktopLyric.width,
|
||||
maxLineNum: desktopLyric.maxLineNum,
|
||||
positionX: desktopLyric.position.x,
|
||||
positionY: desktopLyric.position.y,
|
||||
textPositionX: desktopLyric.textPosition.x,
|
||||
|
@ -1,11 +1,9 @@
|
||||
import { NativeModules, NativeEventEmitter, Dimensions } from 'react-native'
|
||||
import { NativeModules, NativeEventEmitter } from 'react-native'
|
||||
|
||||
const { LyricModule } = NativeModules
|
||||
|
||||
let isShowLyric = false
|
||||
|
||||
let changeListener
|
||||
|
||||
export const themes = [
|
||||
{ id: 'green', value: '#07c556' },
|
||||
{ id: 'yellow', value: '#fffa12' },
|
||||
@ -36,15 +34,6 @@ const getTextPositionY = y => (textPositionY.find(t => t.id == y) || textPositio
|
||||
const getAlpha = num => parseInt(num) / 100
|
||||
const getTextSize = num => parseInt(num) / 10
|
||||
|
||||
const listenChange = () => {
|
||||
unlistenChange()
|
||||
changeListener = Dimensions.addEventListener('change', fixViewPosition)
|
||||
}
|
||||
const unlistenChange = () => {
|
||||
if (!changeListener) return
|
||||
changeListener.remove()
|
||||
changeListener = null
|
||||
}
|
||||
|
||||
/**
|
||||
* show lyric
|
||||
@ -66,7 +55,6 @@ export const showLyric = ({ width, maxLineNum, isLock, themeId, opacity, textSiz
|
||||
maxLineNum,
|
||||
}).then(() => {
|
||||
isShowLyric = true
|
||||
listenChange()
|
||||
})
|
||||
}
|
||||
|
||||
@ -78,7 +66,6 @@ export const hideLyric = () => {
|
||||
if (!isShowLyric) return Promise.resolve()
|
||||
return LyricModule.hideLyric().then(() => {
|
||||
isShowLyric = false
|
||||
unlistenChange()
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user