Exemplo n.º 1
0
 public synchronized void close() {
   imagesOnFS.clear();
   indexFileNames.clear();
   basemapFileNames.clear();
   renderer.clearAllResources();
   closeAmenities();
   closeRouteFiles();
   closeAddresses();
   closeTransport();
 }
Exemplo n.º 2
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();
  }
Exemplo n.º 3
0
  protected void checkVectorIndexesDownloaded() {
    MapRenderRepositories maps = getMyApplication().getResourceManager().getRenderer();
    SharedPreferences pref = getPreferences(MODE_WORLD_WRITEABLE);
    boolean check = pref.getBoolean(VECTOR_INDEXES_CHECK, true);
    // do not show each time
    if (check && new Random().nextInt() % 5 == 1) {
      Builder builder = new AccessibleAlertBuilder(this);
      if (maps.isEmpty()) {
        builder.setMessage(R.string.vector_data_missing);
      } else if (!maps.basemapExists()) {
        builder.setMessage(R.string.basemap_missing);
      } else {
        return;
      }
      builder.setPositiveButton(
          R.string.download_files,
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              startActivity(new Intent(MainMenuActivity.this, DownloadIndexActivity.class));
            }
          });
      builder.setNeutralButton(
          R.string.vector_map_not_needed,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              getPreferences(MODE_WORLD_WRITEABLE)
                  .edit()
                  .putBoolean(VECTOR_INDEXES_CHECK, false)
                  .commit();
            }
          });
      builder.setNegativeButton(R.string.first_time_continue, null);
      builder.show();
    }
  }
Exemplo n.º 4
0
 public void closeFile(String fileName) {
   AmenityIndexRepository rep = amenityRepositories.remove(fileName);
   if (rep != null) {
     rep.close();
   }
   RegionAddressRepository rar = addressMap.remove(fileName);
   if (rar != null) {
     rar.close();
   }
   TransportIndexRepository tir = transportRepositories.remove(fileName);
   if (tir != null) {
     tir.close();
   }
   BinaryMapIndexReader rmp = routingMapFiles.remove(fileName);
   if (rmp != null) {
     try {
       rmp.close();
     } catch (IOException e) {
       log.error(e, e);
     }
   }
   renderer.closeConnection(fileName);
 }
