コード例 #1
0
  private Direction decryptNonTransit(Leg leg) {
    Direction direction = new Direction();

    //
    //	http://opentripplanner.usf.edu/opentripplanner-api-webapp/ws/plan?optimize=QUICK&time=09:24pm&arriveBy=false&wheelchair=false&maxWalkDistance=7600.0&fromPlace=28.033389%2C+-82.521034&toPlace=28.064709%2C+-82.471618&date=03/07/12&mode=WALK,TRAM,SUBWAY,RAIL,BUS,FERRY,CABLE_CAR,GONDOLA,FUNICULAR,TRANSIT,TRAINISH,BUSISH

    // Get appropriate action and icon
    String action = "Walk";
    int icon = R.drawable.mode_walk;
    TraverseMode mode = TraverseMode.valueOf((String) leg.mode);
    if (mode.compareTo(TraverseMode.BICYCLE) == 0) {
      action = "Bike";
      icon = R.drawable.mode_bicycle;
    } else if (mode.compareTo(TraverseMode.CAR) == 0) {
      action = "Drive";
      icon = R.drawable.icon;
    }

    direction.setIcon(icon);

    //		Main direction
    Place fromPlace = leg.from;
    Place toPlace = leg.to;
    String mainDirectionText = action;
    mainDirectionText += fromPlace.name == null ? "" : " from " + fromPlace.name;
    mainDirectionText += toPlace.name == null ? "" : " to " + toPlace.name;
    mainDirectionText +=
        toPlace.stopId == null
            ? ""
            : " (" + toPlace.stopId.getAgencyId() + " " + toPlace.stopId.getId() + ")";
    //		double duration = DateTimeConversion.getDuration(leg.startTime, leg.endTime);
    double totalDistance = leg.distance;
    DecimalFormat twoDForm = new DecimalFormat("#.##");
    totalDistance = Double.valueOf(twoDForm.format(totalDistance));
    mainDirectionText += "\n[" + totalDistance + "meters ]"; // Double.toString(duration);

    direction.setDirectionText(mainDirectionText);

    //		Sub-direction
    List<WalkStep> walkSteps = leg.getSteps();

    if (walkSteps == null) return direction;

    ArrayList<Direction> subDirections = new ArrayList<Direction>(walkSteps.size());

    for (WalkStep step : walkSteps) {
      Direction dir = new Direction();
      String subDirectionText = "";

      double distance = step.distance;
      // Distance traveled [distance]
      distance = Double.valueOf(twoDForm.format(distance));
      dir.setDistanceTraveled(distance);

      RelativeDirection relativeDir = step.relativeDirection;
      String streetName = step.streetName;
      AbsoluteDirection absoluteDir = step.absoluteDirection;
      String exit = step.exit;
      boolean isStayOn = (step.stayOn == null ? false : step.stayOn);
      boolean isBogusName = (step.bogusName == null ? false : step.bogusName);
      double lon = step.lon;
      double lat = step.lat;
      String elevation = step.elevation;
      List<Alerts> alert = step.alerts;

      // Walk East
      if (relativeDir == null) {
        subDirectionText += action + " ";
        subDirectionText += absoluteDir.name() + " ";
      }
      // (Turn left)/(Continue)
      else {
        if (!isStayOn) {
          RelativeDirection rDir = RelativeDirection.valueOf(relativeDir.name());

          // Do not need TURN Continue
          if (rDir.compareTo(RelativeDirection.CONTINUE) != 0
              && rDir.compareTo(RelativeDirection.CIRCLE_CLOCKWISE) != 0
              && rDir.compareTo(RelativeDirection.CIRCLE_COUNTERCLOCKWISE) != 0) {
            subDirectionText += "Turn ";
          }

          subDirectionText += relativeDir.name() + " ";
        } else {
          subDirectionText += relativeDir.name() + " ";
        }
      }

      // (on ABC)
      //			if(!isBogusName) {
      //				subDirectionText += "on "+ streetName + " ";
      //			}

      subDirectionText += "on " + streetName + " ";

      subDirectionText += "\n[" + Double.toString(distance) + "meters ]";

      dir.setDirectionText(subDirectionText);

      dir.setIcon(icon);

      // Add new sub-direction
      subDirections.add(dir);
    }

    direction.setSubDirections(subDirections);

    return direction;
  }
