Skip to content

Commit

Permalink
fix compass crash (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Apr 9, 2017
1 parent 28d1373 commit 63a4167
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface Listener
void onRotationChanged(float rotation);
}

public CompassComponent(Listener listener)
public void setListener(Listener listener)
{
this.listener = listener;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ else if(currentRotation != targetRotation)
if(deltaTime > DURATION) currentRotation = targetRotation;
else currentRotation += deltaRotation * deltaTime / DURATION;
}
listener.onRotationChanged(currentRotation);
if(listener != null) listener.onRotationChanged(currentRotation);
lastTime = System.currentTimeMillis();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class MapFragment extends Fragment implements
TouchInput.ShoveResponder, TouchInput.RotateResponder,
TouchInput.PanResponder, TouchInput.DoubleTapResponder, CompassComponent.Listener
{
private CompassComponent compass = new CompassComponent(this);
private CompassComponent compass = new CompassComponent();

private Marker locationMarker;
private Marker accuracyMarker;
Expand Down Expand Up @@ -134,6 +134,8 @@ protected void initMap()
accuracyMarker.setDrawable(createBitmapDrawableFrom(R.drawable.accuracy_circle));
accuracyMarker.setDrawOrder(1);

compass.setListener(this);

showLocation();
followPosition();

Expand Down Expand Up @@ -461,6 +463,7 @@ private void saveCameraState()
@Override public void onDestroy()
{
super.onDestroy();
compass.setListener(null);
if(mapView != null) mapView.onDestroy();
}

Expand Down

0 comments on commit 63a4167

Please sign in to comment.