Exemplo n.º 5
0
  public List<String> indexingMaps(final IProgress progress) {
    long val = System.currentTimeMillis();
    ArrayList<File> files = new ArrayList<File>();
    File appPath = context.getAppPath(null);
    File roadsPath = context.getAppPath(IndexConstants.ROADS_INDEX_DIR);
    roadsPath.mkdirs();

    collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
    renameRoadsFiles(files, roadsPath);
    collectFiles(roadsPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
    if (!Version.isFreeVersion(context)) {
      collectFiles(
          context.getAppPath(IndexConstants.WIKI_INDEX_DIR),
          IndexConstants.BINARY_MAP_INDEX_EXT,
          files);
    }
    if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
      collectFiles(
          context.getAppPath(IndexConstants.SRTM_INDEX_DIR),
          IndexConstants.BINARY_MAP_INDEX_EXT,
          files);
    }

    if (context.getSettings().BETA_TESTING_LIVE_UPDATES.get()) {
      changesManager.collectChangesFiles(
          context.getAppPath(IndexConstants.LIVE_INDEX_DIR),
          IndexConstants.BINARY_MAP_INDEX_EXT,
          files);
    }

    Collections.sort(files, Algorithms.getFileVersionComparator());
    List<String> warnings = new ArrayList<String>();
    renderer.clearAllResources();
    CachedOsmandIndexes cachedOsmandIndexes = new CachedOsmandIndexes();
    File indCache = context.getAppPath(INDEXES_CACHE);
    if (indCache.exists()) {
      try {
        cachedOsmandIndexes.readFromFile(indCache, CachedOsmandIndexes.VERSION);
      } catch (Exception e) {
        log.error(e.getMessage(), e);
      }
    }
    File liveDir = context.getAppPath(IndexConstants.LIVE_INDEX_DIR);
    for (File f : files) {
      progress.startTask(
          context.getString(R.string.indexing_map) + " " + f.getName(), -1); // $NON-NLS-1$
      try {
        BinaryMapIndexReader mapReader = null;
        try {
          mapReader = cachedOsmandIndexes.getReader(f);
          if (mapReader.getVersion() != IndexConstants.BINARY_MAP_VERSION) {
            mapReader = null;
          }
          if (mapReader != null) {
            renderer.initializeNewResource(progress, f, mapReader);
          }
        } catch (IOException e) {
          log.error(String.format("File %s could not be read", f.getName()), e);
        }
        if (mapReader == null
            || (Version.isFreeVersion(context)
                && (f.getName().contains("_wiki") || f.getName().contains(".wiki")))) {
          warnings.add(
              MessageFormat.format(
                  context.getString(R.string.version_index_is_not_supported),
                  f.getName())); // $NON-NLS-1$
        } else {
          if (mapReader.isBasemap()) {
            basemapFileNames.put(f.getName(), f.getName());
          }
          long dateCreated = mapReader.getDateCreated();
          if (dateCreated == 0) {
            dateCreated = f.lastModified();
          }
          if (f.getParentFile().getName().equals(liveDir.getName())) {
            boolean toUse = changesManager.index(f, dateCreated, mapReader);
            if (!toUse) {
              try {
                mapReader.close();
              } catch (IOException e) {
                log.error(e.getMessage(), e);
              }
              continue;
            }
          } else {
            changesManager.indexMainMap(f, dateCreated);
            indexFileNames.put(f.getName(), dateFormat.format(dateCreated)); // $NON-NLS-1$
          }
          if (!mapReader.getRegionNames().isEmpty()) {
            try {
              RandomAccessFile raf = new RandomAccessFile(f, "r"); // $NON-NLS-1$
              RegionAddressRepositoryBinary rarb =
                  new RegionAddressRepositoryBinary(
                      this, new BinaryMapIndexReader(raf, mapReader), f.getName());
              addressMap.put(f.getName(), rarb);
            } catch (IOException e) {
              log.error("Exception reading " + f.getAbsolutePath(), e); // $NON-NLS-1$
              warnings.add(
                  MessageFormat.format(
                      context.getString(R.string.version_index_is_not_supported),
                      f.getName())); // $NON-NLS-1$
            }
          }
          if (mapReader.hasTransportData()) {
            try {
              RandomAccessFile raf = new RandomAccessFile(f, "r"); // $NON-NLS-1$
              transportRepositories.put(
                  f.getName(),
                  new TransportIndexRepositoryBinary(new BinaryMapIndexReader(raf, mapReader)));
            } catch (IOException e) {
              log.error("Exception reading " + f.getAbsolutePath(), e); // $NON-NLS-1$
              warnings.add(
                  MessageFormat.format(
                      context.getString(R.string.version_index_is_not_supported),
                      f.getName())); // $NON-NLS-1$
            }
          }
          if (mapReader.containsRouteData()) {
            try {
              RandomAccessFile raf = new RandomAccessFile(f, "r"); // $NON-NLS-1$
              routingMapFiles.put(f.getName(), new BinaryMapIndexReader(raf, mapReader));
            } catch (IOException e) {
              log.error("Exception reading " + f.getAbsolutePath(), e); // $NON-NLS-1$
              warnings.add(
                  MessageFormat.format(
                      context.getString(R.string.version_index_is_not_supported),
                      f.getName())); // $NON-NLS-1$
            }
          }
          if (mapReader.containsPoiData()) {
            try {
              RandomAccessFile raf = new RandomAccessFile(f, "r"); // $NON-NLS-1$
              amenityRepositories.put(
                  f.getName(),
                  new AmenityIndexRepositoryBinary(new BinaryMapIndexReader(raf, mapReader)));
            } catch (IOException e) {
              log.error("Exception reading " + f.getAbsolutePath(), e); // $NON-NLS-1$
              warnings.add(
                  MessageFormat.format(
                      context.getString(R.string.version_index_is_not_supported),
                      f.getName())); // $NON-NLS-1$
            }
          }
        }
      } catch (SQLiteException e) {
        log.error("Exception reading " + f.getAbsolutePath(), e); // $NON-NLS-1$
        warnings.add(
            MessageFormat.format(
                context.getString(R.string.version_index_is_not_supported),
                f.getName())); // $NON-NLS-1$
      } catch (OutOfMemoryError oome) {
        log.error("Exception reading " + f.getAbsolutePath(), oome); // $NON-NLS-1$
        warnings.add(
            MessageFormat.format(
                context.getString(R.string.version_index_is_big_for_memory), f.getName()));
      }
    }
    log.debug("All map files initialized " + (System.currentTimeMillis() - val) + " ms");
    if (files.size() > 0 && (!indCache.exists() || indCache.canWrite())) {
      try {
        cachedOsmandIndexes.writeToFile(indCache);
      } catch (Exception e) {
        log.error("Index file could not be written", e);
      }
    }
    return warnings;
  }
