コード例 #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 boolean updateInfo(RotatedTileBox tb, DrawSettings nightMode) {
      boolean visible = true;
      OsmandMapTileView view = ma.getMapView();
      // update cache
      if (view.isZooming()) {
        visible = false;
      } else if (!orientationPortrait && ma.getRoutingHelper().isRoutePlanningMode()) {
        visible = false;
      } else if ((tb.getZoom() != cacheRulerZoom
              || Math.abs(tb.getCenterTileX() - cacheRulerTileX) > 1
              || Math.abs(tb.getCenterTileY() - cacheRulerTileY) > 1)
          && tb.getPixWidth() > 0
          && maxWidth > 0) {
        cacheRulerZoom = tb.getZoom();
        cacheRulerTileX = tb.getCenterTileX();
        cacheRulerTileY = tb.getCenterTileY();
        final double dist =
            tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2);
        double pixDensity = tb.getPixWidth() / dist;
        double roundedDist =
            OsmAndFormatter.calculateRoundedDist(maxWidth / pixDensity, view.getApplication());

        int cacheRulerDistPix = (int) (pixDensity * roundedDist);
        cacheRulerText =
            OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getApplication());
        textShadow.setText(cacheRulerText);
        text.setText(cacheRulerText);
        ViewGroup.LayoutParams lp = layout.getLayoutParams();
        lp.width = cacheRulerDistPix;
        layout.setLayoutParams(lp);
        layout.requestLayout();
      }
      updateVisibility(layout, visible);
      return true;
    }
コード例 #3
0
  public String getInformation(
      RouteInfoLocation route, List<TransportStop> stops, int position, boolean part) {
    StringBuilder text = new StringBuilder(200);
    double dist = 0;
    int ind = 0;
    int stInd = stops.size();
    int eInd = stops.size();
    for (TransportStop s : stops) {
      if (s == route.getStart()) {
        stInd = ind;
      }
      if (s == route.getStop()) {
        eInd = ind;
      }
      if (ind > stInd && ind <= eInd) {
        dist += MapUtils.getDistance(stops.get(ind - 1).getLocation(), s.getLocation());
      }
      ind++;
    }
    text.append(getString(R.string.transport_route_distance))
        .append(" ")
        .append(
            OsmAndFormatter.getFormattedDistance(
                (int) dist, (ClientContext) getApplication())); // $NON-NLS-1$/
    if (!part) {
      text.append(", ")
          .append(getString(R.string.transport_stops_to_pass))
          .append(" ")
          .append(eInd - stInd); // $NON-NLS-1$ //$NON-NLS-2$
      LatLon endStop = getEndStop(position - 1);
      if (endStop != null) {
        String before =
            OsmAndFormatter.getFormattedDistance(
                (int) MapUtils.getDistance(endStop, route.getStart().getLocation()),
                (ClientContext) getApplication());
        text.append(", ")
            .append(getString(R.string.transport_to_go_before))
            .append(" ")
            .append(before); // $NON-NLS-2$//$NON-NLS-1$
      }

      LatLon stStop = getStartStop(position + 1);
      if (stStop != null) {
        String after =
            OsmAndFormatter.getFormattedDistance(
                (int) MapUtils.getDistance(stStop, route.getStop().getLocation()),
                (ClientContext) getApplication());
        text.append(", ")
            .append(getString(R.string.transport_to_go_after))
            .append(" ")
            .append(after); // $NON-NLS-1$ //$NON-NLS-2$
      }
    }

    return text.toString();
  }
コード例 #4
0
    @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(), (ClientContext) getApplication()));
      } 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, (ClientContext) getApplication())
              + " "; //$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);
    }
コード例 #5
0
 @Override
 public void onZoomEnded(double relativeToStart, float angleRelative) {
   // 1.5 works better even on dm.density=1 devices
   float dz = (float) (Math.log(relativeToStart) / Math.log(2)) * 1.5f;
   setIntZoom(Math.round(dz) + initialViewport.getZoom());
   if (Math.abs(angleRelative) < ANGLE_THRESHOLD) {
     angleRelative = 0;
   }
   rotateToAnimate(initialViewport.getRotate() + angleRelative);
   final int newZoom = getZoom();
   if (application.getInternalAPI().accessibilityEnabled()) {
     if (newZoom != initialViewport.getZoom()) {
       showMessage(getContext().getString(R.string.zoomIs) + " " + newZoom); // $NON-NLS-1$
     } else {
       final LatLon p1 = initialViewport.getLatLonFromPixel(x1, y1);
       final LatLon p2 = initialViewport.getLatLonFromPixel(x2, y2);
       showMessage(
           OsmAndFormatter.getFormattedDistance(
               (float)
                   MapUtils.getDistance(
                       p1.getLatitude(), p1.getLongitude(), p2.getLatitude(), p2.getLongitude()),
               application));
     }
   }
 }
