示例#1
0
 public AlarmInfo calculateMostImportantAlarm(
     RouteDataObject ro, Location loc, MetricsConstants mc, boolean showCameras) {
   boolean direction = true;
   if (loc.hasBearing()) {
     double diff =
         MapUtils.alignAngleDifference(
             ro.directionRoute(0, true) - loc.getBearing() / (2 * Math.PI));
     direction = Math.abs(diff) < Math.PI;
   }
   float mxspeed = ro.getMaximumSpeed(direction);
   float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f;
   AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc, delta);
   if (speedAlarm != null) {
     getVoiceRouter().announceSpeedAlarm();
     return speedAlarm;
   }
   for (int i = 0; i < ro.getPointsLength(); i++) {
     int[] pointTypes = ro.getPointTypes(i);
     RouteRegion reg = ro.region;
     if (pointTypes != null) {
       for (int r = 0; r < pointTypes.length; r++) {
         RouteTypeRule typeRule = reg.quickGetEncodingRule(pointTypes[r]);
         AlarmInfo info = AlarmInfo.createAlarmInfo(typeRule, 0, loc);
         if (info != null) {
           if (info.getType() != AlarmInfoType.SPEED_CAMERA || showCameras) {
             long ms = System.currentTimeMillis();
             if (ms - announcedAlarmTime > 50 * 1000) {
               announcedAlarmTime = ms;
               getVoiceRouter().announceAlarm(info.getType());
             }
             return info;
           }
         }
       }
     }
   }
   return null;
 }
示例#2
0
 private void calculateAlarms(RouteCalculationResult route, List<LocationPointWrapper> array) {
   for (AlarmInfo i : route.getAlarmInfo()) {
     if (i.getType() == AlarmInfoType.SPEED_CAMERA) {
       if (app.getSettings().SHOW_CAMERAS.get() || app.getSettings().SPEAK_SPEED_CAMERA.get()) {
         LocationPointWrapper lw =
             new LocationPointWrapper(route, ALARMS, i, 0, i.getLocationIndex());
         lw.setAnnounce(app.getSettings().SPEAK_SPEED_CAMERA.get());
         array.add(lw);
       }
     } else {
       if (app.getSettings().SHOW_TRAFFIC_WARNINGS.get()
           || app.getSettings().SPEAK_TRAFFIC_WARNINGS.get()) {
         LocationPointWrapper lw =
             new LocationPointWrapper(route, ALARMS, i, 0, i.getLocationIndex());
         lw.setAnnounce(app.getSettings().SPEAK_TRAFFIC_WARNINGS.get());
         array.add(lw);
       }
     }
   }
 }
示例#3
0
 public AlarmInfo getMostImportantAlarm(MetricsConstants mc, boolean showCameras) {
   Location lastProjection = app.getRoutingHelper().getLastProjection();
   float mxspeed = route.getCurrentMaxSpeed();
   float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f;
   AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, lastProjection, delta);
   if (speedAlarm != null) {
     getVoiceRouter().announceSpeedAlarm();
   }
   AlarmInfo mostImportant = speedAlarm;
   int value =
       speedAlarm != null ? speedAlarm.updateDistanceAndGetPriority(0, 0) : Integer.MAX_VALUE;
   if (ALARMS < pointsProgress.size()) {
     int kIterator = pointsProgress.get(ALARMS);
     List<LocationPointWrapper> lp = locationPoints.get(ALARMS);
     while (kIterator < lp.size()) {
       LocationPointWrapper lwp = lp.get(kIterator);
       if (lp.get(kIterator).routeIndex < route.getCurrentRoute()) {
         // skip
       } else {
         int d = route.getDistanceToPoint(lwp.routeIndex);
         if (d > LONG_ANNOUNCE_RADIUS) {
           break;
         }
         AlarmInfo inf = (AlarmInfo) lwp.point;
         float speed =
             lastProjection != null && lastProjection.hasSpeed() ? lastProjection.getSpeed() : 0;
         float time = speed > 0 ? d / speed : Integer.MAX_VALUE;
         int vl = inf.updateDistanceAndGetPriority(time, d);
         if (vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)) {
           mostImportant = inf;
           value = vl;
         }
       }
       kIterator++;
     }
   }
   return mostImportant;
 }
 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;
 }