Java Code Examples for com.nostra13.universalimageloader.core.ImageLoaderConfiguration#Builder

The following examples show how to use com.nostra13.universalimageloader.core.ImageLoaderConfiguration#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UniversalImageLoader.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
     * Get default ImageLoaderConfiguration.Builder,and you can easily change the builder.
     * @param context
     * @return
     */
    public static ImageLoaderConfiguration.Builder getDefaultImageLoaderConfigurationBuilder(Context context) {
        File cacheDir = StorageUtils.getCacheDirectory(context);
        ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context)
//                .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
//                .discCacheExtraOptions(480, 800, Bitmap.CompressFormat.JPEG, 75, null)
                .threadPoolSize(3) // default
                .threadPriority(Thread.NORM_PRIORITY - 1) // default
                .tasksProcessingOrder(QueueProcessingType.FIFO) // default
                .denyCacheImageMultipleSizesInMemory()
//                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
//                .memoryCacheSize(2 * 1024 * 1024)
                .memoryCacheSizePercentage(13) // default
                .diskCache(new UnlimitedDiskCache(cacheDir)) // default
//                .discCacheSize(50 * 1024 * 1024)
                .diskCacheFileCount(1000)
                .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
                .imageDownloader(new BaseImageDownloader(context)) // default
                .imageDecoder(new BaseImageDecoder(false)) // default
                        //   .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
                .defaultDisplayImageOptions(getDefaultImageOptions());
        return builder;
    }
 
Example 2
Source File: EditorActivity.java    From RichEditText with Apache License 2.0 6 votes vote down vote up
public void initImageLoader(Context context) {
	// This configuration tuning is custom. You can tune every option, you
	// may tune some of them,
	// or you can create default configuration by
	// ImageLoaderConfiguration.createDefault(this);
	// method.
	ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(
			context);
	config.threadPriority(Thread.NORM_PRIORITY - 2);
	config.denyCacheImageMultipleSizesInMemory();
	config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
	config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
	config.tasksProcessingOrder(QueueProcessingType.LIFO);
	config.writeDebugLogs(); // Remove for release app

	// Initialize ImageLoader with configuration.
	ImageLoader.getInstance().init(config.build());
	
}
 
Example 3
Source File: UILApplication.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 6 votes vote down vote up
public static void initImageLoader(Context context) {
	// This configuration tuning is custom. You can tune every option, you may tune some of them,
	// or you can create default configuration by
	//  ImageLoaderConfiguration.createDefault(this);
	// method.
	ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
	config.threadPriority(Thread.NORM_PRIORITY - 2);
	config.denyCacheImageMultipleSizesInMemory();
	config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
	config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
	config.tasksProcessingOrder(QueueProcessingType.LIFO);
	config.writeDebugLogs(); // Remove for release app

	// Initialize ImageLoader with configuration.
	ImageLoader.getInstance().init(config.build());
}
 
Example 4
Source File: MainActivity.java    From GalleryFinal with Apache License 2.0 6 votes vote down vote up
private void initImageLoader(Context context) {
    // This configuration tuning is custom. You can tune every option, you may tune some of them,
    // or you can create default configuration by
    //  ImageLoaderConfiguration.createDefault(this);
    // method.
    ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
    config.threadPriority(Thread.NORM_PRIORITY - 2);
    config.denyCacheImageMultipleSizesInMemory();
    config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
    config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
    config.tasksProcessingOrder(QueueProcessingType.LIFO);
    config.writeDebugLogs(); // Remove for release app

    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config.build());
}
 
Example 5
Source File: CustomGalleryActivity.java    From MultipleImagePicker with Apache License 2.0 6 votes vote down vote up
private void initImageLoader() {
	try {
		String CACHE_DIR = Environment.getExternalStorageDirectory()
				.getAbsolutePath() + "/.temp_tmp";
		new File(CACHE_DIR).mkdirs();

		File cacheDir = StorageUtils.getOwnCacheDirectory(getBaseContext(),
				CACHE_DIR);

		DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
				.cacheOnDisc(true).imageScaleType(ImageScaleType.EXACTLY)
				.bitmapConfig(Bitmap.Config.RGB_565).build();
		ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(
				getBaseContext())
				.defaultDisplayImageOptions(defaultOptions)
				.discCache(new UnlimitedDiscCache(cacheDir))
				.memoryCache(new WeakMemoryCache());

		ImageLoaderConfiguration config = builder.build();
		imageLoader = ImageLoader.getInstance();
		imageLoader.init(config);

	} catch (Exception e) {

	}
}
 
