private void registerSimpleEventManagerAsListenerIfNotDoneJet( String provider, long minMsBeforUpdate, float minDistForUpdate) { if (gpslistener == null) { gpslistener = initListener(); Log.i(LOG_TAG, "Created location listener and now registering for updates.."); Log.i(LOG_TAG, " > provider=" + provider); Log.i(LOG_TAG, " > minMsBeforUpdate=" + minMsBeforUpdate); Log.i(LOG_TAG, " > minDistForUpdate=" + minDistForUpdate); getLocationManager() .requestLocationUpdates(provider, minMsBeforUpdate, minDistForUpdate, gpslistener); } if (stepListener == null) { stepListener = new OnStepListener() { @Override public void onStep(double compassAngle, double steplength) { if (!stepDetectionEnabled) { return; } Log.d(LOG_TAG, "Step detected"); Log.d(LOG_TAG, " > compassAngle=" + compassAngle); Log.d(LOG_TAG, " > distance=" + steplength); Location location = getCurrentBUfferedLocation(); if (location != null) { Log.i(LOG_TAG, "location.getAccuracy()=" + location.getAccuracy()); } if (location != null) { if (location.getAccuracy() < minimumAverageAccuracy) { for (int i = 0; i < numberOfSimulatedStepsInSameDirection; i++) { location = StepManager.newLocationOneStepFurther(location, steplength, compassAngle); onLocationEventFromSteps(location, myListeners); } } else { Log.w(LOG_TAG, "Location accuracy was to low, wont use step"); } } else { Log.w(LOG_TAG, "Current location was unknown, cant do steps"); } } }; if (stepManager == null) { stepManager = new StepManager(); } stepManager.registerStepListener(context, stepListener); Log.i(LOG_TAG, "Step listener registered"); } }
/** will pause updates from the {@link LocationManager} to the {@link SimpleLocationManager} */ public boolean pauseLocationManagerUpdates() { // its important to use instance here and not getInstance()! if (gpslistener != null) { Log.i(LOG_TAG, "Pausing position updates!"); getLocationManager().removeUpdates(gpslistener); gpslistener = null; } if (stepListener != null) { Log.i(LOG_TAG, "Pausing step updates!"); stepManager.unRegisterStepListener(stepListener); stepListener = null; stepManager = null; return true; } return false; }