コード例 #6
0
ファイル: RoutingHelper.java プロジェクト: herrbert74/Osmand
 public String getGeneralRouteInformation() {
   int dist = getLeftDistance();
   int hours = getLeftTime() / (60 * 60);
   int minutes = (getLeftTime() / 60) % 60;
   return app.getString(
       R.string.route_general_information,
       OsmAndFormatter.getFormattedDistance(dist, app),
       hours,
       minutes);
 }
コード例 #7
0
ファイル: RoutingHelper.java プロジェクト: herrbert74/Osmand
    @Override
    public void run() {

      RouteCalculationResult res = provider.calculateRouteImpl(params);
      if (params.calculationProgress.isCancelled) {
        currentRunningJob = null;
        return;
      }
      final boolean onlineSourceWithoutInternet =
          !res.isCalculated()
              && params.type.isOnline()
              && !settings.isInternetConnectionAvailable();
      if (onlineSourceWithoutInternet && settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
        if (params.previousToRecalculate != null && params.previousToRecalculate.isCalculated()) {
          res = provider.recalculatePartOfflineRoute(res, params);
        }
      }

      synchronized (RoutingHelper.this) {
        if (res.isCalculated()) {
          setNewRoute(res, params.start);
        } else {
          evalWaitInterval = evalWaitInterval * 3 / 2;
          evalWaitInterval = Math.min(evalWaitInterval, 120000);
        }
        currentRunningJob = null;
      }

      if (res.isCalculated()) {
        String msg =
            app.getString(R.string.new_route_calculated_dist)
                + ": "
                + OsmAndFormatter.getFormattedDistance(res.getWholeDistance(), app);
        if (res.getRoutingTime() != 0f) {
          msg += " (" + Algorithms.formatDuration((int) res.getRoutingTime()) + ")";
        }
        showMessage(msg);
      } else if (onlineSourceWithoutInternet) {
        showMessage(
            app.getString(R.string.error_calculating_route)
                + ":\n"
                + app.getString(
                    R.string.internet_connection_required_for_online_route)); // $NON-NLS-1$
      } else {
        if (res.getErrorMessage() != null) {
          showMessage(
              app.getString(R.string.error_calculating_route)
                  + ":\n"
                  + res.getErrorMessage()); // $NON-NLS-1$
        } else {
          showMessage(app.getString(R.string.empty_route_calculated));
        }
      }
      lastTimeEvaluatedRoute = System.currentTimeMillis();
    }
コード例 #8
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      LayoutInflater inflater = getLayoutInflater();
      View row = convertView;
      if (row == null) {
        row = inflater.inflate(R.layout.editing_poi_filter_list, parent, false);
      }
      AmenityType model = getItem(position);

      CheckBox check = (CheckBox) row.findViewById(R.id.filter_poi_check);
      check.setChecked(filter.isTypeAccepted(model));

      TextView text = (TextView) row.findViewById(R.id.filter_poi_label);
      text.setText(OsmAndFormatter.toPublicString(model, getMyApplication()));
      addRowListener(model, text, check);
      return (row);
    }
コード例 #9
0
 @Override
 public boolean updateInfo(DrawSettings drawSettings) {
   int d = getDistance();
   if (distChanged(cachedMeters, d)) {
     cachedMeters = d;
     if (cachedMeters <= 20) {
       cachedMeters = 0;
       setText(null, null);
     } else {
       String ds = OsmAndFormatter.getFormattedDistance(cachedMeters, view.getApplication());
       int ls = ds.lastIndexOf(' ');
       if (ls == -1) {
         setText(ds, null);
       } else {
         setText(ds.substring(0, ls), ds.substring(ls + 1));
       }
     }
     return true;
   }
   return false;
 }
コード例 #10
0
  private void updateDistance() {
    int deviatePath = turnDrawable.deviatedFromRoute ? deviatedPath : nextTurnDistance;
    String ds = OsmAndFormatter.getFormattedDistance(deviatePath, app);

    if (ds != null) {
      TurnType turnType = getTurnType();
      RoutingHelper routingHelper = app.getRoutingHelper();
      if ((turnType != null) && (routingHelper != null)) {
        setContentDescription(ds + " " + routingHelper.getRoute().toString(turnType, app));
      } else {
        setContentDescription(ds);
      }
    }

    int ls = ds.lastIndexOf(' ');
    if (ls == -1) {
      setTextNoUpdateVisibility(ds, null);
    } else {
      setTextNoUpdateVisibility(ds.substring(0, ls), ds.substring(ls + 1));
    }
  }
