示例#1
0
 private WorldRegion init(String regionId, OsmandRegions osmandRegions) {
   this.regionId = regionId;
   String downloadName = osmandRegions.getDownloadName(regionId);
   if (downloadName != null) {
     downloadsIdPrefix = downloadName.toLowerCase() + ".";
   } else {
     this.downloadsIdPrefix = regionId.toLowerCase() + ".";
   }
   this.name = osmandRegions.getLocaleNameByFullName(regionId);
   if (this.name == null) {
     this.name = capitalize(regionId.replace('_', ' '));
   }
   return this;
 }
  public static String getFileName(Context ctx, OsmandRegions regions, String fileName) {
    String basename = getBasename(fileName);
    if (basename.endsWith(WIKI_NAME)) { // wiki files
      return getWikiName(ctx, basename);
    } else if (fileName.endsWith("tts")) { // tts files
      return getVoiceName(ctx, fileName);
    } else if (fileName.startsWith(HILL_SHADE)) {
      return getHillShadeName(ctx, regions, basename);
    } else if (fileName.length() == 2) { // voice recorded files
      try {
        Field f = R.string.class.getField("lang_" + fileName);
        if (f != null) {
          Integer in = (Integer) f.get(null);
          return ctx.getString(in);
        }
      } catch (Exception e) {
        System.err.println(e.getMessage());
      }
    }

    // if nothing else
    String lc = basename.toLowerCase();
    String std = getStandardMapName(ctx, lc);
    if (std != null) {
      return std;
    }

    if (regions != null) {
      return regions.getLocaleName(basename);
    }

    return null;
  }
示例#3
0
  public void loadWorldRegions(OsmandApplication app) {
    OsmandRegions osmandRegions = app.getRegions();

    Map<String, String> loadedItems = osmandRegions.getFullNamesToLowercaseCopy();
    if (loadedItems.size() == 0) {
      return;
    }

    HashMap<String, WorldRegion> regionsLookupTable = new HashMap<>(loadedItems.size());

    // Create main regions
    Resources res = app.getResources();

    WorldRegion africaRegion =
        createRegionAs(
            AFRICA_REGION_ID,
            loadedItems,
            osmandRegions,
            res.getString(R.string.index_name_africa));
    addSubregion(africaRegion);
    regionsLookupTable.put(africaRegion.regionId, africaRegion);

    WorldRegion asiaRegion =
        createRegionAs(
            ASIA_REGION_ID, loadedItems, osmandRegions, res.getString(R.string.index_name_asia));
    addSubregion(asiaRegion);
    regionsLookupTable.put(asiaRegion.regionId, asiaRegion);

    WorldRegion australiaAndOceaniaRegion =
        createRegionAs(
            AUSTRALIA_AND_OCEANIA_REGION_ID,
            loadedItems,
            osmandRegions,
            res.getString(R.string.index_name_oceania));
    addSubregion(australiaAndOceaniaRegion);
    regionsLookupTable.put(australiaAndOceaniaRegion.regionId, australiaAndOceaniaRegion);

    WorldRegion centralAmericaRegion =
        createRegionAs(
            CENTRAL_AMERICA_REGION_ID,
            loadedItems,
            osmandRegions,
            res.getString(R.string.index_name_central_america));
    addSubregion(centralAmericaRegion);
    regionsLookupTable.put(centralAmericaRegion.regionId, centralAmericaRegion);

    WorldRegion europeRegion =
        createRegionAs(
            EUROPE_REGION_ID,
            loadedItems,
            osmandRegions,
            res.getString(R.string.index_name_europe));
    addSubregion(europeRegion);
    regionsLookupTable.put(europeRegion.regionId, europeRegion);

    WorldRegion northAmericaRegion =
        createRegionAs(
            NORTH_AMERICA_REGION_ID,
            loadedItems,
            osmandRegions,
            res.getString(R.string.index_name_north_america));
    addSubregion(northAmericaRegion);
    regionsLookupTable.put(northAmericaRegion.regionId, northAmericaRegion);

    WorldRegion russiaRegion =
        createRegionAs(
            RUSSIA_REGION_ID,
            loadedItems,
            osmandRegions,
            res.getString(R.string.index_name_russia));
    addSubregion(russiaRegion);
    regionsLookupTable.put(russiaRegion.regionId, russiaRegion);

    WorldRegion southAmericaRegion =
        createRegionAs(
            SOUTH_AMERICA_REGION_ID,
            loadedItems,
            osmandRegions,
            res.getString(R.string.index_name_south_america));
    addSubregion(southAmericaRegion);
    regionsLookupTable.put(southAmericaRegion.regionId, southAmericaRegion);

    // Process remaining regions
    for (; ; ) {
      int processedRegions = 0;

      Iterator<Entry<String, String>> iterator = loadedItems.entrySet().iterator();
      while (iterator.hasNext()) {
        String regionId = iterator.next().getKey();
        String parentRegionId = osmandRegions.getParentFullName(regionId);
        if (parentRegionId == null) {
          continue;
        }

        // Try to find parent of this region
        WorldRegion parentRegion = regionsLookupTable.get(parentRegionId);
        if (parentRegion == null) {
          continue;
        }

        WorldRegion newRegion = new WorldRegion().init(regionId, osmandRegions);
        parentRegion.addSubregion(newRegion);
        regionsLookupTable.put(newRegion.regionId, newRegion);

        // Remove
        processedRegions++;
        iterator.remove();
      }

      // If all remaining are orphans, that's all
      if (processedRegions == 0) break;
    }

    LOG.warn("Found orphaned regions: " + loadedItems.size());
    for (String regionId : loadedItems.keySet()) {
      LOG.warn("FullName = " + regionId + " parent=" + osmandRegions.getParentFullName(regionId));
    }
  }
 public static String getHillShadeName(Context ctx, OsmandRegions regions, String basename) {
   String hillsh = ctx.getString(R.string.download_hillshade_item) + " ";
   String locName = regions.getLocaleName(basename.trim());
   return hillsh + locName;
 }