예제 #1
0
  public static double calculateRoundedDist(double distInMeters, Context ctx) {
    OsmandSettings settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
    MetricsConstants mc = settings.METRIC_SYSTEM.get();
    double mainUnitInMeter = 1;
    double metersInSecondUnit = METERS_IN_KILOMETER;
    if (mc == MetricsConstants.MILES_AND_FOOTS) {
      mainUnitInMeter = FOOTS_IN_ONE_METER;
      metersInSecondUnit = METERS_IN_ONE_MILE;
    } else if (mc == MetricsConstants.MILES_AND_YARDS) {
      mainUnitInMeter = YARDS_IN_ONE_METER;
      metersInSecondUnit = METERS_IN_ONE_MILE;
    }
    // 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 ...

    int generator = 1;
    byte pointer = 1;
    double point = mainUnitInMeter;
    while (distInMeters * point > generator) {
      if (pointer++ % 3 == 2) {
        generator = generator * 5 / 2;
      } else {
        generator *= 2;
      }
      if (point == mainUnitInMeter && metersInSecondUnit * mainUnitInMeter * 0.9f <= generator) {
        point = 1 / metersInSecondUnit;
        generator = 1;
        pointer = 1;
      }
    }

    return (generator / point);
  }
예제 #2
0
 public static String getFormattedAlt(double alt, Context ctx) {
   OsmandSettings settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
   MetricsConstants mc = settings.METRIC_SYSTEM.get();
   if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
     return ((int) alt) + " " + ctx.getString(R.string.m);
   } else {
     return ((int) (alt * FOOTS_IN_ONE_METER)) + " " + ctx.getString(R.string.foot);
   }
 }
예제 #3
0
 public static String getFormattedSpeed(float metersperseconds, Context ctx) {
   OsmandSettings settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
   MetricsConstants mc = settings.METRIC_SYSTEM.get();
   float kmh = metersperseconds * 3.6f;
   if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
     return ((int) kmh) + " " + ctx.getString(R.string.km_h);
   } else {
     float mph = kmh * METERS_IN_KILOMETER / METERS_IN_ONE_MILE;
     if (mph >= 10) {
       return ((int) (mph)) + " " + ctx.getString(R.string.mile_per_hour);
     } else {
       mph = ((int) mph * 10f) / 10f;
       return mph + " " + ctx.getString(R.string.mile_per_hour);
     }
   }
 }
예제 #4
0
  public static String getFormattedDistance(float meters, Context ctx) {
    OsmandSettings settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
    MetricsConstants mc = settings.METRIC_SYSTEM.get();
    int mainUnitStr;
    float mainUnitInMeters;
    if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
      mainUnitStr = R.string.km;
      mainUnitInMeters = METERS_IN_KILOMETER;
    } else {
      mainUnitStr = R.string.mile;
      mainUnitInMeters = METERS_IN_ONE_MILE;
    }

    if (meters >= 100 * mainUnitInMeters) {
      return (int) (meters / mainUnitInMeters) + " " + ctx.getString(mainUnitStr); // $NON-NLS-1$
    } else if (meters > 9.99f * mainUnitInMeters) {
      return MessageFormat.format(
          "{0,number,#.#} " + ctx.getString(mainUnitStr),
          ((float) meters) / mainUnitInMeters); // $NON-NLS-1$
    } else if (meters > 0.999f * mainUnitInMeters) {
      return MessageFormat.format(
          "{0,number,#.##} " + ctx.getString(mainUnitStr),
          ((float) meters) / mainUnitInMeters); // $NON-NLS-1$
    } else {
      if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
        return ((int) meters) + " " + ctx.getString(R.string.m); // $NON-NLS-1$
      } else if (mc == MetricsConstants.MILES_AND_FOOTS) {
        int foots = (int) (meters * FOOTS_IN_ONE_METER);
        return foots + " " + ctx.getString(R.string.foot); // $NON-NLS-1$
      } else if (mc == MetricsConstants.MILES_AND_YARDS) {
        int yards = (int) (meters * YARDS_IN_ONE_METER);
        return yards + " " + ctx.getString(R.string.yard); // $NON-NLS-1$
      }
      return ((int) meters) + " " + ctx.getString(R.string.m); // $NON-NLS-1$
    }
  }