コード例 #11
0
 public String getDistance(RoutePoint rp) {
   double d = MapUtils.getDistance(rp.getPoint(), getPoint());
   String distance = OsmAndFormatter.getFormattedDistance((float) d, app);
   return distance;
 }
コード例 #12
0
ファイル: WaypointHelper.java プロジェクト: AmZaf/Osmand
 @Override
 public PointDescription getPointDescription(Context ctx) {
   return new PointDescription(
       PointDescription.POINT_TYPE_POI,
       OsmAndFormatter.getPoiStringWithoutType(a, app.getSettings().MAP_PREFERRED_LOCALE.get()));
 }
コード例 #13
0
    @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, (ClientContext) getApplication())));
        } 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, (ClientContext) getApplication())); // $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, (ClientContext) getApplication())); // $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;
    }
コード例 #14
0
 public boolean updateInfo(DrawSettings drawSettings) {
   boolean visible = false;
   int locimminent = -1;
   int[] loclanes = null;
   int dist = 0;
   // TurnType primary = null;
   if ((rh == null || !rh.isFollowingMode())
       && trackingUtilities.isMapLinkedToLocation()
       && settings.SHOW_LANES.get()) {
     RouteDataObject ro = locationProvider.getLastKnownRouteSegment();
     Location lp = locationProvider.getLastKnownLocation();
     if (ro != null) {
       float degree = lp == null || !lp.hasBearing() ? 0 : lp.getBearing();
       loclanes = RouteResultPreparation.parseTurnLanes(ro, degree / 180 * Math.PI);
       if (loclanes == null) {
         loclanes = RouteResultPreparation.parseLanes(ro, degree / 180 * Math.PI);
       }
     }
   } else if (rh != null && rh.isRouteCalculated()) {
     if (rh.isFollowingMode() && settings.SHOW_LANES.get()) {
       NextDirectionInfo r = rh.getNextRouteDirectionInfo(new NextDirectionInfo(), false);
       if (r != null && r.directionInfo != null && r.directionInfo.getTurnType() != null) {
         loclanes = r.directionInfo.getTurnType().getLanes();
         // primary = r.directionInfo.getTurnType();
         locimminent = r.imminent;
         // Do not show too far
         if ((r.distanceTo > 800 && r.directionInfo.getTurnType().isSkipToSpeak())
             || r.distanceTo > 1200) {
           loclanes = null;
         }
         dist = r.distanceTo;
       }
     } else {
       int di = MapRouteInfoControl.getDirectionInfo();
       if (di >= 0
           && MapRouteInfoControl.isControlVisible()
           && di < rh.getRouteDirections().size()) {
         RouteDirectionInfo next = rh.getRouteDirections().get(di);
         if (next != null) {
           loclanes = next.getTurnType().getLanes();
           // primary = next.getTurnType();
         }
       }
     }
   }
   visible = loclanes != null && loclanes.length > 0;
   if (visible) {
     if (!Arrays.equals(lanesDrawable.lanes, loclanes)
         || (locimminent == 0) != lanesDrawable.imminent) {
       lanesDrawable.imminent = locimminent == 0;
       lanesDrawable.lanes = loclanes;
       lanesDrawable.updateBounds();
       lanesView.setImageDrawable(null);
       lanesView.setImageDrawable(lanesDrawable);
       lanesView.requestLayout();
       lanesView.invalidate();
     }
     if (distChanged(dist, this.dist)) {
       this.dist = dist;
       if (dist == 0) {
         lanesShadowText.setText("");
         lanesText.setText("");
       } else {
         lanesShadowText.setText(OsmAndFormatter.getFormattedDistance(dist, app));
         lanesText.setText(OsmAndFormatter.getFormattedDistance(dist, app));
       }
       lanesShadowText.invalidate();
       lanesText.invalidate();
     }
   }
   updateVisibility(lanesShadowText, visible && shadowRadius > 0);
   updateVisibility(lanesText, visible);
   updateVisibility(lanesView, visible);
   updateVisibility(centerInfo, visible || progress.getVisibility() == View.VISIBLE);
   return true;
 }