Example 6
Source File: UniversalImageLoader.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public static ImageLoaderConfiguration.Builder getDefaultImageLoaderConfigurationBuilder(Context context) {
        File cacheDir = StorageUtils.getCacheDirectory(context);
        ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context)
//                .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
//                .discCacheExtraOptions(480, 800, Bitmap.CompressFormat.JPEG, 75, null)
                .threadPoolSize(3) // default
                .threadPriority(Thread.NORM_PRIORITY - 1) // default
                .tasksProcessingOrder(QueueProcessingType.FIFO) // default
                .denyCacheImageMultipleSizesInMemory()
//                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
//                .memoryCacheSize(2 * 1024 * 1024)
                .memoryCacheSizePercentage(13) // default
                .discCache(new UnlimitedDiscCache(cacheDir)) // default
//                .discCacheSize(50 * 1024 * 1024)
                .discCacheFileCount(1000)
                .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
                .imageDownloader(new BaseImageDownloader(context)) // default
                .imageDecoder(new BaseImageDecoder(false)) // default
                        //   .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
                .defaultDisplayImageOptions(getDefaultImageOptions());
        return builder;
    }
 
Example 7
Source File: MyApp.java    From ImageLoadingView with Apache License 2.0 6 votes vote down vote up
private void initImageLoader(Context context) {
    ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
    config.denyCacheImageMultipleSizesInMemory();
    config.diskCacheSize(50 * 1024 * 1024);
    config.tasksProcessingOrder(QueueProcessingType.LIFO);
    ImageLoader.getInstance().init(config.build());

    defaultOptions = new DisplayImageOptions.Builder()
            .cacheInMemory(false)
            .cacheOnDisk(true)
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)//设置图片以如何的编码方式显示
            .showImageOnLoading(R.mipmap.loading)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .showImageOnFail(R.mipmap.loading)
            .showImageForEmptyUri(R.mipmap.loading)
            .build();

    ImageLoader.getInstance().clearDiskCache();
    ImageLoader.getInstance().clearMemoryCache();
}
 
Example 8
Source File: UILKit.java    From XRichText with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化
 *
 * @param context
 */
private UILKit(Context context) {
    File cacheDir = getDiskCacheDir(context, "img");

    ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .denyCacheImageMultipleSizesInMemory()
            .memoryCacheSize(10 * 1024 * 1024)
            .diskCache(new UnlimitedDiskCache(cacheDir))
            .diskCacheFileNameGenerator(new Md5FileNameGenerator())
            .diskCacheSize(50 * 1024 * 1024) // 50 MiB
            .tasksProcessingOrder(QueueProcessingType.LIFO);

    ImageLoader.getInstance().init(config.build());



    picOptions = new DisplayImageOptions.Builder()
            .imageScaleType(ImageScaleType.EXACTLY)
            .cacheOnDisk(false).cacheInMemory(false)
            .resetViewBeforeLoading(true)
            .displayer(new FadeInBitmapDisplayer(500)).build();
}
 
Example 9
Source File: GirlApplication.java    From Girls with Apache License 2.0 5 votes vote down vote up
public static void initImageLoader(Context context) {
    // This configuration tuning is custom. You can tune every option, you may tune some of them,
    // or you can create default configuration by
    //  ImageLoaderConfiguration.createDefault(this);
    // method.
    ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
    config.threadPriority(Thread.NORM_PRIORITY - 2);
    config.denyCacheImageMultipleSizesInMemory();
    config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
    config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
    config.tasksProcessingOrder(QueueProcessingType.LIFO);
    config.writeDebugLogs(); // Remove for release app
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config.build());
}
 
