Ejemplo n.º 1
0
 @Override
 public void onClick(View convertView) {
   LogHelper.d("test", "test item clicked: ");
   ViewHolder holder = (ViewHolder) convertView.getTag();
   CompoundButton b = holder.cbFilter;
   b.setChecked(!b.isChecked());
 }
Ejemplo n.º 2
0
  public ArrayList<Direction> getDirectionsFromEdges(ArrayList<Edge> pathData) {
    if (pathData == null || pathData.size() == 0) return null;
    Node n;
    Edge edge;
    ArrayList<Direction> directions = new ArrayList<Direction>();
    int currentType = Edge.TYPE_WALK;
    Direction direction = null;

    int prevEdgeType = -1;
    String title = "";
    for (int i = 0; i < pathData.size(); i++) {
      try {
        edge = pathData.get(i);
        if (edge.getEdgeType() == Edge.TYPE_WAIT) {
          // special case: if the final destination is a bus/tram stop
          // we add a final indicator for destination node
          if (i == (pathData.size() - 1)) { // last edge. must display destination
            n = edge.getToNode();
            direction = new Direction(edge, "Reach destination at " + n.getTitle());
            directions.add(direction);
            direction.setFrom(edge.getFromNodeTitle());
            LogHelper.d("2359", "Edge: Direction added: " + "Reach destination at " + n.getTitle());
            break;
          }

          if (edge.getCostForEdge() > 0) title = edge.getFromNode().getTitle();
          continue;
        }

        if (i == 0) { // first edge. must display start point
          currentType = edge.getEdgeType();
          n = edge.getFromNode();
          if (n.getTitle() != null) title = n.getTitle();
          String descText = edge.getLineName();
          if (edge.getEdgeType() == Edge.TYPE_WALK) {
            if (edge.getCostForEdge() == Edge.DUMMY_EDGE_COST)
              descText = "Walk from your starting location";
            else descText = descText.replace("Alight", "Start").replace("#NODE_NAME#", title);
          } else {
            descText =
                descText
                    .replace("Board", "Start at " + title + " and board")
                    .replace("#NODE_NAME#", "");
          }
          direction = new Direction(edge, descText);
          directions.add(direction);
          direction.setFrom(edge.getFromNodeTitle());
          LogHelper.d("2359", "Edge: Direction added: " + descText);

        } else {
          if (edge.getEdgeType() != currentType) {
            // if there is a change in the type of edge
            currentType = edge.getEdgeType();
            n = edge.getFromNode();
            if (n.getTitle() != null) title = n.getTitle();
            String descText = edge.getLineName();
            if (prevEdgeType != Edge.TYPE_WALK && edge.getEdgeType() != Edge.TYPE_WALK)
              descText = descText.replace("Board", "Alight and change to");
            descText = descText.replace("#NODE_NAME#", title);
            direction = new Direction(edge, descText);
            directions.add(direction);
            direction.setFrom(edge.getFromNodeTitle());
            LogHelper.d("2359", "Edge: Direction added: " + descText);
          }
        }

        // add a final indicator for destination node
        if (i == (pathData.size() - 1)) { // last edge. must display destination
          n = edge.getToNode();
          direction = new Direction(edge, "Reach destination at " + n.getTitle());
          directions.add(direction);
          direction.setFrom(edge.getFromNodeTitle());
          LogHelper.d("2359", "Edge: Direction added: " + "Reach destination at " + n.getTitle());
        }

        prevEdgeType = edge.getEdgeType();

        float results[] = {0};
        Location.distanceBetween(
            edge.getFromNode().getLatE6() / 1E6,
            edge.getFromNode().getLongE6() / 1E6,
            edge.getToNode().getLatE6() / 1E6,
            edge.getToNode().getLongE6() / 1E6,
            results);

        LogHelper.d(
            "2359",
            "Edge: From:"
                + edge.getFromNodeTitle()
                + ", To: "
                + edge.getToNodeTitle()
                + ", Type: "
                + edge.getLineLabel()
                + ", Distance: "
                + results[0]
                + " m");
        if (direction != null) {
          direction.setDistance(direction.getDistance() + results[0]);
          direction.setTo(edge.getToNodeTitle());
          if (edge.getEdgeType() != Edge.TYPE_WAIT && edge.getEdgeType() != Edge.TYPE_WALK) {
            direction.setStops(direction.getStops() + 1);
          }
        }
      } catch (Exception ignore) {
        ignore.printStackTrace();
      }
    }
    return directions;
  }