Exemplo n.º 1
0
 static WaypointType convertWaypointSym2Type(final String sym) {
   if ("parking area".equalsIgnoreCase(sym)) {
     return WaypointType.PARKING;
   }
   if ("stages of a multicache".equalsIgnoreCase(sym)) {
     return WaypointType.STAGE;
   }
   if ("question to answer".equalsIgnoreCase(sym)) {
     return WaypointType.PUZZLE;
   }
   if ("trailhead".equalsIgnoreCase(sym)) {
     return WaypointType.TRAILHEAD;
   }
   if ("final location".equalsIgnoreCase(sym)) {
     return WaypointType.FINAL;
   }
   // this is not fully correct, but lets also look for localized waypoint types
   for (WaypointType waypointType : WaypointType.ALL_TYPES_EXCEPT_OWN_AND_ORIGINAL) {
     final String localized = waypointType.getL10n();
     if (StringUtils.isNotEmpty(localized)) {
       if (localized.equalsIgnoreCase(sym)) {
         return waypointType;
       }
     }
   }
   return WaypointType.WAYPOINT;
 }
Exemplo n.º 2
0
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.editwaypoint_activity);

    if (StringUtils.isBlank(geocode) && waypointId <= 0) {
      showToast(res.getString(R.string.err_waypoint_cache_unknown));

      finish();
      return;
    }

    if (waypointId <= 0) {
      setTitle(res.getString(R.string.waypoint_add_title));
    } else {
      setTitle(res.getString(R.string.waypoint_edit_title));
    }

    buttonLat.setOnClickListener(new CoordDialogListener());
    buttonLon.setOnClickListener(new CoordDialogListener());

    addWaypoint.setOnClickListener(new SaveWaypointListener());

    final List<String> wayPointNames = new ArrayList<>();
    for (final WaypointType wpt : WaypointType.ALL_TYPES_EXCEPT_OWN_AND_ORIGINAL) {
      wayPointNames.add(wpt.getL10n());
    }
    final ArrayAdapter<String> adapter =
        new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, wayPointNames);
    waypointName.setAdapter(adapter);

    if (savedInstanceState != null) {
      initViews = false;
    }

    if (geocode != null) {
      cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
      setCoordsModificationVisibility(ConnectorFactory.getConnector(geocode), cache);
    }
    if (waypointId > 0) { // existing waypoint
      waitDialog = ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true);
      waitDialog.setCancelable(true);

      (new LoadWaypointThread()).start();

    } else { // new waypoint
      initializeWaypointTypeSelector();
    }

    initializeDistanceUnitSelector();

    disableSuggestions(distanceView);
  }
Exemplo n.º 3
0
 /**
  * Suffix the waypoint type with a running number to get a default name.
  *
  * @param type type to create a new default name for
  * @return
  */
 private String getDefaultWaypointName(final WaypointType type) {
   final ArrayList<String> wpNames = new ArrayList<>();
   for (final Waypoint waypoint : cache.getWaypoints()) {
     wpNames.add(waypoint.getName());
   }
   // try final and trailhead without index
   if (type == WaypointType.FINAL || type == WaypointType.TRAILHEAD) {
     if (!wpNames.contains(type.getL10n())) {
       return type.getL10n();
     }
   }
   // for other types add an index by default, which is highest found index + 1
   int max = 0;
   for (int i = 0; i < 30; i++) {
     if (wpNames.contains(type.getL10n() + " " + i)) {
       max = i;
     }
   }
   return type.getL10n() + " " + (max + 1);
 }