Пример #1
0
 public Bitmap getCache(Context context) {
   if (cache == null || cache.isRecycled()) {
     File bmp_catch = StorageUtils.getIndividualCacheDirectory(context, "bmp_catch");
     try {
       File file = new File(bmp_catch, uriOrigin.toString().hashCode() + "");
       if (!file.exists()) return null;
       FileInputStream fileInputStream = new FileInputStream(file);
       cache = BitmapFactory.decodeStream(fileInputStream);
       return cache;
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   return cache;
 }
Пример #2
0
 public void setCache(Bitmap cache, Context context, boolean fileCache) {
   this.cache = Bitmap.createBitmap(cache);
   if (!fileCache) return;
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   cache.compress(Bitmap.CompressFormat.PNG, 0, baos); // 压缩位图
   byte[] cacheBytes = baos.toByteArray(); // 创建分配字节数组
   File bmp_catch = StorageUtils.getIndividualCacheDirectory(context, "bmp_catch");
   try {
     File file = new File(bmp_catch, uriOrigin.toString().hashCode() + "");
     FileOutputStream fileOutputStream = new FileOutputStream(file);
     fileOutputStream.write(cacheBytes);
     fileOutputStream.flush();
     fileOutputStream.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 /** Creates default implementation of {@link DiskCache} depends on incoming parameters */
 public static DiskCache createDiskCache(
     Context context,
     FileNameGenerator diskCacheFileNameGenerator,
     long diskCacheSize,
     int diskCacheFileCount) {
   File reserveCacheDir = createReserveDiskCacheDir(context);
   if (diskCacheSize > 0 || diskCacheFileCount > 0) {
     File individualCacheDir = StorageUtils.getIndividualCacheDirectory(context);
     LruDiscCache diskCache =
         new LruDiscCache(
             individualCacheDir, diskCacheFileNameGenerator, diskCacheSize, diskCacheFileCount);
     diskCache.setReserveCacheDir(reserveCacheDir);
     return diskCache;
   } else {
     File cacheDir = StorageUtils.getCacheDirectory(context);
     return new UnlimitedDiscCache(cacheDir, reserveCacheDir, diskCacheFileNameGenerator);
   }
 }
 /**
  * Creates default implementation of {@link
  * com.nostra13.universalimageloader.cache.disc.DiskCache} depends on incoming parameters
  */
 public static DiskCache createDiskCache(
     Context context,
     FileNameGenerator diskCacheFileNameGenerator,
     long diskCacheSize,
     int diskCacheFileCount) {
   File reserveCacheDir = createReserveDiskCacheDir(context);
   if (diskCacheSize > 0 || diskCacheFileCount > 0) {
     File individualCacheDir = StorageUtils.getIndividualCacheDirectory(context);
     try {
       return new LruDiskCache(
           individualCacheDir,
           reserveCacheDir,
           diskCacheFileNameGenerator,
           diskCacheSize,
           diskCacheFileCount);
     } catch (IOException e) {
       L.e(e);
       // continue and create unlimited cache
     }
   }
   File cacheDir = StorageUtils.getCacheDirectory(context);
   return new UnlimitedDiskCache(cacheDir, reserveCacheDir, diskCacheFileNameGenerator);
 }