From 4a502e46f722cc518414a5cf3edfbe2675b4c5ca Mon Sep 17 00:00:00 2001 From: MUQING <1966944300@qq.com> Date: Mon, 1 Jan 2024 18:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=AD=8C=E8=AF=8DBU?= =?UTF-8?q?G,=E4=BC=98=E5=8C=96=E4=BA=86=E6=92=AD=E6=94=BE=E5=99=A8?= =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E6=92=AD=E6=94=BE=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/muqingbfq/bfq.java | 3 +- app/src/main/java/com/muqingbfq/bfq_an.java | 57 +++++---- app/src/main/java/com/muqingbfq/bfqkz.java | 10 +- .../muqingbfq/mq/FloatingLyricsService.java | 104 ++++++++-------- .../java/com/muqingbfq/view/CardImage.java | 6 +- .../main/java/com/muqingbfq/view/LrcView.java | 112 +++++++++++------- app/src/main/java/com/muqingbfq/yc.java | 11 +- 7 files changed, 175 insertions(+), 128 deletions(-) diff --git a/app/src/main/java/com/muqingbfq/bfq.java b/app/src/main/java/com/muqingbfq/bfq.java index bb4df8e..624a2ae 100644 --- a/app/src/main/java/com/muqingbfq/bfq.java +++ b/app/src/main/java/com/muqingbfq/bfq.java @@ -163,7 +163,8 @@ public class bfq extends AppCompatActivity { setname(bfqkz.xm.name); setzz(bfqkz.xm.zz); bfq_an.islike(); - bfqkz.mt.setTX(); + Media.setImageBitmap(); +// bfqkz.mt.setTX(); } } diff --git a/app/src/main/java/com/muqingbfq/bfq_an.java b/app/src/main/java/com/muqingbfq/bfq_an.java index 739a34c..d78ce3a 100644 --- a/app/src/main/java/com/muqingbfq/bfq_an.java +++ b/app/src/main/java/com/muqingbfq/bfq_an.java @@ -1,20 +1,18 @@ package com.muqingbfq; import android.annotation.SuppressLint; -import android.content.Context; import android.view.View; import android.widget.ImageView; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.muqingbfq.api.url; -import com.muqingbfq.fragment.Media; -import com.muqingbfq.fragment.gd; import com.muqingbfq.mq.gj; import com.muqingbfq.mq.wj; import java.lang.reflect.Type; import java.text.SimpleDateFormat; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -60,43 +58,60 @@ public class bfq_an { } public static class control implements View.OnClickListener { + ImageView imageView; + public control(ImageView imageView) { + this.imageView = imageView; + setImage(-1); + } + + private void setImage(int i) { + gj.sc(bfqkz.ms); + + bfqkz.mt.setLooping(bfqkz.ms == 0); switch (bfqkz.ms) { case 0: imageView.setImageResource(R.drawable.mt_xh); + if (i == -1) { + break; + } + if (!bfqkz.list_baocun.isEmpty()) { + bfqkz.list.clear(); + bfqkz.list.addAll(bfqkz.list_baocun); + } break; case 1: imageView.setImageResource(R.drawable.mt_sx); + if (i == -1) { + break; + } + if (!bfqkz.list_baocun.isEmpty()) { + bfqkz.list.clear(); + bfqkz.list.addAll(bfqkz.list_baocun); + } break; case 2: imageView.setImageResource(R.drawable.mt_sj); + if (i == -1) { + break; + } + bfqkz.list_baocun.clear(); + bfqkz.list_baocun.addAll(bfqkz.list); + Collections.shuffle(bfqkz.list); break; } } @Override public void onClick(View v) { - ImageView imageView = (ImageView) v; - switch (bfqkz.ms) { - case 0: - bfqkz.ms = 1; - imageView.setImageResource(R.drawable.mt_sx); -// 顺序 - break; - case 1: - bfqkz.ms = 2; - imageView.setImageResource(R.drawable.mt_sj); -// 随机 - break; - case 2: - bfqkz.ms = 0; - imageView.setImageResource(R.drawable.mt_xh); -// 循环 - break; + if (bfqkz.ms == 2) { + bfqkz.ms = 0; + } else { + bfqkz.ms++; } + setImage(bfqkz.ms); main.edit.putInt("ms", bfqkz.ms); main.edit.commit(); -// imageView.setImageDrawable(); } } diff --git a/app/src/main/java/com/muqingbfq/bfqkz.java b/app/src/main/java/com/muqingbfq/bfqkz.java index ec323b2..f822d37 100644 --- a/app/src/main/java/com/muqingbfq/bfqkz.java +++ b/app/src/main/java/com/muqingbfq/bfqkz.java @@ -30,6 +30,9 @@ import java.util.Random; public class bfqkz extends MediaBrowserServiceCompat { public static MediaPlayer mt = new MediaPlayer(); public static List list = new ArrayList<>(); + + //保存原始list顺序 + public static List list_baocun = new ArrayList<>(); public static List lishi_list = new ArrayList<>(); public static int ms; // 0 循环 1 顺序 2 随机 @@ -39,15 +42,10 @@ public class bfqkz extends MediaBrowserServiceCompat { public static com.muqingbfq.mq.NotificationManagerCompat notify; public static int getmti(int s) { - int i = bfqkz.list.indexOf(xm); - if (s == 1) { - i = bfqkz.list.indexOf(xm) + 1; + int i = bfqkz.list.indexOf(xm) + 1; if (i >= bfqkz.list.size()) { i = 0; } - } else if (s == 2) { - i = new Random().nextInt(bfqkz.list.size()); - } return i; } diff --git a/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java b/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java index f7ac12b..1a21ae6 100644 --- a/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java +++ b/app/src/main/java/com/muqingbfq/mq/FloatingLyricsService.java @@ -64,13 +64,14 @@ public class FloatingLyricsService extends Service implements View.OnClickListen public static class SETUP { //0是关闭 1是打开 2是锁定 - public int i; - public float TOP, Alpha; - public String Color; - public int Y; + public int i = 1; + public float Alpha = 0.9f; + public String Color = "#0088FF"; + public int Y = -main.g; } public SETUP setup = new SETUP(); + public int lock() { if (setup != null && setup.i == 2) { return WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE @@ -79,6 +80,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen return WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; } + @Override public void onCreate() { super.onCreate(); @@ -91,59 +93,53 @@ public class FloatingLyricsService extends Service implements View.OnClickListen Type type = new TypeToken() { }.getType(); setup = gson.fromJson(dqwb, type); - } else { - setup.i = 1; - setup.TOP = 0; - setup.Y = -main.g; - setup.Alpha = 0.9f; - setup.Color = "#0088FF"; } + // 创建悬浮窗歌词的 View +// FloatLrcviewBinding + FloatLrcviewBinding binding = FloatLrcviewBinding.inflate(LayoutInflater.from(this)); + layout = binding.getRoot(); + layout.setOnTouchListener(this); +// int i = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;FLAG_NOT_TOUCH_MODAL + params = new WindowManager.LayoutParams( + WindowManager.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.WRAP_CONTENT, + Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? + WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : + WindowManager.LayoutParams.TYPE_PHONE, + lock(), + PixelFormat.TRANSLUCENT + ); + + params.y = setup.Y; + + lrcView = binding.lrcView; + lrcView.setTextColor(setup.Color); + bfq_an.kz bfqAn = new bfq_an.kz(); + binding.kg.setOnClickListener(this); + binding.syq.setOnClickListener(bfqAn); + binding.xyq.setOnClickListener(bfqAn); + binding.lock.setOnClickListener(this); +// params.gravity = Gravity.CENTER; + + + // 获取 WindowManager 并将悬浮窗歌词添加到窗口中 + windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); + if (setup.i == 2) { + params.flags = lock(); + layout.setBackground(null); + lrcView.setAlpha(0.5f); + layout.findViewById(com.muqingbfq.R.id.controlLayout).setVisibility(View.GONE); + } + windowManager.addView(layout, params); + if (setup.i == 0) { + setup.i = 1; + } + baocun(); + handler.post(updateSeekBar); // 在播放开始时启动更新进度 } catch (Exception e) { wj.sc(file.toString()); gj.sc(getClass() + ":" + e); } - // 创建悬浮窗歌词的 View -// FloatLrcviewBinding - FloatLrcviewBinding binding = FloatLrcviewBinding.inflate(LayoutInflater.from(this)); - layout = binding.getRoot(); - layout.setOnTouchListener(this); -// int i = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;FLAG_NOT_TOUCH_MODAL - params = new WindowManager.LayoutParams( - WindowManager.LayoutParams.MATCH_PARENT, - WindowManager.LayoutParams.WRAP_CONTENT, - Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? - WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : - WindowManager.LayoutParams.TYPE_PHONE, - lock(), - PixelFormat.TRANSLUCENT - ); - - params.y = setup.Y; - - lrcView = binding.lrcView; - lrcView.setTextColor(setup.Color); - bfq_an.kz bfqAn = new bfq_an.kz(); - binding.kg.setOnClickListener(this); - binding.syq.setOnClickListener(bfqAn); - binding.xyq.setOnClickListener(bfqAn); - binding.lock.setOnClickListener(this); -// params.gravity = Gravity.CENTER; - - - // 获取 WindowManager 并将悬浮窗歌词添加到窗口中 - windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); - if (setup.i == 2) { - params.flags = lock(); - layout.setBackground(null); - lrcView.setAlpha(0.5f); - layout.findViewById(com.muqingbfq.R.id.controlLayout).setVisibility(View.GONE); - } - windowManager.addView(layout, params); - if (setup.i == 0) { - setup.i = 1; - } - baocun(); - handler.post(updateSeekBar); // 在播放开始时启动更新进度 } @Override @@ -211,7 +207,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen bfqkz.mt.start(); kg.setImageResource(R.drawable.bf); } - } else if (id==R.id.lock) { + } else if (id == R.id.lock) { setyc(); } else if (id == R.id.like) { // bfq @@ -222,7 +218,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen setup.i = 2; params.flags = lock(); layout.setBackground(null); - lrcView.setAlpha(0.5f); + lrcView.setAlpha(setup.Alpha); layout.findViewById(com.muqingbfq.R.id.controlLayout).setVisibility(View.GONE); windowManager.updateViewLayout(layout, params); baocun(); diff --git a/app/src/main/java/com/muqingbfq/view/CardImage.java b/app/src/main/java/com/muqingbfq/view/CardImage.java index dacdfa9..4d35faf 100644 --- a/app/src/main/java/com/muqingbfq/view/CardImage.java +++ b/app/src/main/java/com/muqingbfq/view/CardImage.java @@ -1,6 +1,7 @@ package com.muqingbfq.view; import android.content.Context; +import android.graphics.Bitmap; import android.util.AttributeSet; import android.widget.ImageView; @@ -8,6 +9,9 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.google.android.material.card.MaterialCardView; import com.muqingbfq.R; +import com.muqingbfq.bfq; +import com.muqingbfq.main; +import com.muqingbfq.mq.gj; public class CardImage extends MaterialCardView { private ImageView imageView; @@ -35,7 +39,7 @@ public class CardImage extends MaterialCardView { public void setImage(Object bitmap) { - Glide.with(getContext()) + Glide.with(this) .load(bitmap) // .apply(new RequestOptions().placeholder(R.drawable.icon)) .into(imageView); diff --git a/app/src/main/java/com/muqingbfq/view/LrcView.java b/app/src/main/java/com/muqingbfq/view/LrcView.java index 485796d..6094d9e 100644 --- a/app/src/main/java/com/muqingbfq/view/LrcView.java +++ b/app/src/main/java/com/muqingbfq/view/LrcView.java @@ -24,34 +24,45 @@ import androidx.recyclerview.widget.RecyclerView; import com.muqingbfq.R; import com.muqingbfq.mq.gj; +import com.muqingbfq.yc; import java.util.ArrayList; import java.util.List; public class LrcView extends RecyclerView { - static List lrclist = new ArrayList<>(); + static List lrclist = new ArrayList<>(); - static class lrc { + static class LRC { String lrc, tlyric; long time; - public lrc(String lrc, long time) { + public LRC(String lrc, long time) { this.lrc = lrc; this.time = time; } - public lrc(String lrc, String tlyric, long time) { - this.lrc = lrc; - this.tlyric = tlyric; - this.time = time; + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + LRC lrc = (LRC) obj; + return time == lrc.time; } - - public lrc setTlyric(String str) { + public LRC setTlyric(String str) { this.tlyric = str; return this; } + @Override + public int hashCode() { + return java.util.Objects.hash(time); + } + } public LrcView(Context context) { @@ -81,8 +92,9 @@ public class LrcView extends RecyclerView { public void setTextColor(String textColor) { TextColor = Color.parseColor(textColor); } - - + public void setLrcline(boolean lrcline) { + Lrcline = lrcline; + } private void init() { if (attrs != null) { @@ -145,40 +157,50 @@ public class LrcView extends RecyclerView { } public static void setLrc(String a, String b) { - setLrc(a); - if (TextUtils.isEmpty(b)) { - return; - } - b.trim(); - String[] lines = b.split("\n"); - for (String line : lines) { - String[] parts = line.split("]"); - if (parts.length >= 2) { - String timeString = parts[0].substring(1); - String lyric = parts[1].trim(); - String[] timeParts = timeString.split(":"); - if (timeParts.length >= 2) { - int minute = Integer.parseInt(timeParts[0]); - String[] secondParts = timeParts[1].split("\\."); - if (secondParts.length >= 2) { - int second = Integer.parseInt(secondParts[0]); - int millisecond = Integer.parseInt(secondParts[1]); - long time = (long) minute * 60 * 1000 + second * 1000L + millisecond; - int currentLineIndex = getCurrentLineIndex(time); - lrclist.set(currentLineIndex, lrclist.get(currentLineIndex).setTlyric(lyric)); + try { + lrclist.clear(); + setLrc(a); + setLrc(b); + if (true) { + return; + } + if (TextUtils.isEmpty(b)) { + return; + } + b.trim(); + String[] lines = b.split("\n"); + for (String line : lines) { + String[] parts = line.split("]"); + if (parts.length >= 2) { + String timeString = parts[0].substring(1); + String lyric = parts[1].trim(); + String[] timeParts = timeString.split(":"); + if (timeParts.length >= 2) { + int minute = Integer.parseInt(timeParts[0]); + String[] secondParts = timeParts[1].split("[.\\-]"); + if (secondParts.length >= 2) { + int second = Integer.parseInt(secondParts[0]); + int millisecond = Integer.parseInt(secondParts[1]); + long time = (long) minute * 60 * 1000 + second * 1000L + millisecond; + int currentLineIndex = getCurrentLineIndex(time); + lrclist.set(currentLineIndex, + lrclist.get(currentLineIndex).setTlyric(lyric)); + } + } } } + } catch (Exception e) { + yc.start("LrcView setLrc :" + e + a + b); } } public static void setLrc(String a) { - lrclist.clear(); // 去除空格 - a.trim(); if (TextUtils.isEmpty(a)) { return; } + a.trim(); String[] lines = a.split("\n"); for (String line : lines) { String[] parts = line.split("]"); @@ -188,12 +210,18 @@ public class LrcView extends RecyclerView { String[] timeParts = timeString.split(":"); if (timeParts.length >= 2) { int minute = Integer.parseInt(timeParts[0]); - String[] secondParts = timeParts[1].split("\\."); + String[] secondParts = timeParts[1].split("[.\\-]"); if (secondParts.length >= 2) { int second = Integer.parseInt(secondParts[0]); int millisecond = Integer.parseInt(secondParts[1]); long time = (long) minute * 60 * 1000 + second * 1000L + millisecond; - lrclist.add(new lrc(lyric, time)); + LRC lrc = new LRC(lyric, time); + if (lrclist.contains(lrc)) { + int index = lrclist.indexOf(lrc); + lrclist.get(index).setTlyric(lyric); + } else { + lrclist.add(lrc); + } } } } @@ -244,7 +272,7 @@ public class LrcView extends RecyclerView { String text; if (lrclist.size() <= 3) { - for (lrc a : lrclist) { + for (LRC a : lrclist) { if (a.time == 5940000 && a.lrc.equals("纯音乐,请欣赏")) { text = "纯音乐,请欣赏"; holder.textView.setText(text); @@ -252,7 +280,7 @@ public class LrcView extends RecyclerView { } } } - lrc currentLrc = lrclist.get(currentLineIndex); + LRC currentLrc = lrclist.get(currentLineIndex); text = currentLrc.lrc; if (currentLrc.tlyric != null) { text += "\n" + currentLrc.tlyric; @@ -265,7 +293,7 @@ public class LrcView extends RecyclerView { return; } try { - lrc lrc = lrclist.get(position); + LRC lrc = lrclist.get(position); StringBuilder stringBuffer = new StringBuilder(); stringBuffer.append(lrc.lrc); if (lrc.tlyric != null) { @@ -286,7 +314,7 @@ public class LrcView extends RecyclerView { @Override public int getItemCount() { if (lrclist.size() < 3) { - for (lrc a : lrclist) { + for (LRC a : lrclist) { if (a.time == 5940000 && a.lrc.equals("纯音乐,请欣赏")) { return 1; } @@ -314,7 +342,7 @@ public class LrcView extends RecyclerView { private int getCurrentLineIndex() { index = -1; for (int i = 0; i < lrclist.size(); i++) { - lrc lineLrc = lrclist.get(i); + LRC lineLrc = lrclist.get(i); if (lineLrc.time <= time) { index = i; } else { @@ -327,7 +355,7 @@ public class LrcView extends RecyclerView { private static int getCurrentLineIndex(long time) { int index = 0; for (int i = 0; i < lrclist.size(); i++) { - lrc lineLrc = lrclist.get(i); + LRC lineLrc = lrclist.get(i); if (lineLrc.time <= time) { index = i; } else { diff --git a/app/src/main/java/com/muqingbfq/yc.java b/app/src/main/java/com/muqingbfq/yc.java index a012a6e..fcd61ba 100644 --- a/app/src/main/java/com/muqingbfq/yc.java +++ b/app/src/main/java/com/muqingbfq/yc.java @@ -14,14 +14,17 @@ import androidx.appcompat.app.AppCompatActivity; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.muqingbfq.databinding.ActivityYcBinding; +import com.muqingbfq.mq.gj; public class yc extends AppCompatActivity { - public static Object exception; + public Object exception; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActivityYcBinding binding = ActivityYcBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); + Intent intent = getIntent(); + exception = intent.getStringExtra("e"); String deviceModel = Build.MODEL; String deviceManufacturer = Build.MANUFACTURER; @@ -52,8 +55,10 @@ public class yc extends AppCompatActivity { } public static void start(Context context, Object e) { - yc.exception = e; - context.startActivity(new Intent(context, yc.class)); + gj.sc(e); + Intent intent = new Intent(context, yc.class); + intent.putExtra("e",e.toString()); + context.startActivity(intent); } public static void tc(Context context, Object exception) {