From 62f3634fe7e4f1697ae03182758981f6d9f885eb Mon Sep 17 00:00:00 2001 From: MUQING <1966944300@qq.com> Date: Thu, 11 Jan 2024 19:28:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=AD=8C=E8=AF=8D=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E8=BF=87=E5=A4=A7=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=85=A8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/muqingbfq/bfq.java | 12 ++-- .../com/muqingbfq/fragment/gd_adapter.java | 4 +- .../muqingbfq/mq/FloatingLyricsService.java | 60 ++++++++++++------- app/src/main/java/com/muqingbfq/sz.java | 2 +- app/src/main/res/layout/float_lrcview.xml | 6 +- 5 files changed, 55 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/muqingbfq/bfq.java b/app/src/main/java/com/muqingbfq/bfq.java index 33f272b..02457bf 100644 --- a/app/src/main/java/com/muqingbfq/bfq.java +++ b/app/src/main/java/com/muqingbfq/bfq.java @@ -46,7 +46,8 @@ public class bfq extends AppCompatActivity { public static View view; public static String lrc; public static com.muqingbfq.view.LrcView lrcView; - private void setLrc(){ + + private void setLrc() { lrcView = binding.lrcView; ViewGroup.LayoutParams layoutParams = binding.cardview.getLayoutParams(); layoutParams.height = main.k - 100; @@ -67,6 +68,7 @@ public class bfq extends AppCompatActivity { lrcView.setOnClickListener(null); } } + @SuppressLint("ClickableViewAccessibility") @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -134,7 +136,7 @@ public class bfq extends AppCompatActivity { return; } if (bfqkz.xm != null) { - new Thread(){ + new Thread() { @Override public void run() { super.run(); @@ -206,7 +208,8 @@ public class bfq extends AppCompatActivity { @SuppressLint("ClickableViewAccessibility") @Override - public boolean onTouch(View view, MotionEvent motionEvent) {LinearLayout root = binding.getRoot(); + public boolean onTouch(View view, MotionEvent motionEvent) { + LinearLayout root = binding.getRoot(); switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: downY = motionEvent.getRawY(); @@ -217,7 +220,7 @@ public class bfq extends AppCompatActivity { //移动的距离 float dy = moveY - downY; //重新设置控件的位置。移动 - if (dy <= 0) { + if (dy < 0) { return true; } else if (dy > main.g - main.g / 5.0) { finish(); @@ -244,6 +247,7 @@ public class bfq extends AppCompatActivity { return true; } } + public static void setlike(boolean bool) { if (binding == null) { return; diff --git a/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java b/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java index d6a57bb..690abf4 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java @@ -81,12 +81,12 @@ public class gd_adapter extends Fragment { MP3 x = listmp3.get(position); holder.binding.wb1.setText(x.name); holder.binding.zz.setText(x.zz); - int color = ContextCompat.getColor(getContext(), R.color.text); +/* int color = ContextCompat.getColor(getContext(), R.color.text); if (bfqkz.xm != null && x.id.equals(bfqkz.xm.id)) { color = ContextCompat.getColor(getContext(), R.color.text_cz); } holder.binding.wb1.setTextColor(color); - holder.binding.zz.setTextColor(color); + holder.binding.zz.setTextColor(color);*/ holder.itemView.setOnClickListener(view -> { if (bfqkz.xm == null || !bfqkz.xm.id.equals(x.id)) { bfqkz.xm = x; diff --git a/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java b/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java index 2958a5f..088a4bd 100644 --- a/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java +++ b/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java @@ -8,6 +8,7 @@ import android.graphics.PixelFormat; import android.os.Build; import android.os.Handler; import android.os.IBinder; +import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -35,16 +36,36 @@ public class FloatingLyricsService extends Service implements View.OnClickListen public Runnable updateSeekBar = new Runnable() { @Override public void run() { - if (bfqkz.mt.isPlaying() && lrcView != null) { - long position = bfqkz.mt.getCurrentPosition(); - lrcView.setTimeLrc(position); + if (bfqkz.mt.isPlaying()) { + int index = 0; + for (int i = 0; i < LrcView.lrclist.size(); i++) { + LrcView.LRC lineLrc = LrcView.lrclist.get(i); + if (lineLrc.time <= bfqkz.mt.getCurrentPosition()) { + index = i; + } else { + break; + } + } + if (index < LrcView.lrclist.size()) { + String text; + if (LrcView.lrclist.size() <= 3) { + for (LrcView.LRC a : LrcView.lrclist) { + if (a.time == 5940000 && a.lrc.equals("纯音乐,请欣赏")) { + text = "纯音乐,请欣赏"; + binding.lrcView.setText(text); + return; + } + } + } + LrcView.LRC currentLrc = LrcView.lrclist.get(index); + text = currentLrc.lrc; + if (currentLrc.tlyric != null) { + text += "\n" + currentLrc.tlyric; + } + binding.lrcView.setText(text); + } } -/* boolean appInForeground = gj.isAppInForeground(FloatingLyricsService.this); - if (appInForeground) { - layout.setVisibility(View.GONE); - } else { - layout.setVisibility(View.VISIBLE); - }*/ +// gj.sc(getClass()+"执行"); handler.postDelayed(this, 1000); // 每秒更新一次进度 } }; @@ -65,7 +86,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen } Handler handler = new Handler(); - LrcView lrcView; + FloatLrcviewBinding binding; WindowManager.LayoutParams params; public static class SETUP { @@ -104,7 +125,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen } // 创建悬浮窗歌词的 View // FloatLrcviewBinding - FloatLrcviewBinding binding = FloatLrcviewBinding.inflate(LayoutInflater.from(this)); + binding = FloatLrcviewBinding.inflate(LayoutInflater.from(this)); layout = binding.getRoot(); layout.setOnTouchListener(this); // int i = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;FLAG_NOT_TOUCH_MODAL @@ -120,10 +141,11 @@ public class FloatingLyricsService extends Service implements View.OnClickListen params.y = setup.Y; - lrcView = binding.lrcView; - lrcView.setTextColor(setup.Color); - lrcView.setSize(setup.size); - lrcView.setAlpha(setup.Alpha); + binding.lrcView.setAlpha(setup.Alpha); + binding.lrcView.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, + setup.size, + getResources().getDisplayMetrics())); + binding.lrcView.setTextColor(Color.parseColor(setup.Color)); bfq_an.kz bfqAn = new bfq_an.kz(); binding.kg.setOnClickListener(this); @@ -138,7 +160,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen if (setup.i == 2) { params.flags = lock(); layout.setBackground(null); - lrcView.setAlpha(setup.Alpha); + binding.lrcView.setAlpha(setup.Alpha); layout.findViewById(com.muqingbfq.R.id.controlLayout).setVisibility(View.GONE); } windowManager.addView(layout, params); @@ -228,8 +250,6 @@ public class FloatingLyricsService extends Service implements View.OnClickListen } } else if (id == R.id.lock) { setyc(); - } else if (id == R.id.like) { -// bfq } } @@ -237,7 +257,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen setup.i = 2; params.flags = lock(); layout.setBackground(null); - lrcView.setAlpha(setup.Alpha); + binding.lrcView.setAlpha(setup.Alpha); layout.findViewById(com.muqingbfq.R.id.controlLayout).setVisibility(View.GONE); windowManager.updateViewLayout(layout, params); baocun(); @@ -247,7 +267,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen setup.i = 1; params.flags = lock(); layout.setBackgroundColor(Color.parseColor("#50000000")); - lrcView.setAlpha(1.0f); + binding.lrcView.setAlpha(1.0f); layout.findViewById(com.muqingbfq.R.id.controlLayout).setVisibility(View.VISIBLE); windowManager.updateViewLayout(layout, params); baocun(); diff --git a/app/src/main/java/com/muqingbfq/sz.java b/app/src/main/java/com/muqingbfq/sz.java index df674db..f982de1 100644 --- a/app/src/main/java/com/muqingbfq/sz.java +++ b/app/src/main/java/com/muqingbfq/sz.java @@ -168,7 +168,7 @@ public class sz extends AppCompatActivity { binding.lrctext.setText(text); } } - gj.sc(getClass()+"执行"); +// gj.sc(getClass()+"执行"); main.handler.postDelayed(this, 1000); // 每秒更新一次进度 } }; diff --git a/app/src/main/res/layout/float_lrcview.xml b/app/src/main/res/layout/float_lrcview.xml index 244c332..1cc9486 100644 --- a/app/src/main/res/layout/float_lrcview.xml +++ b/app/src/main/res/layout/float_lrcview.xml @@ -5,10 +5,12 @@ android:layout_height="wrap_content" android:background="#50000000"> -