Example 10
Source File: GalleryActivity.java    From MutiPhotoChoser with Mozilla Public License 2.0 5 votes vote down vote up
private void initImageLoader() {
    if (options == null) {
        DisplayImageOptions.Builder displayBuilder = new DisplayImageOptions.Builder();
        displayBuilder.cacheInMemory(true);
        displayBuilder.cacheOnDisk(true);
        displayBuilder.showImageOnLoading(R.drawable.default_photo);
        displayBuilder.showImageForEmptyUri(R.drawable.default_photo);
        displayBuilder.considerExifParams(true);
        displayBuilder.bitmapConfig(Bitmap.Config.RGB_565);
        displayBuilder.imageScaleType(ImageScaleType.EXACTLY);
        displayBuilder.displayer(new FadeInBitmapDisplayer(300));
        options = displayBuilder.build();
    }

    if (!ImageLoader.getInstance().isInited()) {
        ImageLoaderConfiguration.Builder loaderBuilder = new ImageLoaderConfiguration.Builder(getApplication());
        loaderBuilder.memoryCacheSize(getMemoryCacheSize());

        try {
            File cacheDir = new File(getExternalCacheDir() + File.separator + CacheConstant.IMAGE_CACHE_DIRECTORY);
            loaderBuilder.diskCache(new LruDiscCache(cacheDir, DefaultConfigurationFactory.createFileNameGenerator(), 500 * 1024 * 1024));
        } catch (IOException e) {
            e.printStackTrace();
        }
        ImageLoader.getInstance().init(loaderBuilder.build());
    }

}
 
Example 11
Source File: DemoApplication.java    From JCVideoPlayer with MIT License 5 votes vote down vote up
private void initUniversalImageLoader() {
    ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(getApplicationContext());
    config.threadPriority(Thread.NORM_PRIORITY - 2);
    config.denyCacheImageMultipleSizesInMemory();
    config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
    config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
    config.tasksProcessingOrder(QueueProcessingType.LIFO);
    config.writeDebugLogs(); // Remove for releaseAllVideos app
    config.defaultDisplayImageOptions(getDefaultDisplayImageOption());
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config.build());
}
 
Example 12
Source File: ImageLoadProxy.java    From JianDan_OkHttp with Apache License 2.0 5 votes vote down vote up
public static void initImageLoader(Context context) {
    ImageLoaderConfiguration.Builder build = new ImageLoaderConfiguration.Builder(context);
    build.tasksProcessingOrder(QueueProcessingType.LIFO);
    build.diskCacheSize(MAX_DISK_CACHE);
    build.memoryCacheSize(MAX_MEMORY_CACHE);
    build.memoryCache(new LruMemoryCache(MAX_MEMORY_CACHE));

    if (BuildConfig.DEBUG && isShowLog) {
        build.writeDebugLogs();
    }
    getImageLoader().init(build.build());
}
 
Example 13
Source File: BlurImageView.java    From BlurImageView with Apache License 2.0 5 votes vote down vote up
private void initUIL() {
  ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(mContext);
  config.threadPriority(Thread.NORM_PRIORITY - 2);
  config.denyCacheImageMultipleSizesInMemory();
  config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
  config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
  config.tasksProcessingOrder(QueueProcessingType.LIFO);
  config.writeDebugLogs(); // Remove for release app

  // Initialize ImageLoader with configuration.
  ImageLoader.getInstance().init(config.build());
}
 
Example 14
Source File: ImageLoaderHelper.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
public ImageLoaderConfiguration getImageLoaderConfiguration(String filePath) {
    File cacheDir = null;
    if (!CommonUtils.isEmpty(filePath)) {
        cacheDir = StorageUtils.getOwnCacheDirectory(mContext, filePath);
    } else {
        cacheDir = StorageUtils.getCacheDirectory(mContext);
    }

    ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(mContext);
    builder.denyCacheImageMultipleSizesInMemory();

    builder.diskCacheSize(512 * 1024 * 1024);
    builder.diskCacheExtraOptions(720, 1280, null);
    builder.diskCache(new UnlimitedDiscCache(cacheDir));
    builder.diskCacheFileNameGenerator(new Md5FileNameGenerator());

    builder.memoryCacheSizePercentage(14);
    builder.memoryCacheSize(2 * 1024 * 1024);
    builder.memoryCacheExtraOptions(720, 1280);
    builder.memoryCache(new WeakMemoryCache());

    builder.threadPoolSize(3);
    builder.threadPriority(Thread.NORM_PRIORITY - 2);

    builder.defaultDisplayImageOptions(getDisplayOptions());

    return builder.build();
}
 
Example 15
Source File: UniversalImageLoader.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public static ImageLoaderConfiguration getDefaultImageLoaderConfiguration(Context context, boolean isWriteLog) {
    ImageLoaderConfiguration.Builder builder = getDefaultImageLoaderConfigurationBuilder(context);
    if (isWriteLog) {
        builder.writeDebugLogs();
    }
    ImageLoaderConfiguration config = builder.build();
    return config;
}
 