コード例 #2
0
 public static String getLocalizedRelativeDir(RelativeDirection relDir, Resources resources) {
   if (relDir != null) {
     if (relDir.equals(RelativeDirection.CIRCLE_CLOCKWISE)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_circle_clockwise);
     } else if (relDir.equals(RelativeDirection.CIRCLE_COUNTERCLOCKWISE)) {
       return resources.getString(
           R.string.step_by_step_non_transit_dir_relative_circle_counterclockwise);
     } else if (relDir.equals(RelativeDirection.CONTINUE)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_continue);
     } else if (relDir.equals(RelativeDirection.DEPART)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_depart);
     } else if (relDir.equals(RelativeDirection.ELEVATOR)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_elevator);
     } else if (relDir.equals(RelativeDirection.HARD_LEFT)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_hard_left);
     } else if (relDir.equals(RelativeDirection.HARD_RIGHT)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_hard_right);
     } else if (relDir.equals(RelativeDirection.LEFT)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_left);
     } else if (relDir.equals(RelativeDirection.RIGHT)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_right);
     } else if (relDir.equals(RelativeDirection.SLIGHTLY_LEFT)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_slightly_left);
     } else if (relDir.equals(RelativeDirection.SLIGHTLY_RIGHT)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_slightly_right);
     } else if (relDir.equals(RelativeDirection.UTURN_LEFT)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_uturn_left);
     } else if (relDir.equals(RelativeDirection.UTURN_RIGHT)) {
       return resources.getString(R.string.step_by_step_non_transit_dir_relative_uturn_right);
     }
   }
   return null;
 }
コード例 #3
0
 public static int getRelativeDirectionIcon(RelativeDirection relDir, Resources resources) {
   if (relDir.equals(RelativeDirection.CIRCLE_CLOCKWISE)) {
     return R.drawable.ic_rotary_clockwise;
   } else if (relDir.equals(RelativeDirection.CIRCLE_COUNTERCLOCKWISE)) {
     return R.drawable.ic_rotary_counterclockwise;
   } else if (relDir.equals(RelativeDirection.CONTINUE)) {
     return R.drawable.ic_continue;
   } else if (relDir.equals(RelativeDirection.DEPART)) {
     return R.drawable.ic_depart;
   } else if (relDir.equals(RelativeDirection.ELEVATOR)) {
     return R.drawable.ic_elevator;
   } else if (relDir.equals(RelativeDirection.HARD_LEFT)) {
     return R.drawable.ic_turn_sharp_left;
   } else if (relDir.equals(RelativeDirection.HARD_RIGHT)) {
     return R.drawable.ic_turn_sharp_right;
   } else if (relDir.equals(RelativeDirection.LEFT)) {
     return R.drawable.ic_turn_left;
   } else if (relDir.equals(RelativeDirection.RIGHT)) {
     return R.drawable.ic_turn_right;
   } else if (relDir.equals(RelativeDirection.SLIGHTLY_LEFT)) {
     return R.drawable.ic_turn_slight_left;
   } else if (relDir.equals(RelativeDirection.SLIGHTLY_RIGHT)) {
     return R.drawable.ic_turn_slight_right;
   } else if (relDir.equals(RelativeDirection.UTURN_LEFT)) {
     return R.drawable.ic_uturn_left;
   } else if (relDir.equals(RelativeDirection.UTURN_RIGHT)) {
     return R.drawable.ic_uturn_right;
   } else {
     Log.d(TAG, "No icon for direction: " + relDir);
     return -1;
   }
 }
