Java Code Examples for com.nostra13.universalimageloader.utils.StorageUtils#getOwnCacheDirectory()

The following examples show how to use com.nostra13.universalimageloader.utils.StorageUtils#getOwnCacheDirectory() . 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: 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 2
Source File: MyApplication.java    From AndroidCacheFoundation with Apache License 2.0 6 votes vote down vote up
/**
 * Universal Image Loader Setup
 */
private void setupUIL() {
    File cacheDir = StorageUtils.getOwnCacheDirectory(
            getApplicationContext(), "CafeCar/cache");
    options = new DisplayImageOptions.Builder()
            .cacheOnDisc(true).cacheInMemory(true).build();
    cache = new TotalSizeLimitedDiscCache(cacheDir, 50 * 1024 * 1024);
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            getApplicationContext()).threadPoolSize(3)
            .threadPriority(Thread.NORM_PRIORITY - 1)
            .denyCacheImageMultipleSizesInMemory()
            .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
                    // You can pass your own memory cache implementation
            .discCache(cache)
                    // You can pass your own disc cache implementation
            .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
            .defaultDisplayImageOptions(options).build();
    ImageLoader.getInstance().init(config);
}
 
Example 3
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 4
Source File: ImageLoaderUtil.java    From sctalk with Apache License 2.0 5 votes vote down vote up
public static void initImageLoaderConfig(Context context) {
        try {
            File cacheDir = StorageUtils.getOwnCacheDirectory(context, CommonUtil.getSavePath(SysConstant.FILE_SAVE_TYPE_IMAGE));
            File reserveCacheDir = StorageUtils.getCacheDirectory(context);

            int maxMemory = (int) (Runtime.getRuntime().maxMemory() );
            // 使用最大可用内存值的1/8作为缓存的大小。
            int cacheSize = maxMemory/8;
            DisplayMetrics metrics=new DisplayMetrics();
            WindowManager mWm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
            mWm.getDefaultDisplay().getMetrics(metrics);

            IMImageLoaderConfig = new ImageLoaderConfiguration.Builder(context)
                    .memoryCacheExtraOptions(metrics.widthPixels, metrics.heightPixels)
                    .threadPriority(Thread.NORM_PRIORITY-2)
//                    .denyCacheImageMultipleSizesInMemory()
                    .memoryCache(new UsingFreqLimitedMemoryCache(cacheSize))
                    .diskCacheFileNameGenerator(new Md5FileNameGenerator())
                    .tasksProcessingOrder(QueueProcessingType.LIFO)
                    .diskCacheExtraOptions(metrics.widthPixels, metrics.heightPixels, null)
                    .diskCache(new UnlimitedDiscCache(cacheDir,reserveCacheDir,new Md5FileNameGenerator()))
                    .diskCacheSize(1024 * 1024 * 1024)
                    .diskCacheFileCount(1000)
                    .build();

            IMImageLoadInstance = ImageLoader.getInstance();
            IMImageLoadInstance.init(IMImageLoaderConfig);
        }catch (Exception e){
            logger.e(e.toString());
        }
    }
 
Example 5
Source File: SdCacheTools.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
public static File getOwnLogCacheDir(Context context) {
    File imageCache = StorageUtils.getOwnCacheDirectory(context,
            "WP/logs");
    if (!imageCache.exists()) {
        imageCache.mkdirs();
    }
    return imageCache;
}
 
Example 6
Source File: MediaStoreUtils.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
public static File getOwnImageCacheDir(Context context) {
	File imageCache = StorageUtils.getOwnCacheDirectory(context,
			"AG/images");
	if (!imageCache.exists()) {
		imageCache.mkdirs();
	}
	return imageCache;
}
 
Example 7
Source File: MediaStoreUtils.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
public static File getOwnAudioCacheDir(Context context) {
	File imageCache = StorageUtils.getOwnCacheDirectory(context,
			"AG/audios");
	if (!imageCache.exists()) {
		imageCache.mkdirs();
	}
	return imageCache;
}
 
Example 8
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 9
Source File: DemoApplication.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public static void initImageLoader(Context context) {
	File cacheDir = StorageUtils.getOwnCacheDirectory(context,
			"leanchat/Cache");
	ImageLoaderConfiguration config = PhotoUtil.getImageLoaderConfig(
			context, cacheDir);
	// Initialize ImageLoader with configuration.
	ImageLoader.getInstance().init(config);
}
 
Example 10
Source File: ImageLoaderSetting.java    From Pas with Apache License 2.0 4 votes vote down vote up
public static void initImageLoader(Context context) {

        // 设置缓存 路径
        File cacheDir = StorageUtils.getOwnCacheDirectory(context,
                "eh2h/imageloader/Cache");

        //默认
        defaultOptions = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.defaultbg)
                .showImageForEmptyUri(R.mipmap.defaultbg)
                .showImageOnFail(R.mipmap.defaultbg)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
                        //.displayer(new FadeInBitmapDisplayer(300, true, true, true))
                        //.displayer(new RoundedBitmapDisplayer(90))
                .delayBeforeLoading(100)//载入图片前稍做延时可以提高整体滑动的流畅度
                .bitmapConfig(Bitmap.Config.RGB_565).build();



        animateFirstListener = new AnimateFirstDisplayListener();


        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
                .diskCacheExtraOptions(480, 800, null)
                .threadPoolSize(3) // default
                .threadPriority(Thread.NORM_PRIORITY - 2) // default
                .tasksProcessingOrder(QueueProcessingType.FIFO) // default
                .denyCacheImageMultipleSizesInMemory()
                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
                .memoryCacheSize(2 * 1024 * 1024)
                .memoryCacheSizePercentage(13) // default
                .diskCache(new UnlimitedDiskCache(cacheDir)) // default
                .diskCacheSize(50 * 1024 * 1024)
                .diskCacheFileCount(100)
                .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
                .imageDownloader(new BaseImageDownloader(context)) // default
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
               // .writeDebugLogs()
                .build();


        ImageLoader.getInstance().init(config);
    }
 
Example 11
Source File: ImageLoaderSetting.java    From Pas with Apache License 2.0 4 votes vote down vote up
public static void initImageLoader(Context context) {

        // 设置缓存 路径
        File cacheDir = StorageUtils.getOwnCacheDirectory(context,
                "eh2h/imageloader/Cache");

        //默认
        defaultOptions = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.ic_launcher)
                .showImageForEmptyUri(R.mipmap.ic_launcher)
                .showImageOnFail(R.mipmap.ic_launcher)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
                        //.displayer(new FadeInBitmapDisplayer(300, true, true, true))
                        //.displayer(new RoundedBitmapDisplayer(90))
                .delayBeforeLoading(100)//载入图片前稍做延时可以提高整体滑动的流畅度
                .bitmapConfig(Bitmap.Config.RGB_565).build();



        animateFirstListener = new AnimateFirstDisplayListener();


        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
                .diskCacheExtraOptions(480, 800, null)
                .threadPoolSize(3) // default
                .threadPriority(Thread.NORM_PRIORITY - 2) // default
                .tasksProcessingOrder(QueueProcessingType.FIFO) // default
                .denyCacheImageMultipleSizesInMemory()
                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
                .memoryCacheSize(2 * 1024 * 1024)
                .memoryCacheSizePercentage(13) // default
                .diskCache(new UnlimitedDiskCache(cacheDir)) // default
                .diskCacheSize(50 * 1024 * 1024)
                .diskCacheFileCount(100)
                .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
                .imageDownloader(new BaseImageDownloader(context)) // default
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
               // .writeDebugLogs()
                .build();


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