/**
   * @param stop
   * @param format {0} - ref, {1} - type, {2} - name, {3} - name_en
   * @return null if something goes wrong
   */
  @Override
  public List<String> getRouteDescriptionsForStop(TransportStop stop, String format) {
    assert acceptTransportStop(stop);
    long now = System.currentTimeMillis();

    MessageFormat f = new MessageFormat(format);
    List<String> res = new ArrayList<String>();
    try {
      List<TransportRoute> routes = file.getTransportRouteDescriptions(stop);
      if (routes != null) {
        for (TransportRoute route : routes) {
          res.add(
              f.format(
                  new String[] {
                    route.getRef() + "",
                    route.getType() + "",
                    route.getName() + "",
                    route.getEnName() + ""
                  })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        }
      }
    } catch (IOException e) {
      log.error("Disk error ", e); // $NON-NLS-1$
    }

    if (log.isDebugEnabled()) {
      log.debug(
          String.format(
              "Search for stop %s done in %s ms found %s.", //$NON-NLS-1$
              stop.getId() + "", System.currentTimeMillis() - now, res.size())); // $NON-NLS-1$
    }
    return res;
  }
  private void insertTransportIntoIndex(TransportRoute route) throws SQLException {
    transRouteStat.setLong(1, route.getId());
    transRouteStat.setString(2, route.getType());
    transRouteStat.setString(3, route.getOperator());
    transRouteStat.setString(4, route.getRef());
    transRouteStat.setString(5, route.getName());
    transRouteStat.setString(6, route.getEnName());
    transRouteStat.setInt(7, route.getAvgBothDistance());
    addBatch(transRouteStat);

    writeRouteStops(route, route.getForwardStops(), true);
    writeRouteStops(route, route.getBackwardStops(), false);
  }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View row = convertView;
      if (row == null) {
        LayoutInflater inflater = getLayoutInflater();
        row = inflater.inflate(R.layout.search_transport_list_item, parent, false);
      }
      LatLon locationToGo = getLocationToGo();
      LatLon locationToStart = getLocationToStart();

      TextView label = (TextView) row.findViewById(R.id.label);
      ImageView icon = (ImageView) row.findViewById(R.id.search_icon);
      RouteInfoLocation stop = getItem(position);

      TransportRoute route = stop.getRoute();
      StringBuilder labelW = new StringBuilder(150);
      labelW.append(route.getType()).append(" ").append(route.getRef()); // $NON-NLS-1$
      labelW.append(" - ["); // $NON-NLS-1$

      if (locationToGo != null) {
        labelW.append(
            OsmAndFormatter.getFormattedDistance(
                stop.getDistToLocation(), SearchTransportActivity.this));
      } else {
        labelW.append(getString(R.string.transport_search_none));
      }
      labelW.append("]\n").append(route.getName(settings.usingEnglishNames())); // $NON-NLS-1$

      // TODO icons
      if (locationToGo != null && stop.getDistToLocation() < 400) {
        icon.setImageResource(R.drawable.opened_poi);
      } else {
        icon.setImageResource(R.drawable.poi);
      }

      int dist =
          locationToStart == null
              ? 0
              : (int) (MapUtils.getDistance(stop.getStart().getLocation(), locationToStart));
      String distance =
          OsmAndFormatter.getFormattedDistance(dist, SearchTransportActivity.this)
              + " "; //$NON-NLS-1$
      label.setText(distance + labelW.toString(), TextView.BufferType.SPANNABLE);
      ((Spannable) label.getText())
          .setSpan(
              new ForegroundColorSpan(getResources().getColor(R.color.color_distance)),
              0,
              distance.length() - 1,
              0);
      return (row);
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
      View row = convertView;
      final RouteInfoLocation info = getItem(position);
      if (info == null) {
        TextView text = new TextView(getContext());
        LatLon st = getStartStop(position + 1);
        LatLon end = getEndStop(position - 1);

        if (st != null && end != null) {
          int dist = (int) MapUtils.getDistance(st, end);
          text.setText(
              MessageFormat.format(
                  getString(R.string.transport_searching_route),
                  OsmAndFormatter.getFormattedDistance(dist, SearchTransportActivity.this)));
        } else {
          text.setText(getString(R.string.transport_searching_transport));
        }
        text.setTextSize(21);
        text.setTypeface(null, Typeface.ITALIC);
        text.setOnClickListener(
            new View.OnClickListener() {

              @Override
              public void onClick(View v) {
                if (intermediateListAdapater.getCount() > 1) {
                  intermediateListAdapater.remove(null);
                  searchTransport();
                } else {
                  if (selectedDestinationLocation == null) {
                    selectedDestinationLocation = destinationLocation;
                  } else {
                    selectedDestinationLocation = null;
                  }
                  searchTransport();
                }
              }
            });
        return text;
      }
      int currentRouteLocation = getCurrentRouteLocation();
      if (row == null || row instanceof TextView) {
        LayoutInflater inflater = getLayoutInflater();
        row = inflater.inflate(R.layout.search_transport_route_item, parent, false);
      }

      TextView label = (TextView) row.findViewById(R.id.label);
      ImageButton icon = (ImageButton) row.findViewById(R.id.remove);

      TransportRoute route = info.getRoute();
      icon.setVisibility(View.VISIBLE);
      StringBuilder labelW = new StringBuilder(150);
      labelW.append(route.getType()).append(" ").append(route.getRef()); // $NON-NLS-1$
      boolean en = settings.usingEnglishNames();
      labelW
          .append(" : ")
          .append(info.getStart().getName(en))
          .append(" - ")
          .append(info.getStop().getName(en)); // $NON-NLS-1$ //$NON-NLS-2$
      // additional information  if route is calculated
      if (currentRouteLocation == -1) {
        labelW.append(" ("); // $NON-NLS-1$
        labelW
            .append(info.getStopNumbers())
            .append(" ")
            .append(getString(R.string.transport_stops))
            .append(", "); // $NON-NLS-1$ //$NON-NLS-2$
        int startDist =
            (int) MapUtils.getDistance(getEndStop(position - 1), info.getStart().getLocation());
        labelW
            .append(getString(R.string.transport_to_go_before))
            .append(" ")
            .append(
                OsmAndFormatter.getFormattedDistance(
                    startDist, SearchTransportActivity.this)); // $NON-NLS-1$
        if (position == getCount() - 1) {
          LatLon stop = getStartStop(position + 1);
          if (stop != null) {
            int endDist = (int) MapUtils.getDistance(stop, info.getStop().getLocation());
            labelW
                .append(", ")
                .append(getString(R.string.transport_to_go_after))
                .append(" ")
                .append(
                    OsmAndFormatter.getFormattedDistance(
                        endDist, SearchTransportActivity.this)); // $NON-NLS-1$ //$NON-NLS-2$
          }
        }

        labelW.append(")"); // $NON-NLS-1$
      }
      label.setText(labelW.toString());
      icon.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              int p = position;
              intermediateListAdapater.remove(null);
              if (!isRouteCalculated() && getCurrentRouteLocation() < p) {
                p--;
              }
              intermediateListAdapater.insert(null, p);
              intermediateListAdapater.remove(info);
              intermediateListAdapater.notifyDataSetChanged();
              zoom = initialZoom;
              searchTransport();
            }
          });
      View.OnClickListener clickListener =
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              showContextMenuOnRoute(info, position);
            }
          };
      label.setOnClickListener(clickListener);
      return row;
    }