gt:         if (passiveFirst > -1) {
context: package eu.ttbox.osm.ui.map.mylocation.sensor.v2;
  
  
  import android.app.Application;
  import android.content.Context;
  import android.hardware.GeomagneticField;
  import android.hardware.Sensor;
  import android.hardware.SensorEvent;
  import android.hardware.SensorEventListener;
  import android.hardware.SensorManager;
  import android.location.GpsSatellite;
  import android.location.GpsStatus;
  import android.location.Location;
  import android.location.LocationListener;
  import android.location.LocationManager;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Display;
  import android.view.Surface;
  import android.view.WindowManager;
  
  import org.osmdroid.util.GeoPoint;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Iterator;
  import java.util.List;
  import java.util.concurrent.CopyOnWriteArrayList;
  import java.util.concurrent.atomic.AtomicBoolean;
  
  import eu.ttbox.osm.core.LocationUtils;
  import eu.ttbox.osm.ui.map.core.MapViewUtils;
  
  public class OsmAndLocationProvider implements SensorEventListener {
  
      private static String TAG = "OsmAndLocationProvider";
  
      public interface OsmAndLocationListener {
          void onLocationChanged( OsmLocation location);
      }
  
      public interface OsmAndCompassListener {
          void updateCompassValue(float value);
      }
  
  
      private static final int INTERVAL_TO_CLEAR_SET_LOCATION = 30 * 1000;
      private static final int LOST_LOCATION_MSG_ID = 10;
      private static final long LOST_LOCATION_CHECK_DELAY = 18000;
  
      private static final float ACCURACY_FOR_GPX_AND_ROUTING = 50;
  
      private static final int GPS_TIMEOUT_REQUEST = 0;
      private static final int GPS_DIST_REQUEST = 0;
      private static final int NOT_SWITCH_TO_NETWORK_WHEN_GPS_LOST_MS = 12000;
  
      private long lastTimeGPSLocationFixed = 0;
  
      private boolean sensorRegistered = false;
      private float[] mGravs = new float[3];
      private float[] mGeoMags = new float[3];
      private float previousCorrectionValue = 360;
  
  
  
      private final boolean USE_KALMAN_FILTER = true;
      private final float KALMAN_COEFFICIENT = 0.04f;
  
      float avgValSin = 0;
      float avgValCos = 0;
      float lastValSin = 0;
      float lastValCos = 0;
      private float[] previousCompassValuesA = new float[50];
      private float[] previousCompassValuesB = new float[50];
      private int previousCompassIndA = 0;
      private int previousCompassIndB = 0;
      private boolean inUpdateValue = false;
  
      private Float heading = null;
  
      // Current screen orientation
      // Screen
      private final Display mDisplay;
    //  private int currentScreenOrientation;
  
      private Application app;
  
  
    //  private NavigationInfo navigationInfo;
    //  private CurrentPositionHelper currentPositionHelper;
    //  private OsmAndLocationSimulation locationSimulation;
  
      private  OsmLocation location = null;
  
      private GPSInfo gpsInfo = new GPSInfo();
  
      private List<OsmAndLocationListener> locationListeners = new CopyOnWriteArrayList<OsmAndLocationListener>();
      private List<OsmAndCompassListener> compassListeners = new CopyOnWriteArrayList<OsmAndCompassListener>();
      private GpsStatus.Listener gpsStatusListener;
      private float[] mRotationM =  new float[9];
  
      // Config
      private AtomicBoolean USE_MAGNETIC_FIELD_SENSOR_COMPASS;
      private AtomicBoolean USE_FILTER_FOR_COMPASS;
  
      //Status
      private AtomicBoolean isLocationEnable = new AtomicBoolean(false);
  
  
      // ===========================================================
      // Constructor
      // ===========================================================
  
      public OsmAndLocationProvider( Application ctx) {
          this.app = ctx;
         // navigationInfo = new NavigationInfo(app);
  
          USE_FILTER_FOR_COMPASS = new AtomicBoolean(true);
          USE_MAGNETIC_FIELD_SENSOR_COMPASS = isUseMagneticFieldSensorCompass();
         // currentPositionHelper = new CurrentPositionHelper(app);
         // locationSimulation = new OsmAndLocationSimulation(app, this);
          // Service
          // Screen
          final WindowManager windowManager = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
          mDisplay = windowManager.getDefaultDisplay();
      }
  
      private AtomicBoolean isUseMagneticFieldSensorCompass() {
          SensorManager sensorMgr = (SensorManager) app.getSystemService(Context.SENSOR_SERVICE);
          Sensor s = sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
          if (s != null ) {
              return new AtomicBoolean(true);
          }
          s = sensorMgr.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
          if (s != null ) {
              return new AtomicBoolean(true);
          }
          return new AtomicBoolean(false);
      }
  
  
      // ===========================================================
      // Life Cycle
      // ===========================================================
  
      public void resumeAllUpdates() {
          isLocationEnable.set(true);
  
          final LocationManager service = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE);
          service.addGpsStatusListener(getGpsStatusListener(service));
          try {
              service.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, gpsListener);
          } catch (IllegalArgumentException e) {
              Log.d(TAG, "GPS location provider not available"); //$NON-NLS-1$
          }
          // try to always ask for network provide : it is faster way to find location
          try {
              service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, networkListener);
          } catch (IllegalArgumentException e) {
              Log.d(TAG, "Network location provider not available"); //$NON-NLS-1$
          }
      }
  
      private void stopLocationRequests() {
          isLocationEnable.set(false);
          LocationManager service = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE);
          service.removeGpsStatusListener(gpsStatusListener);
          service.removeUpdates(gpsListener);
          service.removeUpdates(networkListener);
      }
  
      public void pauseAllUpdates() {
          stopLocationRequests();
          SensorManager sensorMgr = (SensorManager) app.getSystemService(Context.SENSOR_SERVICE);
          sensorMgr.unregisterListener(this);
          sensorRegistered = false;
      }
  
  
  
  
  
      // ===========================================================
      // Accessor
      // ===========================================================
  
      public GPSInfo getGPSInfo(){
          return gpsInfo;
      }
  
  //    public void updateScreenOrientation(int orientation) {
  //        currentScreenOrientation = orientation;
  //    }
  
      public void addLocationListener(OsmAndLocationListener listener){
          if(!locationListeners.contains(listener)) {
              locationListeners.add(listener);
          }
      }
  
      public void removeLocationListener(OsmAndLocationListener listener){
          locationListeners.remove(listener);
      }
  
      public void addCompassListener(OsmAndCompassListener listener){
          if(!compassListeners.contains(listener)) {
              compassListeners.add(listener);
          }
      }
  
      public void removeCompassListener(OsmAndCompassListener listener){
          compassListeners.remove(listener);
      }
  
      public OsmLocation getFirstTimeRunDefaultLocation() {
          LocationManager service = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE);
          List<String> providers = new ArrayList<String>(service.getProviders(true));
          // note, passive provider is from API_LEVEL 8 but it is a constant, we can check for it.
          // constant should not be changed in future
          int passiveFirst = providers.indexOf("passive"); // LocationManager.PASSIVE_PROVIDER
          // put passive provider to first place
  