修复闪退BUG

This commit is contained in:
muqing 2023-12-26 20:36:04 +08:00
parent c7e3897f38
commit f44943d726
13 changed files with 242 additions and 275 deletions

View File

@ -53,7 +53,7 @@
<activity android:name=".activity_search" />
<activity
android:name=".bfq"
android:configChanges="keyboardHidden|orientation|screenSize"
android:configChanges="keyboardHidden|screenSize"
android:theme="@style/fragment_dialog" />
<activity android:name=".fragment.mp3" />

View File

@ -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);

View File

@ -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) {

View File

@ -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));
}
}

View File

@ -120,6 +120,6 @@ public class bfq_an {
}
}
bfqkz.like_bool = contains;
Media.setlike(contains);
bfq.setlike(contains);
}
}

View File

@ -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,7 +54,6 @@ public class Media extends Fragment {
}
public static void setbf(boolean bool) {
if (bfq != null) {
if (bool) {
//开始
bfq.kgsetImageResource(R.drawable.bf);
@ -77,22 +61,14 @@ public class Media extends Fragment {
//暂停
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));
}
}

View File

@ -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<Fragment> list = new ArrayList<>();
private class adaper extends FragmentStateAdapter {
public adaper(@NonNull FragmentActivity fragmentActivity) {
super(fragmentActivity);

View File

@ -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);

View File

@ -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);
}
}

View File

@ -38,13 +38,69 @@
</LinearLayout>
</com.google.android.material.appbar.MaterialToolbar>
<androidx.fragment.app.FragmentContainerView
<LinearLayout
android:id="@+id/fragment_bfq"
android:name="com.muqingbfq.fragment.Media"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:layout="@layout/fragment_bfq" />
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/kp1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
tools:ignore="NestedWeights">
<com.muqingbfq.view.CardImage
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="16dp"
app:cardUseCompatPadding="true" />
</RelativeLayout>
<me.wcy.lrcview.LrcView
android:id="@+id/lrcView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bj"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="3dp"
android:paddingEnd="3dp">
<TextView
android:id="@+id/time_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_00_00" />
<SeekBar
android:id="@+id/tdt"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:padding="6dp" />
<TextView
android:id="@+id/time_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_00_00" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"

View File

@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/kp1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
tools:ignore="NestedWeights">
<com.google.android.material.card.MaterialCardView
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="16dp"
app:cardUseCompatPadding="true" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:background="@color/bj"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="3dp"
android:paddingEnd="3dp">
<TextView
android:id="@+id/time_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_00_00" />
<SeekBar
android:id="@+id/tdt"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:padding="6dp" />
<TextView
android:id="@+id/time_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_00_00" />
</LinearLayout>
</LinearLayout>

View File

@ -38,13 +38,71 @@
</LinearLayout>
</com.google.android.material.appbar.MaterialToolbar>
<androidx.fragment.app.FragmentContainerView
<LinearLayout
android:id="@+id/fragment_bfq"
android:name="com.muqingbfq.fragment.Media"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:layout="@layout/fragment_bfq" />
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/kp1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
tools:ignore="NestedWeights">
<com.muqingbfq.view.CardImage
android:id="@+id/cardview"
android:layout_width="256dp"
android:layout_height="256dp"
app:cardCornerRadius="16dp"
app:cardUseCompatPadding="true" />
</RelativeLayout>
<me.wcy.lrcview.LrcView
android:id="@+id/lrcView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bj"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="3dp"
android:paddingEnd="3dp">
<TextView
android:id="@+id/time_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_00_00" />
<SeekBar
android:id="@+id/tdt"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:padding="6dp" />
<TextView
android:id="@+id/time_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_00_00" />
</LinearLayout>
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"

View File

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/kp1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
tools:ignore="NestedWeights">
<com.google.android.material.card.MaterialCardView
android:id="@+id/cardview"
android:layout_width="260dp"
android:layout_height="260dp"
app:cardCornerRadius="16dp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="@color/bj"
android:paddingStart="3dp"
android:paddingEnd="3dp">
<TextView
android:id="@+id/time_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_00_00" />
<SeekBar
android:id="@+id/tdt"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:padding="6dp" />
<TextView
android:id="@+id/time_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_00_00" />
</LinearLayout>
</LinearLayout>