예제 #1
0
  /** 初始化imageloader */
  private void initImageLoader() {
    File cacheDir = StorageUtils.getOwnCacheDirectory(getApplicationContext(), "imageloader/Cache");

    DisplayImageOptions defaultOptions =
        new DisplayImageOptions.Builder()
            .cacheInMemory(true) // 加载图片时会在内存中加载缓存
            .cacheOnDisk(true) // 加载图片时会在磁盘中加载缓存
            .build();

    ImageLoaderConfiguration config =
        new ImageLoaderConfiguration.Builder(this)
            .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 UnlimitedDiscCache(cacheDir))
            // default
            .diskCacheSize(20 * 1024 * 1024)
            .diskCacheFileCount(100)
            .diskCacheFileNameGenerator(new Md5FileNameGenerator()) // default
            .defaultDisplayImageOptions(defaultOptions) // default
            .writeDebugLogs()
            .build();
    ImageLoader.getInstance().init(config);
  }
예제 #2
0
  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) {

    }
  }
예제 #3
0
 public static void initImageLoader(Context context) {
   // 配置图片缓存路径
   File cacheDir = StorageUtils.getOwnCacheDirectory(context, "IMG/cache");
   // 配置ImageLoaderConfiguration
   ImageLoaderConfiguration config =
       new ImageLoaderConfiguration.Builder(context)
           // max width, max,height,即保存的每个缓存文件的最大长宽
           // .memoryCacheExtraOptions(400, 400)
           // 线程池内加载的数量
           .threadPoolSize(3)
           // 线程优先级
           .threadPriority(Thread.NORM_PRIORITY)
           // 硬盘缓存50MB
           .discCacheSize(50 * 1024 * 1024)
           // 将保存的时候的URI名称用MD5
           .discCacheFileNameGenerator(new Md5FileNameGenerator())
           // 将保存的时候的URI名称用HASHCODE加密
           .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
           .tasksProcessingOrder(QueueProcessingType.LIFO)
           // 缓存的File数量
           .discCacheFileCount(100)
           // 自定义缓存路径
           .discCache(new UnlimitedDiscCache(cacheDir))
           // 设置图片显示配置
           .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
           // connectTimeout (5 s), readTimeout (30 s)超时时间
           .imageDownloader(new BaseImageDownloader(context, 5 * 1000, 30 * 1000))
           .build();
   ImageLoader.getInstance().init(config);
 }
예제 #4
0
  private void initImageLoader() {
    File cacheDir =
        com.nostra13.universalimageloader.utils.StorageUtils.getOwnCacheDirectory(
            this, "imageloader/Cache");

    DisplayImageOptions defaultOptions =
        new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).build();

    ImageLoaderConfiguration config =
        new ImageLoaderConfiguration.Builder(getApplicationContext())
            .defaultDisplayImageOptions(defaultOptions)
            .memoryCache(new LruMemoryCache(12 * 1024 * 1024))
            .memoryCacheSize(12 * 1024 * 1024)
            .discCacheSize(32 * 1024 * 1024)
            .discCacheFileCount(100)
            .discCache(new UnlimitedDiscCache(cacheDir))
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .tasksProcessingOrder(QueueProcessingType.LIFO)
            .build();
    ImageLoader.getInstance().init(config);
    options =
        new DisplayImageOptions.Builder()
            .showStubImage(R.drawable.top_banner_android)
            .showImageForEmptyUri(R.drawable.top_banner_android)
            .showImageOnFail(R.drawable.top_banner_android)
            .cacheInMemory(true)
            .cacheOnDisc(true)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .imageScaleType(ImageScaleType.EXACTLY)
            .build();
  }
예제 #5
0
 /** Call the dialog asking for image input */
 protected void generationImageTemp() {
   File tempPath = StorageUtils.getOwnCacheDirectory(this, Consts.APP_FOLDER_CACHE);
   mNewImageName = String.valueOf(System.currentTimeMillis()) + Consts.PHOTO_JPG_EXTENSION;
   mNewImagePath = tempPath.getAbsolutePath() + mNewImageName;
   File file = new File(tempPath, mNewImageName);
   mNewImageUri = Uri.fromFile(file);
 }
예제 #6
0
  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());
    }
  }
예제 #7
0
 @Override
 public void onCreate() {
   super.onCreate();
   File cacheDir =
       StorageUtils.getOwnCacheDirectory(getApplicationContext(), "Pictures/rubychina");
   ImageLoaderConfiguration config =
       new ImageLoaderConfiguration.Builder(getApplicationContext())
           .threadPoolSize(3)
           .discCache(new UnlimitedDiscCache(cacheDir))
           .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
           .build();
   ImageLoader.getInstance().init(config);
   sContext = getApplicationContext();
 }
