mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-14 16:20:57 +00:00
Merge branch 'ribdashboard_compassfix' into ribdashboard
This commit is contained in:
commit
2969f0a9ff
5 files changed
+105
-3
No files matched your search
+67
@@ -0,0 +1,67 @@
|
||||
package com.sap.sailing.dashboards.gwt.client.device;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Ries (D062114)
|
||||
*
|
||||
*/
|
||||
public class Orientation {
|
||||
|
||||
private static Orientation INSTANCE = null;
|
||||
private List<OrientationListener> orientationListeners;
|
||||
|
||||
private Orientation() {
|
||||
initOrientationEventListener(this);
|
||||
}
|
||||
|
||||
public static Orientation getInstance() {
|
||||
synchronized (Orientation.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new Orientation();
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private static native void initOrientationEventListener(Orientation orientationFetcher) /*-{
|
||||
window.onorientationchange = function() {
|
||||
var orientationDegrees = window.orientation;
|
||||
orientationFetcher.@com.sap.sailing.dashboards.gwt.client.device.Orientation::receivedOrientationDegreesChange(I)(orientationDegrees);
|
||||
};
|
||||
}-*/;
|
||||
|
||||
private void receivedOrientationDegreesChange(int orientationDegrees) {
|
||||
notifiyListenerAboutHeadingChange(orientationDegrees);
|
||||
}
|
||||
|
||||
private static native void readDeviceOrientation(Orientation orientationFetcher) /*-{
|
||||
var orientationDegrees = window.orientation;
|
||||
orientationFetcher.@com.sap.sailing.dashboards.gwt.client.device.Orientation::receivedOrientationDegreesChange(I)(orientationDegrees);
|
||||
}-*/;
|
||||
|
||||
public void triggerDeviceOrientationRead() {
|
||||
readDeviceOrientation(this);
|
||||
}
|
||||
|
||||
public void addListener(OrientationListener orientationListener) {
|
||||
if (orientationListeners == null) {
|
||||
orientationListeners = new ArrayList<OrientationListener>();
|
||||
}
|
||||
orientationListeners.add(orientationListener);
|
||||
}
|
||||
|
||||
public void removeListener(OrientationListener orientationListener) {
|
||||
if (orientationListeners != null) {
|
||||
orientationListeners.remove(orientationListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void notifiyListenerAboutHeadingChange(double orientationHeading) {
|
||||
for (OrientationListener orientationListener : orientationListeners) {
|
||||
orientationListener.orientationChanged(orientationHeading);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.sap.sailing.dashboards.gwt.client.device;
|
||||
|
||||
public interface OrientationListener {
|
||||
|
||||
public void orientationChanged(double orientationHeading);
|
||||
}
|
||||
+11
-1
@@ -1,6 +1,7 @@
|
||||
package com.sap.sailing.dashboards.gwt.client.windchart.compass;
|
||||
|
||||
import com.google.gwt.i18n.client.NumberFormat;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.ui.AbsolutePanel;
|
||||
import com.google.gwt.user.client.ui.HasWidgets;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
@@ -20,6 +21,8 @@ import com.sap.sailing.domain.common.dto.PositionDTO;
|
||||
public class LocationPointerCompass extends AbsolutePanel implements HasWidgets,
|
||||
LocationPointerCompassAngleDistanceListener {
|
||||
|
||||
private double angleOffset;
|
||||
|
||||
private Image compassNeedle;
|
||||
|
||||
/**
|
||||
@@ -46,6 +49,7 @@ public class LocationPointerCompass extends AbsolutePanel implements HasWidgets,
|
||||
initDistanceToPointedLocationLabel();
|
||||
locationPointerCompassAngleDistance = new LocationPointerCompassAngleDistance();
|
||||
locationPointerCompassAngleDistance.addListener(this);
|
||||
locationPointerCompassAngleDistance.triggerOrientationRead();
|
||||
}
|
||||
|
||||
private void initCompassNeedle() {
|
||||
@@ -71,7 +75,7 @@ public class LocationPointerCompass extends AbsolutePanel implements HasWidgets,
|
||||
private void updateNeedleAngle(double newDirection) {
|
||||
// Adapt degrees to image angle
|
||||
synchronized (this) {
|
||||
String winddirectionformatted = NumberFormat.getFormat("#0").format(newDirection);
|
||||
String winddirectionformatted = NumberFormat.getFormat("#0").format(newDirection-angleOffset);
|
||||
compassNeedle.getElement().getStyle().setProperty("transform", "rotate(" + winddirectionformatted + "deg)");
|
||||
compassNeedle.getElement().getStyle()
|
||||
.setProperty("webkitTransform", "rotate(" + winddirectionformatted + "deg)");
|
||||
@@ -98,4 +102,10 @@ public class LocationPointerCompass extends AbsolutePanel implements HasWidgets,
|
||||
updateNeedleAngle(angle);
|
||||
updateDistanceToPointedLocationLabel(distance, angle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngleOffset(double offset) {
|
||||
angleOffset = offset;
|
||||
Window.alert("Orientation Changed: "+offset);
|
||||
}
|
||||
}
|
||||
+19
-1
@@ -7,6 +7,8 @@ import com.sap.sailing.dashboards.gwt.client.device.Compass;
|
||||
import com.sap.sailing.dashboards.gwt.client.device.CompassListener;
|
||||
import com.sap.sailing.dashboards.gwt.client.device.Location;
|
||||
import com.sap.sailing.dashboards.gwt.client.device.LocationListener;
|
||||
import com.sap.sailing.dashboards.gwt.client.device.Orientation;
|
||||
import com.sap.sailing.dashboards.gwt.client.device.OrientationListener;
|
||||
import com.sap.sailing.domain.common.dto.PositionDTO;
|
||||
|
||||
/**
|
||||
@@ -18,7 +20,7 @@ import com.sap.sailing.domain.common.dto.PositionDTO;
|
||||
* @author Alexander Ries (D062114)
|
||||
*
|
||||
*/
|
||||
public class LocationPointerCompassAngleDistance implements LocationListener, CompassListener {
|
||||
public class LocationPointerCompassAngleDistance implements LocationListener, CompassListener, OrientationListener {
|
||||
|
||||
private List<LocationPointerCompassAngleDistanceListener> listeners;
|
||||
private double latDevice;
|
||||
@@ -38,6 +40,11 @@ public class LocationPointerCompassAngleDistance implements LocationListener, Co
|
||||
listeners = new ArrayList<LocationPointerCompassAngleDistanceListener>();
|
||||
Compass.getInstance().addListener(this);
|
||||
Location.getInstance().addListener(this);
|
||||
Orientation.getInstance().addListener(this);
|
||||
}
|
||||
|
||||
public void triggerOrientationRead(){
|
||||
Orientation.getInstance().triggerDeviceOrientationRead();
|
||||
}
|
||||
|
||||
private double getAngleBetweenGPSPoints(double lat1, double lng1, double lat2, double lng2) {
|
||||
@@ -116,4 +123,15 @@ public class LocationPointerCompassAngleDistance implements LocationListener, Co
|
||||
lonBot = positionDTO.lngDeg;
|
||||
calulateNewAngleAndDistance();
|
||||
}
|
||||
|
||||
private void setAngleOffsetAtListeners(double offset) {
|
||||
for (LocationPointerCompassAngleDistanceListener listener : listeners) {
|
||||
listener.setAngleOffset(offset);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void orientationChanged(double orintationHeading) {
|
||||
setAngleOffsetAtListeners(orintationHeading);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
package com.sap.sailing.dashboards.gwt.client.windchart.compass;
|
||||
|
||||
public interface LocationPointerCompassAngleDistanceListener {
|
||||
|
||||
|
||||
public void angleChanged(double angle);
|
||||
public void angleAndDistanceChanged(double angle, double distance);
|
||||
public void setAngleOffset(double offset);
|
||||
}
|
||||
Reference in new issue
Block a user