diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c8d82b9..cf7f148 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -53,7 +53,7 @@ diff --git a/app/src/main/java/com/muqingbfq/MediaPlayer.java b/app/src/main/java/com/muqingbfq/MediaPlayer.java index 121c35b..527603e 100644 --- a/app/src/main/java/com/muqingbfq/MediaPlayer.java +++ b/app/src/main/java/com/muqingbfq/MediaPlayer.java @@ -31,7 +31,7 @@ public class MediaPlayer extends android.media.MediaPlayer { public Runnable updateSeekBar = new Runnable() { @Override public void run() { - if (isPlaying() && Media.view != null) { + if (isPlaying() && Media.lrcview != null) { long position = getCurrentPosition(); Media.setProgress((int) position); } @@ -110,7 +110,7 @@ public class MediaPlayer extends android.media.MediaPlayer { start(); main.handler.post(() -> { bfui(); - if (Media.view != null) { + if (bfq.inflate != null) { main.handler.removeCallbacks(updateSeekBar); // 在播放开始时启动更新进度 long duration = getDuration(); Media.setMax((int) getDuration()); @@ -167,10 +167,10 @@ public class MediaPlayer extends android.media.MediaPlayer { public void bfui() { setTX(); String name = xm.name, zz = bfqkz.xm.zz; - if (Media.view != null) { + if (bfq.inflate != null) { Media.setProgress(0); - Media.setname(name); - Media.setzz(zz); + bfq.setname(name); + bfq.setzz(zz); bfq_an.islike(); } bfq_db.setname(name + "/" + zz); diff --git a/app/src/main/java/com/muqingbfq/api/url.java b/app/src/main/java/com/muqingbfq/api/url.java index 9650d83..a803ee2 100644 --- a/app/src/main/java/com/muqingbfq/api/url.java +++ b/app/src/main/java/com/muqingbfq/api/url.java @@ -38,8 +38,9 @@ public class url extends Thread { } public static String hq(MP3 x) { + getLrc(x.id); if (Media.lrcview != null) { - gc(x.id); + Media.loadLyric(); } try { if (wj.cz(wj.mp3 + x.id)) { @@ -136,7 +137,7 @@ public class url extends Thread { } - public static void gc(String id) { + public static void getLrc(String id) { String file = wj.mp3 + id; if (wj.cz(file)) { try { @@ -154,7 +155,6 @@ public class url extends Thread { }else { bfq.lrc = wl.hq("/lyric?id=" + id); } - Media.loadLyric(); } public static String picurl(String id) { diff --git a/app/src/main/java/com/muqingbfq/bfq.java b/app/src/main/java/com/muqingbfq/bfq.java index bf54a82..533376c 100644 --- a/app/src/main/java/com/muqingbfq/bfq.java +++ b/app/src/main/java/com/muqingbfq/bfq.java @@ -40,23 +40,29 @@ import java.util.List; public class bfq extends AppCompatActivity { @SuppressLint("StaticFieldLeak") - public static AppCompatActivity context; - public ActivityBfqBinding inflate; + public static ActivityBfqBinding inflate; public static String lrc; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); - context = this; inflate = ActivityBfqBinding.inflate(getLayoutInflater()); + new Media(inflate); + Media.lrcview.setCurrentColor(ContextCompat.getColor(this,R.color.text)); + Media.lrcview.setLabel(getString(R.string.app_name)); + Media.lrcview.setCurrentTextSize(TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_SP, 16, getResources().getDisplayMetrics())); +// lrcView.setLrcPadding(16); + Media.lrcview.setCurrentTextSize(TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_SP, 20, getResources().getDisplayMetrics())); + Media.lrcview.setTimelineTextColor(ContextCompat.getColor(this,R.color.text_tm)); + LinearLayout root = inflate.getRoot(); TypedValue typedValue = new TypedValue(); home.appCompatActivity.getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true); // 设置背景颜色 root.setBackgroundColor(typedValue.data); setContentView(root); - Media media = (Media) getSupportFragmentManager().findFragmentById(R.id.fragment_bfq); - media.setBfq(this); Toolbar toolbar = inflate.toolbar; toolbar.setNavigationOnClickListener(view1 -> finish()); toolbar.setOnMenuItemClickListener(item -> { @@ -106,12 +112,6 @@ public class bfq extends AppCompatActivity { e.printStackTrace(); } }); - if (bfqkz.xm != null) { - Media.setname(bfqkz.xm.name); - Media.setzz(bfqkz.xm.zz); - bfq_an.islike(); - bfqkz.mt.setTX(); - } inflate.download.setOnClickListener(view -> { if (wj.cz(wj.mp3 + bfqkz.xm.id)) { gj.ts(this, "你已经下载过这首歌曲了"); @@ -140,8 +140,27 @@ public class bfq extends AppCompatActivity { }.start(); } }); + if (bfqkz.xm != null) { + setname(bfqkz.xm.name); + setzz(bfqkz.xm.zz); + bfq_an.islike(); + bfqkz.mt.setTX(); + } } + public static void setname(String str) { + if (inflate == null) { + return; + } + inflate.name.setText(str); + } + + public static void setzz(String str) { + if (inflate == null) { + return; + } + inflate.zz.setText(str); + } public static Bitmap bitmap; @@ -152,7 +171,7 @@ public class bfq extends AppCompatActivity { context.startActivity(intent); } - public void kgsetImageResource(int a) { + public static void kgsetImageResource(int a) { if (inflate == null) { return; } @@ -207,4 +226,15 @@ public class bfq extends AppCompatActivity { return true; }); } + public static void setlike(boolean bool) { + if (inflate == null) { + return; + } + int color = R.color.text; + if (bool) { + color = android.R.color.holo_red_dark; + } + inflate.like.setImageTintList(ContextCompat. + getColorStateList(inflate.getRoot().getContext(), color)); + } } \ No newline at end of file diff --git a/app/src/main/java/com/muqingbfq/bfq_an.java b/app/src/main/java/com/muqingbfq/bfq_an.java index 15f4ca5..feb826a 100644 --- a/app/src/main/java/com/muqingbfq/bfq_an.java +++ b/app/src/main/java/com/muqingbfq/bfq_an.java @@ -120,6 +120,6 @@ public class bfq_an { } } bfqkz.like_bool = contains; - Media.setlike(contains); + bfq.setlike(contains); } } diff --git a/app/src/main/java/com/muqingbfq/fragment/Media.java b/app/src/main/java/com/muqingbfq/fragment/Media.java index c94e9af..ddfa9a2 100644 --- a/app/src/main/java/com/muqingbfq/fragment/Media.java +++ b/app/src/main/java/com/muqingbfq/fragment/Media.java @@ -3,42 +3,27 @@ package com.muqingbfq.fragment; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.Configuration; -import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.SeekBar; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import com.muqingbfq.R; import com.muqingbfq.bfq; import com.muqingbfq.bfq_an; import com.muqingbfq.bfqkz; -import com.muqingbfq.databinding.FragmentBfqBinding; -import com.muqingbfq.home; +import com.muqingbfq.databinding.ActivityBfqBinding; import com.muqingbfq.main; import com.muqingbfq.mq.gj; +import com.muqingbfq.view.CardImage; -import org.json.JSONException; import org.json.JSONObject; import me.wcy.lrcview.LrcView; -public class Media extends Fragment { - @SuppressLint("StaticFieldLeak") - public static LinearLayout view; - private static bfq bfq; - - public void setBfq(bfq bfq) { - Media.bfq = bfq; - } - +public class Media{ @SuppressLint("StaticFieldLeak") private static TextView time_a, time_b; @SuppressLint("StaticFieldLeak") @@ -69,30 +54,21 @@ public class Media extends Fragment { } public static void setbf(boolean bool) { - if (bfq != null) { - if (bool) { - //开始 - bfq.kgsetImageResource(R.drawable.bf); - } else { - //暂停 - bfq.kgsetImageResource(R.drawable.zt); - } + if (bool) { + //开始 + bfq.kgsetImageResource(R.drawable.bf); + } else { + //暂停 + bfq.kgsetImageResource(R.drawable.zt); } bfq_db.setkg(bool); bfqkz.updateNotification(); } - - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) { - if (view != null) { - return view; - } - FragmentBfqBinding inflate = FragmentBfqBinding.inflate(inflater, container, false); - view = inflate.getRoot(); - inflate.cardview.addView(home.imageView); - tdt = inflate.tdt; + public Media(ActivityBfqBinding binding) { + imageView = binding.cardview; + lrcview = binding.lrcView; + tdt = binding.tdt; tdt.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { @@ -112,44 +88,34 @@ public class Media extends Fragment { bfqkz.mt.seekTo(seekBar.getProgress()); } }); - - time_a = inflate.timeA; - time_b = inflate.timeB; + time_a = binding.timeA; + time_b = binding.timeB; //初始化歌词组件 lrcview.setDraggable(true, (view, time) -> { bfqkz.mt.seekTo(Math.toIntExact(time)); return false; }); - if (!isTablet(com.muqingbfq.bfq.context)) { + if (!isTablet(binding.getRoot().getContext())) { lrcview.setOnTapListener((view, x, y) -> { - View kp = inflate.kp1; + View kp = binding.kp1; if (kp.getVisibility() == View.VISIBLE) { kp.setVisibility(View.GONE); } else { kp.setVisibility(View.VISIBLE); } }); - LinearLayout.LayoutParams layoutParams = - new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.MATCH_PARENT,2); - inflate.linearlayout.addView(lrcview,layoutParams); - }else{ - LinearLayout.LayoutParams layoutParams = - new LinearLayout.LayoutParams(0, - LinearLayout.LayoutParams.MATCH_PARENT,1); - inflate.linearlayout.addView(lrcview,layoutParams); } //初始化播放器列表 if (bfqkz.xm != null) { - main.handler.removeCallbacks(bfqkz.mt.updateSeekBar); // 在播放开始时启动更新进度 +// main.handler.removeCallbacks(bfqkz.mt.updateSeekBar); // 在播放开始时启动更新进度 long duration = bfqkz.mt.getDuration(); tdt.setMax((int) bfqkz.mt.getDuration()); setTime_a(bfq_an.getTime(duration)); long position = bfqkz.mt.getCurrentPosition(); +// main.handler.post(bfqkz.mt.updateSeekBar); // 在播放开始时启动更新进度 + loadLyric(); setProgress((int) position); - main.handler.post(bfqkz.mt.updateSeekBar); // 在播放开始时启动更新进度 } - return view; } private boolean isTablet(Context context) { @@ -174,46 +140,14 @@ public class Media extends Fragment { lrcview.loadLrc(a, b); } - public static void setlike(boolean bool) { - if (bfq == null || bfq.inflate == null) { - return; - } - int color = R.color.text; - if (bool) { - color = android.R.color.holo_red_dark; - } - gj.sc(color); - bfq.inflate.like.setImageTintList(ContextCompat. - getColorStateList(com.muqingbfq.bfq.context, color)); - } + + @SuppressLint("StaticFieldLeak") + public static CardImage imageView; public static void setImageBitmap() { - if (home.imageView == null) { + if (imageView == null) { return; } - main.handler.post(() -> home.imageView.setImageBitmap(com.muqingbfq.bfq.bitmap)); - } - - public static void setname(String str) { - if (com.muqingbfq.bfq.context == null) { - return; - } - TextView name = com.muqingbfq.bfq.context.findViewById(R.id.name); - name.setText(str); - } - - public static void setzz(String str) { - if (com.muqingbfq.bfq.context == null) { - return; - } - TextView zz = com.muqingbfq.bfq.context.findViewById(R.id.zz); - zz.setText(str); - } - - public static Context Context() { - if (view == null) { - return null; - } - return view.getContext(); + main.handler.post(() -> imageView.setImage(com.muqingbfq.bfq.bitmap)); } } diff --git a/app/src/main/java/com/muqingbfq/home.java b/app/src/main/java/com/muqingbfq/home.java index e0c7db3..bb4ee4b 100644 --- a/app/src/main/java/com/muqingbfq/home.java +++ b/app/src/main/java/com/muqingbfq/home.java @@ -38,46 +38,17 @@ import me.wcy.lrcview.LrcView; public class home extends AppCompatActivity { @SuppressLint("StaticFieldLeak") public static AppCompatActivity appCompatActivity; - @SuppressLint("StaticFieldLeak") - public static ImageView imageView; ActivityHomeBinding binding; - @Override protected void onCreate(Bundle savedInstanceState) { appCompatActivity = this; setTheme(R.style.Theme_muqing); super.onCreate(savedInstanceState); - if (false) { - com.muqingbfq.mq.floating.start(this); - } binding = ActivityHomeBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); DisplayMetrics dm = getResources().getDisplayMetrics(); main.k = dm.widthPixels; main.g = dm.heightPixels; - if (imageView == null) { - imageView = new ImageView(this); - imageView.setScaleType(ImageView.ScaleType.FIT_XY); - if (bfq.bitmap == null) { - imageView.setImageResource(R.drawable.icon); - } else { - Media.setImageBitmap(); - } - } - if (Media.lrcview == null) { - // 在合适的位置初始化LrcView - Media.lrcview = new LrcView(this); - // 请将Context替换为实际的上下文对象 - // 设置LrcView的属性 - Media.lrcview.setCurrentColor(ContextCompat.getColor(this,R.color.text)); - Media.lrcview.setLabel(getString(R.string.app_name)); - Media.lrcview.setCurrentTextSize(TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_SP, 16, getResources().getDisplayMetrics())); -// lrcView.setLrcPadding(16); - Media.lrcview.setCurrentTextSize(TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_SP, 20, getResources().getDisplayMetrics())); - Media.lrcview.setTimelineTextColor(ContextCompat.getColor(this,R.color.text_tm)); - } try { //初始化工具栏 setSupportActionBar(binding.toolbar); @@ -108,7 +79,6 @@ public class home extends AppCompatActivity { } List list = new ArrayList<>(); - private class adaper extends FragmentStateAdapter { public adaper(@NonNull FragmentActivity fragmentActivity) { super(fragmentActivity); diff --git a/app/src/main/java/com/muqingbfq/mq/wj.java b/app/src/main/java/com/muqingbfq/mq/wj.java index 4c22638..68433e9 100644 --- a/app/src/main/java/com/muqingbfq/mq/wj.java +++ b/app/src/main/java/com/muqingbfq/mq/wj.java @@ -77,6 +77,9 @@ public class wj { public static String dqwb(String url) { try { File file = new File(url); + if (!file.exists()) { + return null; + } FileInputStream fis = new FileInputStream(file); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); StringBuilder str = new StringBuilder(); @@ -97,9 +100,6 @@ public class wj { return new File(url).exists(); } - public static boolean cz(File file) { - return file.exists(); - } public static boolean sc(String url) { File file = new File(url); diff --git a/app/src/main/java/com/muqingbfq/view/CardImage.java b/app/src/main/java/com/muqingbfq/view/CardImage.java new file mode 100644 index 0000000..f79f60c --- /dev/null +++ b/app/src/main/java/com/muqingbfq/view/CardImage.java @@ -0,0 +1,42 @@ +package com.muqingbfq.view; + +import android.content.Context; +import android.graphics.Bitmap; +import android.util.AttributeSet; +import android.widget.ImageView; + +import com.bumptech.glide.Glide; +import com.google.android.material.card.MaterialCardView; +import com.muqingbfq.R; + +public class CardImage extends MaterialCardView { + private ImageView imageView; + + public CardImage(Context context) { + super(context); + start(); + } + public CardImage(Context context, AttributeSet attrs) { + super(context, attrs); + start(); + } + + public CardImage(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + start(); + } + + public void start() { + imageView = new ImageView(getContext()); + imageView.setScaleType(ImageView.ScaleType.FIT_XY); + addView(imageView); + setImage(R.drawable.icon); + } + + + public void setImage(Object bitmap) { + Glide.with(getContext()) + .load(bitmap) + .into(imageView); + } +} diff --git a/app/src/main/res/layout-land/activity_bfq.xml b/app/src/main/res/layout-land/activity_bfq.xml index a9a85c4..fce6cea 100644 --- a/app/src/main/res/layout-land/activity_bfq.xml +++ b/app/src/main/res/layout-land/activity_bfq.xml @@ -38,13 +38,69 @@ - + android:orientation="vertical"> + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_bfq.xml b/app/src/main/res/layout/activity_bfq.xml index 3ad9de4..4418565 100644 --- a/app/src/main/res/layout/activity_bfq.xml +++ b/app/src/main/res/layout/activity_bfq.xml @@ -38,13 +38,71 @@ - + android:orientation="vertical"> + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - \ No newline at end of file