package com.mjsheng.myappstore.image;

import android.content.Context;

import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory;
import com.bumptech.glide.module.AppGlideModule;
import com.mjsheng.myappstore.download.StorageUtils;

/**
 * Created by Administrator on 2017/2/9.
 */
@com.bumptech.glide.annotation.GlideModule
public class MyGlideModule extends AppGlideModule {
    @Override
    public void applyOptions(final Context context, GlideBuilder builder) {
        // 设置图片的显示格式  低内存时降低图片质量
//        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
//        if (activityManager != null){
//            ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
//            activityManager.getMemoryInfo(memoryInfo);
//            builder.setDecodeFormat(memoryInfo.lowMemory ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888);
//        }
        builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
        //设置磁盘缓存目录（和创建的缓存目录相同）
        String downloadDirectoryPath = StorageUtils.getFileCache(context, "imageCache");
        //设置缓存的大小为100M
        int cacheSize = 100 * 1024 * 1024;
        builder.setDiskCache(
                new DiskLruCacheFactory(downloadDirectoryPath, cacheSize));
    }
    /**
     * 清单解析的开启
     *
     * 这里不开启，避免添加相同的modules两次
     * @return
     */
    @Override
    public boolean isManifestParsingEnabled() {
        return false;
    }
}

