Ejemplo n.º 1
0
  public static void loadTile(TileProvider provider, Tile t) {
    BaseApplication application = BaseApplication.getApplication();
    if (application == null) return;

    File cache = application.getCacheDir();
    if (cache == null) // cache is not available now
    return;

    File file = getTileFile(cache, provider.code, t.x, t.y, t.zoomLevel);
    if (!file.exists()) return;
    try {
      FileInputStream fileInputStream;
      fileInputStream = new FileInputStream(file);
      byte[] data = new byte[(int) file.length()];
      int count = fileInputStream.read(data);
      fileInputStream.close();
      if (count != data.length) return;
      t.bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
      t.expired =
          provider.tileExpiration > 0
              && file.lastModified() + provider.tileExpiration < System.currentTimeMillis();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
  public static void saveTile(TileProvider provider, byte[] dat, int tx, int ty, byte z) {
    BaseApplication application = BaseApplication.getApplication();
    if (application == null) return;

    File cache = application.getCacheDir();
    if (cache == null) // cache is not available now
    return;

    File file = getTileFile(cache, provider.code, tx, ty, z);
    //noinspection ResultOfMethodCallIgnored
    file.getParentFile().mkdirs();
    FileOutputStream fileOutputStream;
    try {
      fileOutputStream = new FileOutputStream(file);
      fileOutputStream.write(dat);
      fileOutputStream.flush();
      fileOutputStream.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }