package cn.flightfeather.thirdapp.adapter;
|
|
import android.content.Context;
|
import android.support.v4.view.PagerAdapter;
|
import android.view.View;
|
import android.view.ViewGroup;
|
|
import com.bm.library.PhotoView;
|
import com.bumptech.glide.Glide;
|
|
import java.io.File;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* Created by hyhb01 on 2018/3/26.
|
*/
|
|
public class CommonPagerAdapter extends PagerAdapter {
|
private List<File> fileList;
|
private List<PhotoView> viewList;
|
private List<String> titleList;
|
private Context context;
|
private View currentView;
|
private boolean hasAdd = false;
|
|
public CommonPagerAdapter(List<PhotoView> viewList, List<String> titleList, Context context) {
|
this.viewList = viewList;
|
this.titleList = titleList;
|
this.fileList = new ArrayList<>();
|
}
|
|
public CommonPagerAdapter(List<File> fileList, Context context) {
|
this.fileList = fileList;
|
this.context = context;
|
this.viewList = new ArrayList<PhotoView>();
|
this.titleList = new ArrayList<>();
|
for (int i = 0; i < fileList.size(); i++) {
|
viewList.add(new PhotoView(context));
|
}
|
}
|
|
@Override
|
public int getCount() {
|
return fileList.size();
|
}
|
|
@Override
|
public boolean isViewFromObject(View view, Object object) {
|
return view == object;
|
}
|
|
@Override
|
public Object instantiateItem(ViewGroup container, int position) {
|
|
// Bitmap bm = PhotoUtil.decodeSampledBitmapFromResource(fileList.get(position).getAbsolutePath(), ScreenUtils.getScreenWidth(context), ScreenUtils.getScreenHeight(context));
|
// viewList.get(position).setImageBitmap(bm);
|
|
Glide.with(container)
|
.load(fileList.get(position))
|
.into(viewList.get(position));
|
container.addView(viewList.get(position));
|
|
return viewList.get(position);
|
}
|
|
@Override
|
public void destroyItem(ViewGroup container, int position, Object object) {
|
// BitmapDrawable bitmapDrawable = (BitmapDrawable) viewList.get(position).getDrawable();
|
// viewList.get(position).setImageDrawable(null);
|
// if (bitmapDrawable != null) {
|
// Bitmap bitmap = bitmapDrawable.getBitmap();
|
// if (bitmap != null) {
|
// bitmap.recycle();
|
// System.gc();
|
// }
|
// }
|
|
container.removeView(viewList.get(position));
|
}
|
|
@Override
|
public CharSequence getPageTitle(int position) {
|
return titleList.get(position);
|
}
|
|
|
}
|