Пример #1
0
  /// On low memory method ///
  public void onLowMemory() {
    log.info("On low memory : cleaning tiles - size = " + cacheOfImages.size()); // $NON-NLS-1$
    clearTiles();
    for (RegionAddressRepository r : addressMap.values()) {
      r.clearCache();
    }
    renderer.clearCache();

    System.gc();
  }
Пример #2
0
  protected Bitmap getRequestedImageTile(TileLoadDownloadRequest req) {
    if (req.tileId == null || req.dirWithTiles == null) {
      return null;
    }
    Bitmap cacheBmp = cacheOfImages.get(req.tileId);
    if (cacheBmp != null) {
      return cacheBmp;
    }
    if (cacheOfImages.size() > maxImgCacheSize) {
      clearTiles();
    }
    if (req.dirWithTiles.canRead()
        && !asyncLoadingThread.isFileCurrentlyDownloaded(req.fileToSave)
        && !asyncLoadingThread.isFilePendingToDownload(req.fileToSave)) {
      long time = System.currentTimeMillis();
      if (log.isDebugEnabled()) {
        log.debug(
            "Start loaded file : "
                + req.tileId
                + " "
                + Thread.currentThread().getName()); // $NON-NLS-1$ //$NON-NLS-2$
      }
      Bitmap bmp = null;
      if (req.tileSource instanceof SQLiteTileSource) {
        try {
          long[] tm = new long[1];
          bmp = ((SQLiteTileSource) req.tileSource).getImage(req.xTile, req.yTile, req.zoom, tm);
          if (tm[0] != 0) {
            int ts = req.tileSource.getExpirationTimeMillis();
            if (ts != -1 && req.url != null && time - tm[0] > ts) {
              asyncLoadingThread.requestToDownload(req);
            }
          }
        } catch (OutOfMemoryError e) {
          log.error("Out of memory error", e); // $NON-NLS-1$
          clearTiles();
        }
      } else {
        File en = new File(req.dirWithTiles, req.tileId);
        if (en.exists()) {
          try {
            bmp = BitmapFactory.decodeFile(en.getAbsolutePath());
            int ts = req.tileSource.getExpirationTimeMillis();
            if (ts != -1 && req.url != null && time - en.lastModified() > ts) {
              asyncLoadingThread.requestToDownload(req);
            }
          } catch (OutOfMemoryError e) {
            log.error("Out of memory error", e); // $NON-NLS-1$
            clearTiles();
          }
        }
      }

      if (bmp != null) {
        cacheOfImages.put(req.tileId, bmp);
        if (log.isDebugEnabled()) {
          log.debug(
              "Loaded file : "
                  + req.tileId
                  + " "
                  + -(time - System.currentTimeMillis())
                  + " ms "
                  + cacheOfImages.size()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }
      }

      if (cacheOfImages.get(req.tileId) == null && req.url != null) {
        asyncLoadingThread.requestToDownload(req);
      }
    }
    return cacheOfImages.get(req.tileId);
  }