Exemplo n.º 1
0
  public static String getImageSavePath(CachedImageKey key) {
    String filePath = null;
    if (key == null || StringUtil.isEmpty(key.getImageUrl())) {
      return null;
    }

    filePath =
        File.separator + IMAGE_FOLDER[key.getCacheType()] + File.separator + key.getCachedName();
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
      filePath = ImageCache.filePath + filePath;
    } else {
      filePath = ImageCache.secondaryFilePath + filePath;
    }
    return filePath;
  }
Exemplo n.º 2
0
  @Override
  public void put(CachedImageKey key, CachedImage value) {
    if (value == null || key == null || StringUtil.isEmpty(key.getImageUrl())) {
      return;
    }

    Bitmap bitmap = value.getWrap();
    if (bitmap != null && !value.isLocalCached()) {
      write(key, value);
      value.setLocalCached(true);
    }

    memoryCache.put(key, value);
    if (memoryCache.size() > 50) {
      reclaim(ReclaimLevel.LIGHT);
    }
  }
Exemplo n.º 3
0
  public static String getRealPath(CachedImageKey key) {
    String filePath = null;
    if (key == null || StringUtil.isEmpty(key.getImageUrl())) {
      return filePath;
    }

    filePath =
        File.separator + IMAGE_FOLDER[key.getCacheType()] + File.separator + key.getCachedName();
    File file = new File(ImageCache.filePath + filePath);
    if (file.exists() && file.isFile()) {
      return file.getPath();
    }

    file = new File(ImageCache.secondaryFilePath + filePath);
    if (file.exists() && file.isFile()) {
      return file.getPath();
    }

    return null;
  }
Exemplo n.º 4
0
  // 把数组写入文件
  public static void write(CachedImageKey key, byte[] imgBytes) {
    if (key == null
        || StringUtil.isEmpty(key.getImageUrl())
        || imgBytes == null
        || imgBytes.length == 0) {
      return;
    }

    String fileName =
        File.separator + IMAGE_FOLDER[key.getCacheType()] + File.separator + key.getCachedName();
    File file = new File(filePath + fileName);
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
      file = new File(secondaryFilePath + fileName);
    }
    if (file.exists()) {
      return;
    }

    FileOutputStream fos = null;
    try {
      file.createNewFile();
      fos = new FileOutputStream(file);

      fos.write(imgBytes);

      fos.flush();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (fos != null) {
        try {
          fos.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }