riku
2022-02-18 d59d55575d913646b7a90fca651904ab889c6723
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package cn.flightfeather.thirdappmodule.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);
    }
 
 
}