public boolean updateInfo(DrawSettings drawSettings) {
   boolean trafficWarnings = settings.SHOW_TRAFFIC_WARNINGS.get();
   boolean cams = settings.SHOW_CAMERAS.get();
   boolean peds = settings.SHOW_PEDESTRIAN.get();
   boolean visible = false;
   boolean eval = rh.isFollowingMode() || trackingUtilities.isMapLinkedToLocation();
   if ((trafficWarnings || cams) && eval) {
     AlarmInfo alarm;
     if (rh.isFollowingMode()) {
       alarm = wh.getMostImportantAlarm(settings.METRIC_SYSTEM.get(), cams);
     } else {
       RouteDataObject ro = locationProvider.getLastKnownRouteSegment();
       Location loc = locationProvider.getLastKnownLocation();
       if (ro != null && loc != null) {
         alarm = wh.calculateMostImportantAlarm(ro, loc, settings.METRIC_SYSTEM.get(), cams);
       } else {
         alarm = null;
       }
     }
     if (alarm != null) {
       int locimgId = R.drawable.warnings_limit;
       String text = "";
       if (alarm.getType() == AlarmInfoType.SPEED_LIMIT) {
         if (settings.DRIVING_REGION.get().americanSigns) {
           locimgId = R.drawable.warnings_speed_limit_us;
           // else case is done by drawing red ring
         }
         text = alarm.getIntValue() + "";
       } else if (alarm.getType() == AlarmInfoType.SPEED_CAMERA) {
         locimgId = R.drawable.warnings_speed_camera;
       } else if (alarm.getType() == AlarmInfoType.BORDER_CONTROL) {
         locimgId = R.drawable.warnings_border_control;
       } else if (alarm.getType() == AlarmInfoType.HAZARD) {
         locimgId = R.drawable.warnings_hazard;
       } else if (alarm.getType() == AlarmInfoType.TOLL_BOOTH) {
         // image done by drawing red ring
       } else if (alarm.getType() == AlarmInfoType.TRAFFIC_CALMING) {
         if (settings.DRIVING_REGION.get().americanSigns) {
           locimgId = R.drawable.warnings_traffic_calming_us;
         } else {
           locimgId = R.drawable.warnings_traffic_calming;
         }
       } else if (alarm.getType() == AlarmInfoType.STOP) {
         locimgId = R.drawable.warnings_stop;
       } else if (alarm.getType() == AlarmInfoType.RAILWAY) {
         if (settings.DRIVING_REGION.get().americanSigns) {
           locimgId = R.drawable.warnings_railways_us;
         } else {
           locimgId = R.drawable.warnings_railways;
         }
       } else if (alarm.getType() == AlarmInfoType.PEDESTRIAN) {
         if (settings.DRIVING_REGION.get().americanSigns) {
           locimgId = R.drawable.warnings_pedestrian_us;
         } else {
           locimgId = R.drawable.warnings_pedestrian;
         }
       } else {
         text = null;
       }
       visible = (text != null && text.length() > 0) || (locimgId != 0);
       if (visible) {
         if (alarm.getType() == AlarmInfoType.SPEED_CAMERA) {
           visible = cams;
         } else if (alarm.getType() == AlarmInfoType.PEDESTRIAN) {
           visible = peds;
         } else {
           visible = trafficWarnings;
         }
       }
       if (visible) {
         if (locimgId != imgId) {
           imgId = locimgId;
           icon.setImageResource(locimgId);
         }
         if (!Algorithms.objectEquals(text, this.textString)) {
           textString = text;
           this.text.setText(this.textString);
         }
       }
     }
   }
   updateVisibility(layout, visible);
   return true;
 }
Ejemplo n.º 2
0
    public boolean updateInfo(DrawSettings d) {
      String text = null;
      TurnType[] type = new TurnType[1];
      boolean showNextTurn = false;
      if (routingHelper != null && routingHelper.isRouteCalculated()) {
        if (routingHelper.isFollowingMode()) {
          if (settings.SHOW_STREET_NAME.get()) {
            text = routingHelper.getCurrentName(type);
            if (text == null) {
              text = "";
            }
          }
        } else {
          int di = MapRouteInfoMenu.getDirectionInfo();
          if (di >= 0
              && MapRouteInfoMenu.isControlVisible()
              && di < routingHelper.getRouteDirections().size()) {
            showNextTurn = true;
            RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
            type[0] = next.getTurnType();
            text =
                RoutingHelper.formatStreetName(
                    next.getStreetName(), next.getRef(), next.getDestinationName());
            //						if(next.distance > 0) {
            //							text += " " + OsmAndFormatter.getFormattedDistance(next.distance,
            // map.getMyApplication());
            //						}
            if (text == null) {
              text = "";
            }
          }
        }
      } else if (settings.getApplicationMode() != ApplicationMode.DEFAULT
          && map.getMapViewTrackingUtilities().isMapLinkedToLocation()
          && settings.SHOW_STREET_NAME.get()) {
        RouteDataObject rt = locationProvider.getLastKnownRouteSegment();
        if (rt != null) {
          text =
              RoutingHelper.formatStreetName(
                  rt.getName(settings.MAP_PREFERRED_LOCALE.get()),
                  rt.getRef(),
                  rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()));
        }
        if (text == null) {
          text = "";
        }
      }
      if (!showNextTurn && updateWaypoint()) {
        updateVisibility(true);
        updateVisibility(addressText, false);
        updateVisibility(addressTextShadow, false);
      } else if (text == null) {
        updateVisibility(false);
      } else {
        updateVisibility(true);
        updateVisibility(waypointInfoBar, false);
        updateVisibility(addressText, true);
        updateVisibility(addressTextShadow, shadowRad > 0);
        boolean update = turnDrawable.setTurnType(type[0]);

        int h = addressText.getHeight() / 4 * 3;
        if (h != turnDrawable.getBounds().bottom) {
          turnDrawable.setBounds(0, 0, h, h);
        }
        if (update) {
          if (type[0] != null) {
            addressTextShadow.setCompoundDrawables(turnDrawable, null, null, null);
            addressTextShadow.setCompoundDrawablePadding(4);
            addressText.setCompoundDrawables(turnDrawable, null, null, null);
            addressText.setCompoundDrawablePadding(4);
          } else {
            addressTextShadow.setCompoundDrawables(null, null, null, null);
            addressText.setCompoundDrawables(null, null, null, null);
          }
        }
        if (!text.equals(addressText.getText().toString())) {
          if (!text.equals("")) {
            topBar.setContentDescription(text);
          } else {
            topBar.setContentDescription(
                map.getResources().getString(R.string.map_widget_top_text));
          }
          addressTextShadow.setText(text);
          addressText.setText(text);
          return true;
        }
      }
      return false;
    }
 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;
 }