public class MyApp extends Application {
private static final String TAG = "---MyApp";
private Context context;getOptions
@Override
public void onCreate() {
super.onCreate();
context = this;
Log.d(TAG, "应用创建---");
initImageLoader();
}
private void initImageLoader() {
//Configuration 配置
//Builder 建造者模式
//存到images
String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/images";
File file = new File(sdcardPath);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
//内存配置
.memoryCacheExtraOptions(480, 800) // default = device screen dimensions
//磁盘缓存
// .diskCacheExtraOptions(480, 800, Bitmap.CompressFormat.JPEG, 75, null)
.threadPoolSize(3) // 线程池里面线程的数量
.threadPriority(Thread.NORM_PRIORITY - 1) // 线程优先级
.tasksProcessingOrder(QueueProcessingType.FIFO) // default
.memoryCache(new LruMemoryCache(2 * 1024 * 1024))//内存缓存的大小
.memoryCacheSize(2 * 1024 * 1024)
.diskCache(new UnlimitedDiskCache(file)) // 指sdcard的缓存路径
.diskCacheSize(50 * 1024 * 1024)//指sdcard的缓存大小
// .diskCacheFileCount(100)//指sdcard的缓存文件数量
.diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
.imageDownloader(new BaseImageDownloader(context)) // default
// .imageDecoder(new BaseImageDecoder()) // 图片解码
.defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
.writeDebugLogs()
.build();
//记得配置到ImageLoader
ImageLoader.getInstance().init(config);
}
//加载图片时候的配置
public static DisplayImageOptions getOptions() {
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.mipmap.ic_launcher) // 加载过程中显示的图片
.showImageForEmptyUri(R.mipmap.ic_launcher) //当地址为空的时候显示的图片
.showImageOnFail(R.mipmap.ic_launcher) // 加载错误时显示的图片
.resetViewBeforeLoading(true) // 加载前重置视图
.cacheInMemory(true) // 启动内存缓存
.cacheOnDisk(true) // 启动磁盘缓存
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
.bitmapConfig(Bitmap.Config.ARGB_8888) // default
.displayer(new SimpleBitmapDisplayer()) // default
.displayer(new FadeInBitmapDisplayer(100))
.handler(new Handler()) // default
.build();
return options;
}
}
private static final String TAG = "---MyApp";
private Context context;getOptions
@Override
public void onCreate() {
super.onCreate();
context = this;
Log.d(TAG, "应用创建---");
initImageLoader();
}
private void initImageLoader() {
//Configuration 配置
//Builder 建造者模式
//存到images
String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/images";
File file = new File(sdcardPath);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
//内存配置
.memoryCacheExtraOptions(480, 800) // default = device screen dimensions
//磁盘缓存
// .diskCacheExtraOptions(480, 800, Bitmap.CompressFormat.JPEG, 75, null)
.threadPoolSize(3) // 线程池里面线程的数量
.threadPriority(Thread.NORM_PRIORITY - 1) // 线程优先级
.tasksProcessingOrder(QueueProcessingType.FIFO) // default
.memoryCache(new LruMemoryCache(2 * 1024 * 1024))//内存缓存的大小
.memoryCacheSize(2 * 1024 * 1024)
.diskCache(new UnlimitedDiskCache(file)) // 指sdcard的缓存路径
.diskCacheSize(50 * 1024 * 1024)//指sdcard的缓存大小
// .diskCacheFileCount(100)//指sdcard的缓存文件数量
.diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
.imageDownloader(new BaseImageDownloader(context)) // default
// .imageDecoder(new BaseImageDecoder()) // 图片解码
.defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
.writeDebugLogs()
.build();
//记得配置到ImageLoader
ImageLoader.getInstance().init(config);
}
//加载图片时候的配置
public static DisplayImageOptions getOptions() {
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.mipmap.ic_launcher) // 加载过程中显示的图片
.showImageForEmptyUri(R.mipmap.ic_launcher) //当地址为空的时候显示的图片
.showImageOnFail(R.mipmap.ic_launcher) // 加载错误时显示的图片
.resetViewBeforeLoading(true) // 加载前重置视图
.cacheInMemory(true) // 启动内存缓存
.cacheOnDisk(true) // 启动磁盘缓存
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
.bitmapConfig(Bitmap.Config.ARGB_8888) // default
.displayer(new SimpleBitmapDisplayer()) // default
.displayer(new FadeInBitmapDisplayer(100))
.handler(new Handler()) // default
.build();
return options;
}
}