aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/notification
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-08-24 10:46:48 +0500
committerAbyss777 <abyss@fox5.ru>2016-08-24 10:46:48 +0500
commitd2e89a2c1aa8f787bc0a296f588295ad1a5f76f2 (patch)
treebe2823cbaa7084d6ee5689ff7b0e3f9f232eb239 /src/org/traccar/notification
parentea0bdea88003f46fd6f6164d5c45e33d53f47c81 (diff)
downloadtrackermap-server-d2e89a2c1aa8f787bc0a296f588295ad1a5f76f2.tar.gz
trackermap-server-d2e89a2c1aa8f787bc0a296f588295ad1a5f76f2.tar.bz2
trackermap-server-d2e89a2c1aa8f787bc0a296f588295ad1a5f76f2.zip
- Added speed converting in NotificationFormatter
- Used constants in UnitsConverter
Diffstat (limited to 'src/org/traccar/notification')
-rw-r--r--src/org/traccar/notification/NotificationFormatter.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java
index 1d5257b4f..fb8019900 100644
--- a/src/org/traccar/notification/NotificationFormatter.java
+++ b/src/org/traccar/notification/NotificationFormatter.java
@@ -15,10 +15,12 @@
*/
package org.traccar.notification;
+import java.text.DecimalFormat;
import java.util.Formatter;
import java.util.Locale;
import org.traccar.Context;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -55,7 +57,7 @@ public final class NotificationFormatter {
public static final String TITLE_TEMPLATE_TYPE_DEVICE_OVERSPEED = "%1$s: exceeds the speed";
public static final String MESSAGE_TEMPLATE_TYPE_DEVICE_OVERSPEED = "Device: %1$s%n"
- + "Exceeds the speed: %5$f%n"
+ + "Exceeds the speed: %5$s%n"
+ "Point: http://www.openstreetmap.org/?mlat=%3$f&mlon=%4$f#map=16/%3$f/%4$f%n"
+ "Time: %2$tc%n";
@@ -161,7 +163,7 @@ public final class NotificationFormatter {
break;
case Event.TYPE_DEVICE_OVERSPEED:
formatter.format(MESSAGE_TEMPLATE_TYPE_DEVICE_OVERSPEED, device.getName(), position.getFixTime(),
- position.getLatitude(), position.getLongitude(), position.getSpeed());
+ position.getLatitude(), position.getLongitude(), formatSpeed(userId, position.getSpeed()));
break;
case Event.TYPE_GEOFENCE_ENTER:
formatter.format(MESSAGE_TEMPLATE_TYPE_GEOFENCE_ENTER, device.getName(), position.getFixTime(),
@@ -194,4 +196,20 @@ public final class NotificationFormatter {
formatter.close();
return result;
}
+
+ private static String formatSpeed(long userId, double speed) {
+ DecimalFormat df = new DecimalFormat("#.##");
+ String result = df.format(speed) + " kn";
+ switch (Context.getPermissionsManager().getUser(userId).getSpeedUnit()) {
+ case "kmh":
+ result = df.format(UnitsConverter.kphFromKnots(speed)) + " km/h";
+ break;
+ case "mph":
+ result = df.format(UnitsConverter.mphFromKnots(speed)) + " mph";
+ break;
+ default:
+ break;
+ }
+ return result;
+ }
}