Пример #1
0
  private static String getDistance(Geopoint position, Geopoint target) {
    final float kilometers = position.distanceTo(target);

    if (Settings.isUseMetricUnits()) {
      return getDistance(
          kilometers,
          (int) (kilometers * 1000.0),
          5.0f,
          1.0f,
          50,
          R.plurals.tts_kilometers,
          R.string.tts_one_kilometer,
          R.plurals.tts_meters,
          R.string.tts_one_meter);
    }
    return getDistance(
        kilometers / IConversion.MILES_TO_KILOMETER,
        (int) (kilometers * 1000.0 * IConversion.METERS_TO_FEET),
        3.0f,
        0.2f,
        300,
        R.plurals.tts_miles,
        R.string.tts_one_mile,
        R.plurals.tts_feet,
        R.string.tts_one_foot);
  }
Пример #2
0
 private static void assertDistance(final String expected, final float distance) {
   final String actual = Units.getDistanceFromKilometers(distance);
   if (!StringUtils.equals(expected, actual.replace(',', '.'))) { // make 1.2 the same as 1,2
     fail(
         "getHumanDistance("
             + distance
             + ") [metric: "
             + (Settings.isUseMetricUnits() ? "yes" : "no")
             + "] fails to match "
             + expected
             + ": "
             + actual);
   }
 }
Пример #3
0
 // Make method non-static so that Settings is initialized
 @SuppressWarnings("static-method")
 public void testSpeed() {
   assertEquals("?", Units.getDistanceFromKilometers(null));
   final boolean savedMetrics = Settings.isUseMetricUnits();
   try {
     Settings.setUseMetricUnits(true);
     assertSpeed("123 km/h", 122.782f);
     assertSpeed("123 km/h", 123.456f);
     assertSpeed("12.3 km/h", 12.3456f);
     assertSpeed("1.23 km/h", 1.23456f);
     assertSpeed("123 m/h", 0.123456f);
     Settings.setUseMetricUnits(false);
     assertSpeed("76.7 mph", 123.456f);
     assertSpeed("7.67 mph", 12.3456f);
     assertSpeed("0.77 mph", 1.23456f);
   } finally {
     Settings.setUseMetricUnits(savedMetrics);
   }
 }
Пример #4
0
 // Make method non-static so that Settings is initialized
 @SuppressWarnings("static-method")
 public void testElevation() {
   final boolean savedMetrics = Settings.isUseMetricUnits();
   try {
     Settings.setUseMetricUnits(true);
     assertElevation("↥ 123 m", 122.782f);
     assertElevation("↥ 123 m", 123.456f);
     assertElevation("↥ 12 m", 12.3456f);
     assertElevation("↥ 1 m", 1.23456f);
     assertElevation("↥ 2 m", 1.6f);
     assertElevation("↥ 0 m", 0.123456f);
     assertElevation("↧ 123 m", -122.782f);
     assertElevation("↧ 123 m", -123.456f);
     assertElevation("↧ 12 m", -12.3456f);
     assertElevation("↧ 1 m", -1.23456f);
     assertElevation("↧ 2 m", -1.6f);
     assertElevation("↧ 0 m", -0.123456f);
     Settings.setUseMetricUnits(false);
     assertElevation("↥ 405 ft", 123.456f);
     assertElevation("↥ 41 ft", 12.3456f);
   } finally {
     Settings.setUseMetricUnits(savedMetrics);
   }
 }