Example 16
Source File: ICApplication.java    From ImageChooser with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化ImageLoader
 * 
 * @param context
 */
public static void initImageLoader(Context context) {
    ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory()
            .discCacheFileNameGenerator(new Md5FileNameGenerator())
            .memoryCache(new WeakMemoryCache()).discCacheSize(8 * 1024 * 1024)
            .tasksProcessingOrder(QueueProcessingType.LIFO);
    // 如果是调试模式,输出日志,否则不输出
    if (BuildConfig.DEBUG) {
        builder.writeDebugLogs();
    }
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(builder.build());
}
 
Example 17
Source File: App.java    From json2notification with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(getApplicationContext());
    config.threadPriority(Thread.NORM_PRIORITY - 2);
    config.denyCacheImageMultipleSizesInMemory();
    config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
    config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
    config.tasksProcessingOrder(QueueProcessingType.LIFO);
    config.writeDebugLogs(); // Remove for release app

    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config.build());
}
 
Example 18
Source File: UniversalImageLoader.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * Get default ImageLoaderConfiguration and you can choose the ImageLoader will write log or not.
 * @param context
 * @param isWriteLog
 * @return
 */
public static ImageLoaderConfiguration getDefaultImageLoaderConfiguration(Context context, boolean isWriteLog) {
    ImageLoaderConfiguration.Builder builder = getDefaultImageLoaderConfigurationBuilder(context);
    if (isWriteLog) {
        builder.writeDebugLogs();
    }
    ImageLoaderConfiguration config = builder.build();
    return config;
}
 
Example 19
Source File: ImageLoaderConfig.java    From fitness_Android with Apache License 2.0 5 votes vote down vote up
/**
 * 异步图片加载ImageLoader的初始化操作,在Application中调用此方法
 * 
 * @param context
 *            上下文对象
 * @param cacheDisc
 *            图片缓存到SDCard的目录,只需要传入SDCard根目录下的子目录即可,默认会建立在SDcard的根目录下
 */
public static void initImageLoader(Context context, String cacheDisc) {
	
	// 配置ImageLoader
	// 获取本地缓存的目录,该目录在SDCard的根目录下
	File cacheDir = StorageUtils.getOwnCacheDirectory(context, cacheDisc);
	// 实例化Builder
	ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(
			context);
	// 设置线程数量
	builder.threadPoolSize(3);
	// 设定线程等级比普通低一点
	builder.threadPriority(Thread.NORM_PRIORITY);
	// 设定内存缓存为弱缓存
	builder.memoryCache(new WeakMemoryCache());
	// 设定内存图片缓存大小限制,不设置默认为屏幕的宽高
	builder.memoryCacheExtraOptions(480, 800);
	// 设定只保存同一尺寸的图片在内存
	builder.denyCacheImageMultipleSizesInMemory();
	// 设定缓存的SDcard目录,UnlimitDiscCache速度最快
	builder.discCache(new UnlimitedDiscCache(cacheDir));
	// 设定缓存到SDCard目录的文件命名
	builder.discCacheFileNameGenerator(new HashCodeFileNameGenerator());
	// 设定网络连接超时 timeout: 10s 读取网络连接超时read timeout: 60s
	builder.imageDownloader(new BaseImageDownloader(context, 10000, 60000));
	// 设置ImageLoader的配置参数
	builder.defaultDisplayImageOptions(initDisplayOptions(true));

	// 初始化ImageLoader
	ImageLoader.getInstance().init(builder.build());
}
 
Example 20
Source File: ImageLoadProxy.java    From JianDanRxJava with Apache License 2.0 5 votes vote down vote up
public static void initImageLoader(Context context) {
    ImageLoaderConfiguration.Builder build = new ImageLoaderConfiguration.Builder(context);
    build.tasksProcessingOrder(QueueProcessingType.LIFO);
    build.diskCacheSize(MAX_DISK_CACHE);
    build.memoryCacheSize(MAX_MEMORY_CACHE);
    build.memoryCache(new LruMemoryCache(MAX_MEMORY_CACHE));

    if (BuildConfig.DEBUG && isShowLog) {
        build.writeDebugLogs();
    }
    getImageLoader().init(build.build());
}