Esempio n. 1
0
  public void test() {
    Log.i("ROUTE-TEST", "Duration: " + this.duration);
    Log.i("ROUTE-TEST", "Length: " + this.length);
    Log.i("ROUTE-TEST", "Steps: " + this.steps.size());
    for (int i = 0; i < this.steps.size(); i++) {
      RouteStep s = this.steps.get(i);
      Log.i("ROUTE-TEST", "\tDuration:" + s.duration);
      Log.i("ROUTE-TEST", "\tLength:" + s.length);

      Log.i("ROUTE-TEST", "\tfirstLoc:" + s.firstLoc);
      Log.i("ROUTE-TEST", "\tlastLoc:" + s.lastLoc);
      Log.i("ROUTE-TEST", "\ttype:" + s.type);
      Log.i("ROUTE-TEST", "\tIcon:" + s.getIconId());

      Log.i("ROUTE-TEST", "\tPath length:" + s.path.size());

      for (int j = 0; j < s.path.size(); j++) {
        PathSegment p = s.path.get(j);
        Log.i("ROUTE-TEST", "\t\tPath name:" + p.name);
        Log.i("ROUTE-TEST", "\t\tCoords:" + p.coords.x + " " + p.coords.y);
        Log.i("ROUTE-TEST", "\t\tarrTime:" + p.arrTime.toLocaleString());
        Log.i("ROUTE-TEST", "\t\tdepTime:" + p.depTime.toLocaleString());
      }
    }
  }
Esempio n. 2
0
  public Route(JSONObject obj) throws JSONException {
    this.duration = obj.getDouble("duration");
    this.length = obj.getDouble("length");

    JSONArray legs = obj.getJSONArray("legs");

    steps = new ArrayList<Route.RouteStep>();

    for (int i = 0; i < legs.length(); i++) {
      RouteStep s = new RouteStep();

      JSONObject leg = legs.getJSONObject(i);

      s.length = leg.getDouble("length");
      s.duration = leg.getDouble("duration");
      this.actual_duration += Math.ceil(s.duration / 60) * 60;

      try {
        s.desc = leg.getString("code");
      } catch (Exception e) {
        // Log.e("HelsinkiTravel", "That's ok");
      }
      ;

      try {
        s.type = leg.getInt("type");
      } catch (Exception e) {
        // Log.e("HelsinkiTravel", "That's ok");
      }
      ;

      JSONArray locs = leg.getJSONArray("locs");

      s.path = new ArrayList<Route.PathSegment>();

      for (int j = 0; j < locs.length(); j++) {
        JSONObject loc = locs.getJSONObject(j);
        JSONObject coord = loc.getJSONObject("coord");

        PathSegment p = new PathSegment();
        p.coords = new Coords(coord.getDouble("y"), coord.getDouble("x"));

        p.arrTime = parseReittiOpasDate(loc.getString("arrTime"));
        p.depTime = parseReittiOpasDate(loc.getString("depTime"));

        try {
          p.name = loc.getString("name");
        } catch (Exception e) {
          // Log.e("HelsinkiTravel", "That's ok");
        }
        ;

        if (p.name != null && !p.name.equals("nul")) {
          if (s.firstLoc.equals("")) s.firstLoc = p.name;
          s.lastLoc = p.name;
        }
        s.path.add(p);

        if (s.depTime == null && p.depTime != null) {
          s.depTime = parseReittiOpasDate(loc.getString("depTime"));
        }
        if (p.arrTime != null) {
          s.arrTime = parseReittiOpasDate(loc.getString("arrTime"));
        }

        if (this.depTime == null && p.depTime != null) {
          this.depTime = parseReittiOpasDate(loc.getString("depTime"));
        }
        if (p.arrTime != null) {
          this.arrTime = parseReittiOpasDate(loc.getString("arrTime"));
        }
        if (this.firstBusTime == null && p.depTime != null && s.type != 0) {
          this.firstBusTime = parseReittiOpasDate(loc.getString("depTime"));
        }
      }

      steps.add(s);
    }

    this.jsonString = obj.toString();
  }