예제 #1
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((base == null) ? 0 : base.hashCode());
   result = prime * result + ((name == null) ? 0 : name.hashCode());
   return result;
 }
예제 #2
0
 public void updateDescription(LocalIndexInfo info) {
   File f = new File(info.getPathToData());
   if (info.getType() == LocalIndexType.MAP_DATA) {
     Map<String, String> ifns = app.getResourceManager().getIndexFileNames();
     if (ifns.containsKey(info.getFileName())) {
       try {
         Date dt = app.getResourceManager().getDateFormat().parse(ifns.get(info.getFileName()));
         info.setDescription(getInstalledDate(dt.getTime(), null));
       } catch (ParseException e) {
         e.printStackTrace();
       }
     } else {
       info.setDescription(getInstalledDate(f));
     }
   } else if (info.getType() == LocalIndexType.TILES_DATA) {
     ITileSource template;
     if (f.isDirectory() && TileSourceManager.isTileSourceMetaInfoExist(f)) {
       template = TileSourceManager.createTileSourceTemplate(new File(info.getPathToData()));
     } else if (f.isFile() && f.getName().endsWith(SQLiteTileSource.EXT)) {
       template = new SQLiteTileSource(app, f, TileSourceManager.getKnownSourceTemplates());
     } else {
       return;
     }
     String descr = "";
     descr += app.getString(R.string.local_index_tile_data_name, template.getName());
     if (template.getExpirationTimeMinutes() >= 0) {
       descr +=
           "\n"
               + app.getString(
                   R.string.local_index_tile_data_expire, template.getExpirationTimeMinutes());
     }
     info.setDescription(descr);
   } else if (info.getType() == LocalIndexType.SRTM_DATA) {
     info.setDescription(app.getString(R.string.download_srtm_maps));
   } else if (info.getType() == LocalIndexType.WIKI_DATA) {
     info.setDescription(getInstalledDate(f));
   } else if (info.getType() == LocalIndexType.TTS_VOICE_DATA) {
     info.setDescription(getInstalledDate(f));
   } else if (info.getType() == LocalIndexType.DEACTIVATED) {
     info.setDescription(getInstalledDate(f));
   } else if (info.getType() == LocalIndexType.VOICE_DATA) {
     info.setDescription(getInstalledDate(f));
   }
 }
예제 #3
0
  protected synchronized Bitmap getTileImageForMap(
      String tileId,
      ITileSource map,
      int x,
      int y,
      int zoom,
      boolean loadFromInternetIfNeeded,
      boolean sync,
      boolean loadFromFs,
      boolean deleteBefore) {
    if (tileId == null) {
      tileId = calculateTileId(map, x, y, zoom);
      if (tileId == null) {
        return null;
      }
    }

    if (deleteBefore) {
      cacheOfImages.remove(tileId);
      if (map instanceof SQLiteTileSource) {
        ((SQLiteTileSource) map).deleteImage(x, y, zoom);
      } else {
        File f = new File(dirWithTiles, tileId);
        if (f.exists()) {
          f.delete();
        }
      }
      imagesOnFS.put(tileId, null);
    }

    if (loadFromFs && cacheOfImages.get(tileId) == null && map != null) {
      boolean locked = map instanceof SQLiteTileSource && ((SQLiteTileSource) map).isLocked();
      if (!loadFromInternetIfNeeded && !locked && !tileExistOnFileSystem(tileId, map, x, y, zoom)) {
        return null;
      }
      String url = loadFromInternetIfNeeded ? map.getUrlToLoad(x, y, zoom) : null;
      File toSave = null;
      if (url != null) {
        if (map instanceof SQLiteTileSource) {
          toSave =
              new File(
                  dirWithTiles, calculateTileId(((SQLiteTileSource) map).getBase(), x, y, zoom));
        } else {
          toSave = new File(dirWithTiles, tileId);
        }
      }
      TileLoadDownloadRequest req =
          new TileLoadDownloadRequest(dirWithTiles, url, toSave, tileId, map, x, y, zoom);
      if (sync) {
        return getRequestedImageTile(req);
      } else {
        asyncLoadingThread.requestToLoadImage(req);
      }
    }
    return cacheOfImages.get(tileId);
  }
예제 #4
0
  public synchronized String calculateTileId(ITileSource map, int x, int y, int zoom) {
    builder.setLength(0);
    if (map == null) {
      builder.append(IndexConstants.TEMP_SOURCE_TO_LOAD);
    } else {
      builder.append(map.getName());
    }

    if (map instanceof SQLiteTileSource) {
      builder.append('@');
    } else {
      builder.append('/');
    }
    builder
        .append(zoom)
        .append('/')
        .append(x)
        .append('/')
        .append(y)
        .append(map == null ? ".jpg" : map.getTileFormat())
        .append(".tile"); // $NON-NLS-1$ //$NON-NLS-2$
    return builder.toString();
  }
예제 #5
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   SQLiteTileSource other = (SQLiteTileSource) obj;
   if (base == null) {
     if (other.base != null) return false;
   } else if (!base.equals(other.base)) return false;
   if (name == null) {
     if (other.name != null) return false;
   } else if (!name.equals(other.name)) return false;
   return true;
 }
예제 #6
0
  public void openDialog() {
    BaseMapLayer mainLayer = mapView.getMainLayer();
    if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
      AccessibleToast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT)
          .show();
    }
    final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
    if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
      AccessibleToast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT)
          .show();
      return;
    }
    final RotatedTileBox rb = mapView.getCurrentRotatedTileBox();
    final int max = mapSource.getMaximumZoomSupported();
    // get narrow zoom
    final int zoom = rb.getZoom();

    // calculate pixel rectangle
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    LayoutInflater inflater =
        (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.download_tiles, null);

    ((TextView) view.findViewById(R.id.MinZoom)).setText(zoom + ""); // $NON-NLS-1$
    ((TextView) view.findViewById(R.id.MaxZoom)).setText(max + ""); // $NON-NLS-1$
    final SeekBar seekBar = (SeekBar) view.findViewById(R.id.ZoomToDownload);
    seekBar.setMax(max - zoom);
    seekBar.setProgress((max - zoom) / 2);

    final TextView downloadText = ((TextView) view.findViewById(R.id.DownloadDescription));
    final String template = ctx.getString(R.string.tiles_to_download_estimated_size);

    updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, seekBar.getProgress());
    seekBar.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {

          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, progress);
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {}

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {}
        });

    builder.setPositiveButton(
        R.string.shared_string_download,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            run(zoom, seekBar.getProgress(), rb.getLatLonBounds(), mapSource);
          }
        });
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    builder.setView(view);
    builder.show();
  }
예제 #7
0
 @Override
 public int getTileSize() {
   return base != null ? base.getTileSize() : tileSize;
 }
예제 #8
0
 @Override
 public String getTileFormat() {
   return base != null ? base.getTileFormat() : ".png"; // $NON-NLS-1$
 }
예제 #9
0
 @Override
 public int getMinimumZoomSupported() {
   getDatabase();
   return base != null ? base.getMinimumZoomSupported() : minZoom;
 }
예제 #10
0
 @Override
 public int getBitDensity() {
   return base != null ? base.getBitDensity() : 16;
 }