コード例 #4
0
  private Direction generateNonTransitDirections(Leg leg) {
    Direction direction = new Direction();

    // http://opentripplanner.usf.edu/opentripplanner-api-webapp/ws/plan?optimize=QUICK&time=09:24pm&arriveBy=false&wheelchair=false&maxWalkDistance=7600.0&fromPlace=28.033389%2C+-82.521034&toPlace=28.064709%2C+-82.471618&date=03/07/12&mode=WALK,TRAM,SUBWAY,RAIL,BUS,FERRY,CABLE_CAR,GONDOLA,FUNICULAR,TRANSIT,TRAINISH,BUSISH

    // Get appropriate action and icon
    String action =
        applicationContext
            .getResources()
            .getString(R.string.step_by_step_non_transit_mode_walk_action);
    TraverseMode mode = TraverseMode.valueOf((String) leg.mode);
    int icon = getModeIcon(new TraverseModeSet(mode));
    if (mode.compareTo(TraverseMode.BICYCLE) == 0) {
      action =
          applicationContext
              .getResources()
              .getString(R.string.step_by_step_non_transit_mode_bicycle_action);
    } else if (mode.compareTo(TraverseMode.CAR) == 0) {
      action =
          applicationContext
              .getResources()
              .getString(R.string.step_by_step_non_transit_mode_car_action);
    }

    direction.setIcon(icon);

    // Main direction
    Place fromPlace = leg.from;
    Place toPlace = leg.to;
    String mainDirectionText = action;
    mainDirectionText +=
        fromPlace.name == null
            ? ""
            : " "
                + applicationContext
                    .getResources()
                    .getString(R.string.step_by_step_non_transit_from)
                + " "
                + getLocalizedStreetName(fromPlace.name, applicationContext.getResources());
    mainDirectionText +=
        toPlace.name == null
            ? ""
            : " "
                + applicationContext.getResources().getString(R.string.step_by_step_non_transit_to)
                + " "
                + getLocalizedStreetName(toPlace.name, applicationContext.getResources());
    String extraStopInformation = toPlace.stopCode;
    long legDuration;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext);
    if (prefs.getInt(OTPConstants.PREFERENCE_KEY_API_VERSION, OTPConstants.API_VERSION_V1)
        == OTPConstants.API_VERSION_V1) {
      legDuration = leg.duration;
    } else {
      legDuration = leg.duration / 1000;
    }
    if (!TextUtils.isEmpty(extraStopInformation)) {
      mainDirectionText += " (" + extraStopInformation + ")";
    }
    mainDirectionText +=
        "\n["
            + ConversionUtils.getFormattedDistance(leg.distance, applicationContext)
            + " - "
            + ConversionUtils.getFormattedDurationTextNoSeconds(
                legDuration, false, applicationContext)
            + " ]";
    direction.setDirectionText(mainDirectionText);

    // Sub-direction
    List<WalkStep> walkSteps = leg.getSteps();

    if (walkSteps == null) {
      return direction;
    }

    ArrayList<Direction> subDirections = new ArrayList<Direction>(walkSteps.size());

    for (WalkStep step : walkSteps) {
      int subdirection_icon = -1;
      Direction dir = new Direction();
      String subDirectionText = "";

      double distance = step.distance;

      RelativeDirection relativeDir = step.relativeDirection;
      String relativeDirString =
          getLocalizedRelativeDir(relativeDir, applicationContext.getResources());
      String streetName = step.streetName;
      AbsoluteDirection absoluteDir = step.absoluteDirection;
      String absoluteDirString =
          getLocalizedAbsoluteDir(absoluteDir, applicationContext.getResources());
      String exit = step.exit;
      boolean isStayOn = (step.stayOn == null ? false : step.stayOn);
      boolean isBogusName = (step.bogusName == null ? false : step.bogusName);
      double lon = step.lon;
      double lat = step.lat;
      String streetConnector =
          applicationContext
              .getResources()
              .getString(R.string.step_by_step_non_transit_connector_street_name);
      // Elevation[] elevation = step.getElevation();  //Removed elevation for now, since we're not
      // doing anything with it and it causes version issues between OTP server APIs v0.9.1-SNAPSHOT
      // and v0.9.2-SNAPSHOT
      List<Alerts> alert = step.alerts;

      // Walk East
      if (relativeDir == null) {
        subDirectionText +=
            action
                + " "
                + applicationContext
                    .getResources()
                    .getString(R.string.step_by_step_non_transit_heading)
                + " ";
        subDirectionText += absoluteDirString + " ";
      }
      // (Turn left)/(Continue)
      else {
        RelativeDirection rDir = RelativeDirection.valueOf(relativeDir.name());

        subdirection_icon = getRelativeDirectionIcon(rDir, applicationContext.getResources());

        // Do not need TURN Continue
        if (rDir.compareTo(RelativeDirection.RIGHT) == 0
            || rDir.compareTo(RelativeDirection.LEFT) == 0) {
          subDirectionText +=
              applicationContext.getResources().getString(R.string.step_by_step_non_transit_turn)
                  + " ";
        }

        subDirectionText += relativeDirString + " ";

        if (rDir.compareTo(RelativeDirection.CIRCLE_CLOCKWISE) == 0
            || rDir.compareTo(RelativeDirection.CIRCLE_COUNTERCLOCKWISE) == 0) {
          if (step.exit != null) {
            try {
              String ordinal =
                  getOrdinal(Integer.parseInt(step.exit), applicationContext.getResources());
              if (ordinal != null) {
                subDirectionText += ordinal + " ";
              } else {
                subDirectionText +=
                    applicationContext
                            .getResources()
                            .getString(R.string.step_by_step_non_transit_roundabout_number)
                        + " "
                        + ordinal
                        + " ";
              }
            } catch (NumberFormatException e) {
              // If is not a step_by_step_non_transit_roundabout_number and is not null is better to
              // try to display it
              subDirectionText += step.exit + " ";
            }
            subDirectionText +=
                applicationContext
                        .getResources()
                        .getString(R.string.step_by_step_non_transit_roundabout_exit)
                    + " ";
            streetConnector =
                applicationContext
                    .getResources()
                    .getString(R.string.step_by_step_non_transit_connector_street_name_roundabout);
          }
        }
      }

      subDirectionText +=
          streetConnector
              + " "
              + getLocalizedStreetName(streetName, applicationContext.getResources())
              + " ";

      subDirectionText +=
          "\n[" + ConversionUtils.getFormattedDistance(distance, applicationContext) + " ]";

      dir.setDirectionText(subDirectionText);

      dir.setIcon(subdirection_icon);

      // Add new sub-direction
      subDirections.add(dir);
    }

    direction.setSubDirections(subDirections);

    return direction;
  }