コード例 #1
0
  @Override
  public void onListItemClick(ListView parent, View v, int position, long id) {
    final RouteInfoLocation item = ((TransportStopAdapter) getListAdapter()).getItem(position);
    Builder builder = new AlertDialog.Builder(this);
    List<String> items = new ArrayList<String>();
    final List<TransportStop> stops =
        item.getDirection()
            ? item.getRoute().getForwardStops()
            : item.getRoute().getBackwardStops();
    LatLon locationToGo = getLocationToGo();
    LatLon locationToStart = getLocationToStart();
    builder.setTitle(
        getString(R.string.transport_stop_to_go_out)
            + "\n"
            + getInformation(item, stops, getCurrentRouteLocation(), true)); // $NON-NLS-1$
    int ind = 0;
    for (TransportStop st : stops) {
      StringBuilder n = new StringBuilder(50);
      n.append(ind++);
      if (st == item.getStop()) {
        n.append("!! "); // $NON-NLS-1$
      } else {
        n.append(". "); // $NON-NLS-1$
      }
      String name = st.getName(settings.usingEnglishNames());
      if (locationToGo != null) {
        n.append(name).append(" - ["); // $NON-NLS-1$
        n.append(
                OsmAndFormatter.getFormattedDistance(
                    (int) MapUtils.getDistance(locationToGo, st.getLocation()),
                    (ClientContext) getApplication()))
            .append("]"); // $NON-NLS-1$
      } else if (locationToStart != null) {
        n.append("[")
            .append(
                OsmAndFormatter.getFormattedDistance(
                    (int) MapUtils.getDistance(locationToStart, st.getLocation()),
                    (ClientContext) getApplication()))
            .append("] - "); // $NON-NLS-1$ //$NON-NLS-2$
        n.append(name);
      } else {
        n.append(name);
      }
      items.add(n.toString());
    }
    builder.setItems(
        items.toArray(new String[items.size()]),
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            int i = which;
            if (i >= 0) {
              TransportStop stop = stops.get(i);
              showContextMenuOnStop(stop, item, i);
            }
          }
        });
    builder.show();
  }
コード例 #2
0
  public void showContextMenuOnRoute(final RouteInfoLocation route, final int routeInd) {
    Builder b = new AlertDialog.Builder(this);
    List<TransportStop> stops =
        route.getDirection()
            ? route.getRoute().getForwardStops()
            : route.getRoute().getBackwardStops();
    boolean en = settings.usingEnglishNames();

    String info = getInformation(route, stops, routeInd, false);
    StringBuilder txt = new StringBuilder(300);
    txt.append(info);
    boolean start = false;
    for (TransportStop s : stops) {
      if (s == route.getStart()) {
        start = true;
      }
      if (start) {
        txt.append("\n")
            .append(getString(R.string.transport_Stop))
            .append(" : ")
            .append(s.getName(en)); // $NON-NLS-1$ //$NON-NLS-2$
      }
      if (s == route.getStop()) {
        break;
      }
    }

    b.setMessage(txt.toString());
    b.setPositiveButton(getString(R.string.default_buttons_ok), null);
    b.setNeutralButton(
        getString(R.string.transport_search_before),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            int toInsert = routeInd;
            int c = getCurrentRouteLocation();
            if (c >= 0 && c < routeInd) {
              toInsert--;
            }
            intermediateListAdapater.remove(null);
            intermediateListAdapater.insert(null, toInsert);
            zoom = initialZoom;
            searchTransport();
          }
        });
    b.setNegativeButton(
        getString(R.string.transport_search_after),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            int toInsert = routeInd;
            int c = getCurrentRouteLocation();
            if (c > routeInd || c == -1) {
              toInsert++;
            }
            intermediateListAdapater.remove(null);
            intermediateListAdapater.insert(null, toInsert);
            zoom = initialZoom;
            searchTransport();
          }
        });
    b.show();
  }