fix:切换图片时会白屏的问题
This commit is contained in:
parent
b04bd7ca5a
commit
3aef3c1504
@ -69,48 +69,16 @@ public class MainActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_main);
|
||||
handler = new Handler(Looper.myLooper());
|
||||
initView();
|
||||
play.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (browserHelper.isPlayer()) {
|
||||
browserHelper.getTransportControls().pause();
|
||||
} else {
|
||||
browserHelper.getTransportControls().play();
|
||||
}
|
||||
}
|
||||
});
|
||||
play.setOnClickListener(v -> handler.post(() -> {
|
||||
|
||||
if (browserHelper.isPlayer()) {
|
||||
browserHelper.getTransportControls().pause();
|
||||
} else {
|
||||
browserHelper.getTransportControls().play();
|
||||
}
|
||||
});
|
||||
next.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
browserHelper.getTransportControls().skipToNext();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
previous.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
browserHelper.getTransportControls().skipToPrevious();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}));
|
||||
next.setOnClickListener(v -> handler.post(() -> browserHelper.getTransportControls().skipToNext()));
|
||||
previous.setOnClickListener(v -> handler.post(() -> browserHelper.getTransportControls().skipToPrevious()));
|
||||
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
@ -124,27 +92,21 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (browserHelper.getTransportControls() != null) {
|
||||
browserHelper.getTransportControls().seekTo(MainActivity.this.seekBar.getProgress());
|
||||
}
|
||||
handler.post(() -> {
|
||||
if (browserHelper.getTransportControls() != null) {
|
||||
browserHelper.getTransportControls().seekTo(MainActivity.this.seekBar.getProgress());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
playModel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int model = (int) playModel.getTag();
|
||||
if (model == MusicContainer.PLAY_MODEL_LIST_RANDOM) {
|
||||
setPlayModelButton(MusicContainer.PLAY_MODEL_RANDOM, true);
|
||||
return;
|
||||
}
|
||||
setPlayModelButton(model + 1, true);
|
||||
playModel.setOnClickListener(v -> {
|
||||
int model = (int) playModel.getTag();
|
||||
if (model == MusicContainer.PLAY_MODEL_LIST_RANDOM) {
|
||||
setPlayModelButton(MusicContainer.PLAY_MODEL_RANDOM, true);
|
||||
return;
|
||||
}
|
||||
setPlayModelButton(model + 1, true);
|
||||
});
|
||||
|
||||
browserHelper = new MediaBrowserHelper(this);
|
||||
@ -190,26 +152,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
int seconds = (int) (data.getDurationAsDouble() % 60);
|
||||
durationTime.setText(String.format(Locale.CHINA, "%02d", minutes) + ":"
|
||||
+ String.format(Locale.CHINA, "%02d", seconds));
|
||||
int model = ConfigTools.getPreferences().getInt("playModel", MusicContainer.PLAY_MODEL_RANDOM);
|
||||
int model = ConfigTools.getConfigPreferences().getInt("playModel", MusicContainer.PLAY_MODEL_RANDOM);
|
||||
setPlayModelButton(model);
|
||||
if (data.getImg(AppData.imageWidth, AppData.imageHigh) != null) {
|
||||
setImage(data);
|
||||
} else {
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (data.getImg(AppData.imageWidth, AppData.imageHigh) != null) {
|
||||
AppData.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setImage(data);
|
||||
}
|
||||
});
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}, 0, 100);
|
||||
}
|
||||
setImage(data);
|
||||
|
||||
}
|
||||
|
||||
@ -243,17 +188,17 @@ public class MainActivity extends AppCompatActivity {
|
||||
break;
|
||||
default:
|
||||
setPlayModelButton(MusicContainer.PLAY_MODEL_RANDOM, isButton);
|
||||
return;
|
||||
}
|
||||
ConfigTools.getPreferences().edit().putInt("playModel", model).apply();
|
||||
}
|
||||
|
||||
private void setImage(MusicData data) {
|
||||
// setBarColor(data.getImageColor());
|
||||
Glide.with(this).load(data.getImg(AppData.imageWidth, AppData.imageHigh))
|
||||
.placeholder(album_image.getDrawable())
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
||||
.into(album_image);
|
||||
Glide.with(this).load(data.getImg(AppData.minImageWidth, AppData.minImageHigh))
|
||||
.placeholder(background_image.getDrawable())
|
||||
.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)))
|
||||
.into(background_image);
|
||||
}
|
||||
@ -274,7 +219,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
playModel = findViewById(R.id.playModel);
|
||||
playIndex = findViewById(R.id.playIndex);
|
||||
touch = new GestureDetectorCompat(this, new MyTouch());
|
||||
int model = ConfigTools.getPreferences().getInt("playModel", MusicContainer.PLAY_MODEL_RANDOM);
|
||||
int model = ConfigTools.getConfigPreferences().getInt("playModel", MusicContainer.PLAY_MODEL_RANDOM);
|
||||
setPlayModelButton(model);
|
||||
}
|
||||
|
||||
@ -358,11 +303,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
} else {
|
||||
dialog.setTitle("播放列表:" + playList.size());
|
||||
MusicLibsAdapter adapter = new MusicLibsAdapter(this);
|
||||
// ItemTouchHelper touchHelper=new ItemTouchHelper(new MusicItemTouchAdapterCallback());
|
||||
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
recyclerView = new RecyclerView(this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.setLayoutParams(params);
|
||||
recyclerView.setAdapter(adapter);
|
||||
// touchHelper.attachToRecyclerView(recyclerView);
|
||||
adapter.setData(playList);
|
||||
adapter.setBrowserHelper(browserHelper);
|
||||
dialog.setContentView(recyclerView);
|
||||
|
Loading…
Reference in New Issue
Block a user