예제 #5
0
  private void createUI() {
    addPreferencesFromResource(R.xml.navigation_settings);
    PreferenceScreen screen = getPreferenceScreen();
    settings = getMyApplication().getSettings();
    routerServicePreference =
        (ListPreference) screen.findPreference(settings.ROUTER_SERVICE.getId());

    RouteService[] vls = RouteService.getAvailableRouters(getMyApplication());
    String[] entries = new String[vls.length];
    for (int i = 0; i < entries.length; i++) {
      entries[i] = vls[i].getName();
    }
    registerListPreference(settings.ROUTER_SERVICE, screen, entries, vls);

    registerBooleanPreference(settings.SNAP_TO_ROAD, screen);

    Integer[] intValues = new Integer[] {0, 5, 10, 15, 20, 25, 30, 45, 60, 90};
    entries = new String[intValues.length];
    entries[0] = getString(R.string.shared_string_never);
    for (int i = 1; i < intValues.length; i++) {
      entries[i] = (int) intValues[i] + " " + getString(R.string.int_seconds);
    }
    registerListPreference(settings.AUTO_FOLLOW_ROUTE, screen, entries, intValues);

    entries = new String[AutoZoomMap.values().length];
    for (int i = 0; i < entries.length; i++) {
      entries[i] = getString(AutoZoomMap.values()[i].name);
    }
    registerListPreference(settings.AUTO_ZOOM_MAP, screen, entries, AutoZoomMap.values());

    // keep informing option:
    Integer[] keepInformingValues = new Integer[] {0, 1, 2, 3, 5, 7, 10, 15, 20, 25, 30};
    String[] keepInformingNames = new String[keepInformingValues.length];
    keepInformingNames[0] = getString(R.string.keep_informing_never);
    for (int i = 1; i < keepInformingValues.length; i++) {
      keepInformingNames[i] = keepInformingValues[i] + " " + getString(R.string.int_min);
    }
    registerListPreference(
        settings.KEEP_INFORMING, screen, keepInformingNames, keepInformingValues);

    SpeedConstants[] speedValues = SpeedConstants.values();
    String[] speedNamesVls = new String[speedValues.length];
    for (int i = 0; i < speedValues.length; i++) {
      speedNamesVls[i] = speedValues[i].toHumanString(this);
    }
    ;
    registerListPreference(settings.SPEED_SYSTEM, screen, speedNamesVls, speedValues);

    // screen power save option:
    Integer[] screenPowerSaveValues = new Integer[] {0, 5, 10, 15, 20, 30, 45, 60};
    String[] screenPowerSaveNames = new String[screenPowerSaveValues.length];
    screenPowerSaveNames[0] = getString(R.string.shared_string_never);
    for (int i = 1; i < screenPowerSaveValues.length; i++) {
      screenPowerSaveNames[i] = screenPowerSaveValues[i] + " " + getString(R.string.int_seconds);
    }
    registerListPreference(
        settings.WAKE_ON_VOICE_INT, screen, screenPowerSaveNames, screenPowerSaveValues);

    //         registerBooleanPreference(settings.SHOW_ZOOM_BUTTONS_NAVIGATION, screen);

    autoZoomMapPreference = (ListPreference) screen.findPreference(settings.AUTO_ZOOM_MAP.getId());
    autoZoomMapPreference.setOnPreferenceChangeListener(this);

    showAlarms = (Preference) screen.findPreference("show_routing_alarms");
    showAlarms.setOnPreferenceClickListener(this);

    speakAlarms = (Preference) screen.findPreference("speak_routing_alarms");
    speakAlarms.setOnPreferenceClickListener(this);

    Float[] arrivalValues = new Float[] {1.5f, 1f, 0.5f, 0.25f};
    String[] arrivalNames =
        new String[] {
          getString(R.string.arrival_distance_factor_early),
          getString(R.string.arrival_distance_factor_normally),
          getString(R.string.arrival_distance_factor_late),
          getString(R.string.arrival_distance_factor_at_last)
        };
    registerListPreference(settings.ARRIVAL_DISTANCE_FACTOR, screen, arrivalNames, arrivalValues);

    // array size should be equal!
    Float[] speedLimitsKm = new Float[] {0f, 5f, 7f, 10f, 15f, 20f};
    Float[] speedLimitsMiles = new Float[] {0f, 3f, 5f, 7f, 10f, 15f};
    if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
      String[] speedNames = new String[speedLimitsKm.length];
      for (int i = 0; i < speedLimitsKm.length; i++) {
        speedNames[i] = speedLimitsKm[i] + " " + getString(R.string.km_h);
      }
      registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm);
    } else {
      String[] speedNames = new String[speedLimitsKm.length];
      for (int i = 0; i < speedNames.length; i++) {
        speedNames[i] = speedLimitsMiles[i] + " " + getString(R.string.mile_per_hour);
      }
      registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm);
    }

    PreferenceCategory category =
        (PreferenceCategory) screen.findPreference("guidance_preferences");
    speedLimitExceed = (ListPreference) category.findPreference("speed_limit_exceed");
    ApplicationMode mode = getMyApplication().getSettings().getApplicationMode();
    if (!mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
      category.removePreference(speedLimitExceed);
    }

    // deprecated 2.2
    //		Integer[] delayIntervals = new Integer[] { -1, 3, 5, 7, 10, 15, 20 };
    //		String[] delayIntervalNames = new String[delayIntervals.length];
    //		for (int i = 0; i < delayIntervals.length; i++) {
    //			if (i == 0) {
    //				delayIntervalNames[i] = getString(R.string.auto_follow_route_never);
    //			} else {
    //				delayIntervalNames[i] = delayIntervals[i] + " " + getString(R.string.int_seconds);
    //			}
    //		}
    // registerListPreference(settings.DELAY_TO_START_NAVIGATION, screen, delayIntervalNames,
    // delayIntervals);

    if (getIntent() != null && getIntent().hasExtra(INTENT_SKIP_DIALOG)) {
      setSelectedAppMode(settings.getApplicationMode());
    } else {
      profileDialog();
    }
  }
 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;
 }