예제 #8
0
 /** 初始化ImageLoader */
 public static void initImageLoader(Context context) {
   File cacheDir = StorageUtils.getOwnCacheDirectory(context, "qctt/Cache"); // 获取到缓存的目录地址
   Log.d("cacheDir", cacheDir.getPath());
   ImageLoaderConfiguration config =
       new ImageLoaderConfiguration.Builder(context)
           .threadPoolSize(3)
           .threadPriority(Thread.NORM_PRIORITY - 2)
           .denyCacheImageMultipleSizesInMemory()
           .discCacheFileNameGenerator(new Md5FileNameGenerator()) // 将保存的时�?的URI名称用MD5
           // 加密
           .tasksProcessingOrder(QueueProcessingType.LIFO)
           .discCache(new UnlimitedDiscCache(cacheDir)) // 自定义缓存路�?
           .writeDebugLogs() // Remove for release app
           .build();
   ImageLoader.getInstance().init(config); // 全局初始化此配置
 }
예제 #9
0
파일: App.java 프로젝트: LYDXY/QuickNews
  /** 初始化ImageLoader */
  public static void initImageLoader(Context context) {
    String filePath =
        Environment.getExternalStorageDirectory()
            + "/Android/data/"
            + context.getPackageName()
            + "/cache/";

    File cacheDir = StorageUtils.getOwnCacheDirectory(context, filePath); // 获取到缓存的目录地址
    Log.d("cacheDir", cacheDir.getPath());
    // 创建配置ImageLoader(所有的选项都是可选的,只使用那些你真的想定制),这个可以设定在APPLACATION里面,设置为全局的配置参数
    ImageLoaderConfiguration config =
        new ImageLoaderConfiguration.Builder(context)
            // .memoryCacheExtraOptions(480, 800) // max width, max
            // height,即保存的每个缓存文件的最大长宽
            // .discCacheExtraOptions(480, 800, CompressFormat.JPEG,
            // 75, null) // Can slow ImageLoader, use it carefully
            // (Better don't use it)设置缓存的详细信息,最好不要设置这个
            .threadPoolSize(3) // 线程池内加载的数量
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .denyCacheImageMultipleSizesInMemory()
            .memoryCache(new WeakMemoryCache())
            // .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024
            // * 1024)) // You can pass your own memory cache
            // implementation你可以通过自己的内存缓存实现
            .memoryCacheSize(2 * 1024 * 1024)
            // /.discCacheSize(50 * 1024 * 1024)
            .discCacheFileNameGenerator(new Md5FileNameGenerator()) // 将保存的时候的URI名称用MD5
            // 加密
            // .discCacheFileNameGenerator(new
            // HashCodeFileNameGenerator())//将保存的时候的URI名称用HASHCODE加密
            .tasksProcessingOrder(QueueProcessingType.LIFO)
            // .discCacheFileCount(100) //缓存的File数量
            .discCache(new UnlimitedDiscCache(cacheDir)) // 自定义缓存路径
            .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
            .imageDownloader(
                new BaseImageDownloader(context, 5 * 1000, 30 * 1000)) // connectTimeout (5 s),
            // readTimeout(30)// 超时时间
            .writeDebugLogs() // Remove for release app
            .build();
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config); // 全局初始化此配置
  }
예제 #10
0
 /** 初始化ImageLoader */
 public static void initImageLoader(Context context) {
   File cacheDir = StorageUtils.getOwnCacheDirectory(context, "bmobim/Cache"); // 获取到缓存的目录地址
   // 创建配置ImageLoader(所有的选项都是可选的,只使用那些你真的想定制),这个可以设定在APPLACATION里面,设置为全局的配置参数
   ImageLoaderConfiguration config =
       new ImageLoaderConfiguration.Builder(context)
           // 线程池内加载的数量
           .threadPoolSize(3)
           .threadPriority(Thread.NORM_PRIORITY - 2)
           .memoryCache(new WeakMemoryCache())
           .denyCacheImageMultipleSizesInMemory()
           .discCacheFileNameGenerator(new Md5FileNameGenerator())
           // 将保存的时候的URI名称用MD5 加密
           .tasksProcessingOrder(QueueProcessingType.LIFO)
           .discCache(new UnlimitedDiscCache(cacheDir)) // 自定义缓存路径
           // .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
           .writeDebugLogs() // Remove for release app
           .build();
   // Initialize ImageLoader with configuration.
   ImageLoader.getInstance().init(config); // 全局初始化此配置
 }
