Commit 4555129f authored by gaodapeng's avatar gaodapeng

优化了bitmap的回收

parent d3c90cdb
package com.widget.imagevideobanner.banner;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
......@@ -88,10 +91,10 @@ public class ImageVideoFragment extends Fragment {
view = LayoutInflater.from(getActivity()).inflate(R.layout.item_image_view, container, false);
ImageView imageView = view.findViewById(R.id.iv);
File file = new File(bannerBean.getUrl());
if(file.exists()){
if (file.exists()) {
Glide.with(container.getContext()).load(file)
.into(imageView);
}else {
} else {
Glide.with(container.getContext()).load(bannerBean.getUrl())
.into(imageView);
}
......@@ -116,21 +119,20 @@ public class ImageVideoFragment extends Fragment {
*/
public void setPicture() {
//视频未加载完成,使用菊花
if(bannerBean.getLoadingImage() == null){
if(bannerBean.getUrl().contains("android.resource")){
ivWaitLoading.setVisibility(View.VISIBLE);
ivWaitLoading.setImageResource(R.drawable.guide_defaut);
llWaitLoading.setVisibility(View.GONE);
}else{
ivWaitLoading.setVisibility(View.GONE);
llWaitLoading.setVisibility(View.VISIBLE);
}
}else{//加载完成使用首帧图片
ivWaitLoading.setVisibility(View.VISIBLE);
ivWaitLoading.setImageBitmap(BitmapUtils.getBitmap(bannerBean.getLoadingImage()));
llWaitLoading.setVisibility(View.GONE);
}
if (bannerBean.getLoadingImage() == null) {
if (bannerBean.getUrl().contains("android.resource")) {
ivWaitLoading.setVisibility(View.VISIBLE);
ivWaitLoading.setImageResource(R.drawable.guide_defaut);
llWaitLoading.setVisibility(View.GONE);
} else {
ivWaitLoading.setVisibility(View.GONE);
llWaitLoading.setVisibility(View.VISIBLE);
}
} else {//加载完成使用首帧图片
ivWaitLoading.setVisibility(View.VISIBLE);
ivWaitLoading.setImageBitmap(BitmapUtils.getBitmap(bannerBean.getLoadingImage()));
llWaitLoading.setVisibility(View.GONE);
}
}
......@@ -142,7 +144,7 @@ public class ImageVideoFragment extends Fragment {
mVideoView.requestFocus();
try {
mVideoView.setVideoURI(Uri.parse(bannerBean.getUrl()));
}catch (Exception e){
} catch (Exception e) {
}
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
......@@ -221,7 +223,7 @@ public class ImageVideoFragment extends Fragment {
public void startPlayer() {
if (null != mVideoView) {
// setWaitLoading();
Log.e(TAG, "startPlayer "+currentPosition);
Log.e(TAG, "startPlayer " + currentPosition);
mVideoView.setBackgroundColor(Color.TRANSPARENT);
mVideoView.seekTo(currentPosition);
mVideoView.start();
......@@ -265,7 +267,7 @@ public class ImageVideoFragment extends Fragment {
private void pausePlayer() {
if (null != mVideoView) {
Log.e(TAG, "pausePlayer 当前进度是"+mVideoView.getCurrentPosition());
Log.e(TAG, "pausePlayer 当前进度是" + mVideoView.getCurrentPosition());
mVideoView.setBackgroundColor(getResources().getColor(R.color.white));
playerPaused = true;
this.currentPosition = mVideoView.getCurrentPosition();
......@@ -351,6 +353,21 @@ public class ImageVideoFragment extends Fragment {
sendPauseVideoMsg();
}
@Override
public void onDestroyView() {
if (ivWaitLoading != null) {
Drawable drawable = ivWaitLoading.getDrawable();
ivWaitLoading.setImageDrawable(null);
if (drawable instanceof BitmapDrawable) {
Bitmap bm = ((BitmapDrawable) drawable).getBitmap();
if (!bm.isRecycled()) {
bm.recycle();
}
}
}
super.onDestroyView();
}
@Override
public void onDestroy() {
super.onDestroy();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment