Пример #1
0
 /**
  * get one image from three places, imageMemoryCache,imageFileCache,network
  *
  * @param url The URL of the image to download.
  * @return Bitmap return a bitmap
  */
 private Bitmap getBitmap(final String url) {
   if (null == url || "".equals(url)) {
     return null;
   }
   // get image from mLruMemoryCache
   Bitmap result = null;
   result = mLruMemoryCache.get(url);
   if (result == null) {
     // get image from imageFileCache
     result = imageFileCache.getImage(url);
     if (result == null) {
       // get image from network
       //                result = getImageHttp(url);
       result = getImageFromHttp(url);
       if (result != null) {
         if (mLruMemoryCache.get(url) == null) {
           mLruMemoryCache.put(url, result);
         }
         imageFileCache.addImgToSDTask(url, result);
       }
     } else {
       if (mLruMemoryCache.get(url) == null) {
         mLruMemoryCache.put(url, result);
       }
     }
   }
   return result;
 }
Пример #2
0
  public Bitmap getBitmap(String url) {
    // 从内存缓存中获取图片
    Bitmap result = memoryCache.getBitmapFromCache(url);
    if (result == null) {
      // 文件缓存中获取
      result = fileCache.getImage(url);
      if (result == null) {
        // 从网络获取
        result = getBitmapFromWeb(url);
        if (result != null) {
          fileCache.saveBitmap(result, url);
          memoryCache.addBitmapToCache(url, result);
          System.out.println("图片从网络中获取");
        }
      } else {
        // 添加到内存缓存
        memoryCache.addBitmapToCache(url, result);
        System.out.println("图片从文件缓存中获取");
      }
    } else {
      System.out.println("图片从内存缓存中获取");
    }

    return result;
  } // end getBitmap
Пример #3
0
 public Bitmap getBitmapCut(String path, int w, int h, boolean isUpload, String extensions) {
   String filename = FileUtil.convertUrlToFileName(path);
   Bitmap result = memoryCache.getBitmapFromCache(filename);
   if (result == null && fileCache != null) {
     result = fileCache.getImageFile(path, w, h, isUpload, extensions);
     if (result != null) {
       memoryCache.addBitmapToCache(filename, result);
     }
   }
   return result;
 }
Пример #4
0
 public void setCacheDir(String cacheDir) {
   if (cacheDir != null && cacheDir.length() > 0 && fileCache == null) {
     fileCache = new ImageFileCache();
     fileCache.setCacheDir(cacheDir);
     try {
       File dirFile = new File(cacheDir);
       if (!dirFile.exists()) dirFile.mkdirs();
     } catch (Exception ex) {
     }
   }
 }
Пример #5
0
 public Bitmap getBitmap(String url) {
   String filename = FileUtil.convertUrlToFileName(url);
   boolean isDownload = true;
   if (url.startsWith("http") || url.toLowerCase().startsWith("http")) {
     url = filename;
   } else {
     isDownload = false;
   }
   Bitmap result = memoryCache.getBitmapFromCache(filename);
   if (result == null && fileCache != null) {
     result = fileCache.getImage(url, isDownload);
     if (result != null) {
       memoryCache.addBitmapToCache(filename, result);
     }
   }
   return result;
 }
Пример #6
0
 public void save(Bitmap img, String path, String extensions) {
   fileCache.saveBitmap(img, path, extensions);
 }
Пример #7
0
 public String getCacheUploadPath(String filename) {
   if (fileCache == null) {
     return null;
   }
   return fileCache.getCacheUploadPath(filename);
 }
Пример #8
0
 public void deleteAllImages() {
   imageFileCache.deleteAll();
 }
Пример #9
0
 /** delete the image files from sd */
 public void deleteImagesOfSd() {
   imageFileCache.deleteAll();
 }