예제 #11
0
  private void initImageLoader() {
    categoryLoadOption =
        new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.product_icon_default) // resource or drawable
            .showImageForEmptyUri(R.drawable.product_icon_default) // resource or drawable
            .showImageOnFail(R.drawable.product_icon_default) // resource or drawable
            .resetViewBeforeLoading(false) // default
            .delayBeforeLoading(500)
            .cacheInMemory(true) // default
            .cacheOnDisk(true) // default
            .imageScaleType(ImageScaleType.EXACTLY)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .build();

    File cacheDir = StorageUtils.getOwnCacheDirectory(getApplicationContext(), "imageloader/Cache");

    Util.sysLog(TAG, "image cache path:" + cacheDir.getAbsolutePath());
    ImageLoaderConfiguration config =
        new ImageLoaderConfiguration.Builder(this)
            .defaultDisplayImageOptions(categoryLoadOption)
            .memoryCacheExtraOptions(480, 800)
            .diskCacheExtraOptions(480, 800, null)
            .threadPoolSize(2)
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .denyCacheImageMultipleSizesInMemory()
            .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
            .memoryCacheSize(2 * 1024 * 1024)
            .diskCacheFileNameGenerator(new Md5FileNameGenerator())
            .diskCacheSize(50 * 1024 * 1024)
            .diskCacheFileCount(100)
            .diskCache(new UnlimitedDiscCache(cacheDir))
            .tasksProcessingOrder(QueueProcessingType.FIFO)
            .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
            .writeDebugLogs()
            .build();

    ImageLoader.getInstance().init(config);
  }
예제 #12
0
  /** 初始化ImageLoader */
  public static void initImageLoader(Context context) {
    File cacheDir = StorageUtils.getOwnCacheDirectory(context, "qctt/Cache"); // 获取到缓存的目录地址
    Log.d("cacheDir", cacheDir.getPath());
    // 创建配置ImageLoader(�?��的�?项都是可选的,只使用那些你真的想定�?,这个可以设定在APPLACATION里面,设置为全局的配置参�?
    ImageLoaderConfiguration config =
        new ImageLoaderConfiguration.Builder(context)
            // .memoryCacheExtraOptions(480, 800) // max width, max
            // height,即保存的每个缓存文件的�?��长宽
            //				 .discCacheExtraOptions(480, 800, CompressFormat.JPEG, 0,
            //				 null) // Can slow ImageLoader, use it carefully (Better don't
            // use it)设置缓存的详细信息,�?��不要设置这个
            // .threadPoolSize(3)//线程池内加载的数�?

            .threadPoolSize(3)
            // 线程池内加载的数�?
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .denyCacheImageMultipleSizesInMemory()
            // .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 *
            // 1024)) // You can pass your own memory cache
            // implementation你可以�?过自己的内存缓存实现
            // .memoryCacheSize(2 * 1024 * 1024)
            // /.discCacheSize(50 * 1024 * 1024)
            .discCacheFileNameGenerator(new Md5FileNameGenerator()) // 将保存的时�?的URI名称用MD5
            // 加密
            // .discCacheFileNameGenerator(new
            // HashCodeFileNameGenerator())//将保存的时�?的URI名称用HASHCODE加密
            .tasksProcessingOrder(QueueProcessingType.LIFO)
            // .discCacheFileCount(100) //缓存的File数量
            .discCache(new UnlimitedDiscCache(cacheDir)) // 自定义缓存路�?
            // .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
            // .imageDownloader(new BaseImageDownloader(context, 5 * 1000,
            // 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间
            .writeDebugLogs() // Remove for release app
            .build();
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config); // 全局初始化此配置
  }
예제 #13
0
  private ImageLoaderConfiguration getDefaultConfig() throws IOException {
    int MAX_CACHE_MEMORY_SIZE = (int) (Runtime.getRuntime().maxMemory() / 8);
    File cacheDir =
        StorageUtils.getOwnCacheDirectory(context, context.getPackageName() + "/cache/image/");

    LogUtil.i(TAG, "ImageLoader memory cache size = " + MAX_CACHE_MEMORY_SIZE / M + "M");
    LogUtil.i(TAG, "ImageLoader disk cache directory = " + cacheDir.getAbsolutePath());

    ImageLoaderConfiguration config =
        new ImageLoaderConfiguration.Builder(context)
            .threadPoolSize(3) // 线程池内加载的数量
            .threadPriority(Thread.NORM_PRIORITY - 2) // 降低线程的优先级,减小对UI主线程的影响
            .denyCacheImageMultipleSizesInMemory()
            .memoryCache(new LruMemoryCache(MAX_CACHE_MEMORY_SIZE))
            .discCache(new LruDiskCache(cacheDir, new Md5FileNameGenerator(), 0))
            .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
            .imageDownloader(
                new BaseImageDownloader(
                    context, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间
            .writeDebugLogs()
            .build();

    return config;
  }