Ejemplo n.º 1
0
 public HttpConfig() {
   if (mCache == null) {
     File folder = FileUtils.getSaveFolder(CACHEPATH);
     mCache = new DiskCache(folder, DISK_CACHE_SIZE);
   }
   mNetwork = new Network(httpStackFactory());
   mDelivery = new DeliveryExecutor(new Handler(Looper.getMainLooper()));
   mController = new DownloadTaskQueue(HttpConfig.MAX_DOWNLOAD_TASK_SIZE);
 }
  /** 计算缓存的大小 */
  private void caculateCacheSize() {
    long fileSize = 0;
    String cacheSize = "0KB";
    File filesDir = getActivity().getFilesDir();
    File cacheDir = getActivity().getCacheDir();

    fileSize += FileUtil.getDirSize(filesDir);
    fileSize += FileUtil.getDirSize(cacheDir);
    // 2.2版本才有将应用缓存转移到sd卡的功能
    if (AppContext.isMethodsCompat(android.os.Build.VERSION_CODES.FROYO)) {
      File externalCacheDir = MethodsCompat.getExternalCacheDir(getActivity());
      fileSize += FileUtil.getDirSize(externalCacheDir);
      fileSize +=
          FileUtil.getDirSize(
              new File(
                  org.kymjs.kjframe.utils.FileUtils.getSDCardPath()
                      + File.separator
                      + HttpConfig.CACHEPATH));
    }
    if (fileSize > 0) cacheSize = FileUtil.formatFileSize(fileSize);
    mTvCacheSize.setText(cacheSize);
  }