use of com.nostra13.universalimageloader.cache.disc.DiskCache in project CustomViews by AndroidStudy233.
the class MyApplication method initImageLoader.
/**
* 初始化ImageLoader
*/
private void initImageLoader() {
File cacheDir = getCacheDir();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).memoryCacheExtraOptions(480, // max width, max height,即保存的每个缓存文件的最大长宽
800).threadPoolSize(// 线程池内加载的数量
3).threadPriority(// 线程优先级
Thread.NORM_PRIORITY - 1).denyCacheImageMultipleSizesInMemory().memoryCache(new WeakMemoryCache()).memoryCacheSize(// 内存缓存2MB
2 * 1024 * 1024).tasksProcessingOrder(QueueProcessingType.LIFO).diskCache(// 限制缓存时长
new LimitedAgeDiskCache(cacheDir, 7 * 24 * 60 * 60)).diskCacheSize(// 本地缓存50MB
50 * 1024 * 1024).diskCacheFileNameGenerator(// MD5加密名字
new Md5FileNameGenerator()).defaultDisplayImageOptions(// 设置默认选项
DisplayImageOptions.createSimple()).imageDownloader(// connectTimeout (5 s), readTimeout (30 s)超时时间
new BaseImageDownloader(getApplicationContext(), 5 * 1000, 20 * 1000)).build();
// 开始构建
ImageLoader.getInstance().init(config);
}
use of com.nostra13.universalimageloader.cache.disc.DiskCache in project AndLang by wugemu.
the class BaseLangApplication method initImageLoad.
private void initImageLoad() {
// 配置uil工具
File cacheDir = StorageUtils.getOwnCacheDirectory(getApplicationContext(), tmpImageDir);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).memoryCacheExtraOptions(480, // default = device screen dimensions
800).threadPriority(// default
Thread.NORM_PRIORITY - 1).tasksProcessingOrder(// default
QueueProcessingType.FIFO).threadPoolSize(3).denyCacheImageMultipleSizesInMemory().memoryCache(new LruMemoryCache(2 * 1024 * 1024)).memoryCacheSize(2 * 1024 * 1024).memoryCacheSizePercentage(// default
13).diskCache(new UnlimitedDiskCache(cacheDir)).diskCacheSize(// 缓冲大小
50 * 1024 * 1024).diskCacheFileCount(// 缓冲文件数目
100).diskCacheFileNameGenerator(// default
new HashCodeFileNameGenerator()).imageDownloader(// default
new BaseImageDownloader(this)).defaultDisplayImageOptions(// default
DisplayImageOptions.createSimple()).writeDebugLogs().build();
// 2.单例ImageLoader类的初始化
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
ImageLoadUtils.setImageSetter(new IInnerImageSetter() {
@Override
public <IMAGE extends ImageView> void doLoadImageUrl(@NonNull IMAGE view, @Nullable String url) {
if (!BaseLangUtil.isEmpty(url)) {
if (url.toLowerCase().contains(".gif")) {
GlideUtil.getInstance().displayGif(getApplicationContext(), url, view);
} else {
GlideUtil.getInstance().display(getApplicationContext(), url, view);
}
}
}
@Override
public <IMAGE extends ImageView> void doLoadImageUrlCenterCrop(@NonNull IMAGE view, @Nullable String url) {
if (!BaseLangUtil.isEmpty(url)) {
if (url.toLowerCase().contains(".gif")) {
GlideUtil.getInstance().displayGifCenterCrop(getApplicationContext(), url, view);
} else {
GlideUtil.getInstance().displayCenterCrop(getApplicationContext(), url, view);
}
}
}
@Override
public <IMAGE extends ImageView> void doLoadImageUrlFitCenter(@NonNull IMAGE view, @Nullable String url) {
if (!BaseLangUtil.isEmpty(url)) {
if (url.toLowerCase().contains(".gif")) {
GlideUtil.getInstance().displayGifFitCenter(getApplicationContext(), url, view);
} else {
GlideUtil.getInstance().displayFitCenter(getApplicationContext(), url, view);
}
}
}
@Override
public <IMAGE extends ImageView> void doLoadCircleImageUrl(@NonNull IMAGE view, @Nullable String url) {
if (!BaseLangUtil.isEmpty(url)) {
if (url.toLowerCase().contains(".gif")) {
GlideUtil.getInstance().displayGif(getApplicationContext(), url, view);
} else {
GlideUtil.getInstance().displayHead(getApplicationContext(), url, view);
}
}
}
@Override
public <IMAGE extends ImageView> void doLoadImageRound(@NonNull IMAGE view, @Nullable String url, float round) {
if (!BaseLangUtil.isEmpty(url)) {
if (url.toLowerCase().contains(".gif")) {
GlideUtil.getInstance().displayGif(getApplicationContext(), url, view);
} else {
GlideUtil.getInstance().displayRoundImg(getApplicationContext(), url, view, round);
}
}
}
@Override
public <IMAGE extends ImageView> void doLoadByImageLoader(@NonNull IMAGE view, @Nullable String url) {
// 测试比较加载速度使用
ImageLoader.getInstance().displayImage(url, view, BOUTIQUE_OPTIPON);
}
@Override
public <IMAGE extends ImageView> void doLoadImageRes(@NonNull IMAGE view, @Nullable int resId) {
GlideUtil.getInstance().displayLocRes(getApplicationContext(), resId, view);
}
});
}
use of com.nostra13.universalimageloader.cache.disc.DiskCache in project QuickAndroid by ImKarl.
the class QAImageLoaderConfig method getConfig.
/**
* 获取加载配置
* @param context
* @param imageOnLoadingRes 加载中显示的图片
* @param imageOnFailRes 加载失败显示的图片
* @return
*/
public static ImageLoaderConfiguration getConfig(Context context, int imageOnLoadingRes, int imageOnFailRes) {
DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(// 加载中
imageOnLoadingRes).showImageForEmptyUri(// 图片Uri为空或是错误的时候显示的图片
imageOnFailRes).showImageOnFail(// resource or drawable
imageOnFailRes).resetViewBeforeLoading(// default
false).delayBeforeLoading(// 加载前延迟时长
50).cacheInMemory(// default = false 是否使用内存缓存
true).cacheOnDisk(// default = false 是否使用文件缓存
true).considerExifParams(// default = false
false).imageScaleType(// default
ImageScaleType.IN_SAMPLE_POWER_OF_2).bitmapConfig(// default
Bitmap.Config.ARGB_8888).displayer(// default = new SimpleBitmapDisplayer()
new FadeInBitmapDisplayer(100)).build();
File cacheDir = new File(QAFileManager.getUsableDir(context.getPackageName()));
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPoolSize(// default 线程池大小
3).threadPriority(// default 线程优先级
Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().memoryCache(// 内存缓存
new LruMemoryCache(8 * 1024 * 1024)).diskCache(// default 磁盘缓存
new UnlimitedDiskCache(cacheDir)).diskCacheSize(// 磁盘缓存大小
30 * 1024 * 1024).diskCacheFileNameGenerator(// default 磁盘缓存文件名
new HashCodeFileNameGenerator()).imageDownloader(// default 图片下载器
new BaseImageDownloader(context)).imageDecoder(// default 图片解码器
new BaseImageDecoder(QACore.isDebug())).defaultDisplayImageOptions(// default=DisplayImageOptions.createSimple() 图片显示选项
options).build();
return config;
}
use of com.nostra13.universalimageloader.cache.disc.DiskCache in project PLDroidPlayer by pili-engineering.
the class MainActivity method initImageLoader.
private void initImageLoader() {
// sdcard目录
File cacheDir = StorageUtils.getOwnCacheDirectory(this, DEFAULT_CACHE_DIR_NAME);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).diskCache(// default 可以自定义缓存路径
new UnlimitedDiskCache(cacheDir)).diskCacheSize(50 * 1024 * 1024).diskCacheFileCount(100).memoryCache(new LruMemoryCache(2 * 1024 * 1024)).memoryCacheSize(2 * 1024 * 1024).memoryCacheSizePercentage(13).build();
ImageLoader.getInstance().init(config);
}
use of com.nostra13.universalimageloader.cache.disc.DiskCache in project yellowmessenger-sdk by yellowmessenger.
the class DrawableManager method getInstance.
public static DrawableManager getInstance(Context context) {
if (drawableManager == null) {
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).displayer(new FadeInBitmapDisplayer(500)).resetViewBeforeLoading(true).build();
// for caching
File cacheDir = StorageUtils.getOwnCacheDirectory(context, "image_cache");
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).defaultDisplayImageOptions(defaultOptions).diskCache(new UnlimitedDiskCache(cacheDir)).threadPoolSize(5).memoryCacheSize(20000000).denyCacheImageMultipleSizesInMemory().diskCacheFileNameGenerator(new HashCodeFileNameGenerator()).build();
ImageLoader.getInstance().init(config);
drawableManager = new DrawableManager();
}
return drawableManager;
}
Aggregations