Exemplo n.º 6
0
 public void interruptRendering() {
   renderer.interruptLoadingMap();
 }
Exemplo n.º 7
0
 public void updateRendererMap(RotatedTileBox rotatedTileBox) {
   renderer.interruptLoadingMap();
   asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox));
 }
Exemplo n.º 8
0
 ////////////////////////////////////////////// Working with map
 // ////////////////////////////////////////////////
 public boolean updateRenderedMapNeeded(RotatedTileBox rotatedTileBox, DrawSettings drawSettings) {
   return renderer.updateMapIsNeeded(rotatedTileBox, drawSettings);
 }
Exemplo n.º 9
0
  @SuppressWarnings("unchecked")
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    // handle boolean prefences
    OsmandPreference<Boolean> boolPref = booleanPreferences.get(preference.getKey());
    OsmandPreference<Integer> seekPref = seekBarPreferences.get(preference.getKey());
    OsmandPreference<Object> listPref =
        (OsmandPreference<Object>) listPreferences.get(preference.getKey());
    OsmandPreference<String> editPref = editTextPreferences.get(preference.getKey());
    if (boolPref != null) {
      boolPref.set((Boolean) newValue);
      if (boolPref.getId().equals(osmandSettings.MAP_VECTOR_DATA.getId())) {
        MapRenderRepositories r =
            ((OsmandApplication) getApplication()).getResourceManager().getRenderer();
        if (r.isEmpty()) {
          Toast.makeText(this, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show();
          return false;
        }
      }
    } else if (seekPref != null) {
      seekPref.set((Integer) newValue);
    } else if (editPref != null) {
      editPref.set((String) newValue);
    } else if (listPref != null) {
      int ind = ((ListPreference) preference).findIndexOfValue((String) newValue);
      CharSequence entry = ((ListPreference) preference).getEntries()[ind];
      Map<String, ?> map = listPrefValues.get(preference.getKey());
      Object obj = map.get(entry);
      final Object oldValue = listPref.get();
      boolean changed = listPref.set(obj);

      // Specific actions after list preference changed
      if (changed) {
        if (listPref.getId().equals(osmandSettings.VOICE_PROVIDER.getId())) {
          if (MORE_VALUE.equals(newValue)) {
            listPref.set(oldValue); // revert the change..
            final Intent intent = new Intent(this, DownloadIndexActivity.class);
            intent.putExtra(DownloadIndexActivity.FILTER_KEY, "voice");
            startActivity(intent);
          } else {
            getMyApplication().showDialogInitializingCommandPlayer(this, false);
          }
        } else if (listPref.getId().equals(osmandSettings.APPLICATION_MODE.getId())) {
          updateAllSettings();
        } else if (listPref.getId().equals(osmandSettings.PREFERRED_LOCALE.getId())) {
          // restart application to update locale
          getMyApplication().checkPrefferedLocale();
          Intent intent = getIntent();
          finish();
          startActivity(intent);
        }
      }
      if (listPref.getId().equals(osmandSettings.RENDERER.getId())) {
        if (changed) {
          Toast.makeText(this, R.string.renderer_load_sucess, Toast.LENGTH_SHORT).show();
        } else {
          Toast.makeText(this, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
        }
      }
    } else if (preference == applicationDir) {
      warnAboutChangingStorage((String) newValue);
      return false;
    } else if (preference == routeServiceEnabled) {
      Intent serviceIntent = new Intent(this, NavigationService.class);
      if ((Boolean) newValue) {
        ComponentName name = startService(serviceIntent);
        if (name == null) {
          routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null);
        }
      } else {
        if (!stopService(serviceIntent)) {
          routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null);
        }
      }
    } else if (preference == tileSourcePreference
        || preference == overlayPreference
        || preference == underlayPreference) {
      if (MORE_VALUE.equals(newValue)) {
        SettingsActivity.installMapLayers(
            this,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                updateTileSourceSummary();
              }
            });
      } else if (preference == tileSourcePreference) {
        osmandSettings.MAP_TILE_SOURCES.set((String) newValue);
        updateTileSourceSummary();
      } else {
        if (((String) newValue).length() == 0) {
          newValue = null;
        }
        if (preference == underlayPreference) {
          osmandSettings.MAP_UNDERLAY.set(((String) newValue));
        } else if (preference == overlayPreference) {
          osmandSettings.MAP_OVERLAY.set(((String) newValue));
        }
      }
    }
    return true;
  }