add option to remove of inner callback from RoutingHelper if no aidl callbacks registered.
This commit is contained in:
parent
44885666e1
commit
cf10d7394b
2 changed files with 19 additions and 14 deletions
|
@ -26,6 +26,7 @@ import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import net.osmand.CallbackWithObject;
|
import net.osmand.CallbackWithObject;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
@ -1930,10 +1931,13 @@ public class OsmandAidlApi {
|
||||||
if (params.isSubscribeToUpdates()) {
|
if (params.isSubscribeToUpdates()) {
|
||||||
updateCallbackId++;
|
updateCallbackId++;
|
||||||
callbacks.put(updateCallbackId, callback);
|
callbacks.put(updateCallbackId, callback);
|
||||||
startNavigationalUpdates(updateCallbackId);
|
startNavigationalUpdates();
|
||||||
return updateCallbackId;
|
return updateCallbackId;
|
||||||
} else {
|
} else {
|
||||||
callbacks.remove(params.getCallbackId());
|
callbacks.remove(params.getCallbackId());
|
||||||
|
if (callbacks.size() == 0) {
|
||||||
|
navUpdateListener = null;
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1944,14 +1948,14 @@ public class OsmandAidlApi {
|
||||||
return callbacks.size() > 0;
|
return callbacks.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startNavigationalUpdates(final long updateCallbackId) {
|
private void startNavigationalUpdates() {
|
||||||
final ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false);
|
final ADirectionInfo directionInfo = new ADirectionInfo(-1, -1, false);
|
||||||
final NextDirectionInfo baseNdi = new NextDirectionInfo();
|
final NextDirectionInfo baseNdi = new NextDirectionInfo();
|
||||||
|
if (navUpdateListener == null) {
|
||||||
navUpdateListener = new NavUpdateListener() {
|
navUpdateListener = new NavUpdateListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onNavUpdate() {
|
public void onNavUpdate() {
|
||||||
RoutingHelper rh = app.getRoutingHelper();
|
RoutingHelper rh = app.getRoutingHelper();
|
||||||
if (callbacks.containsKey(updateCallbackId)) {
|
|
||||||
if (rh.isDeviatedFromRoute()) {
|
if (rh.isDeviatedFromRoute()) {
|
||||||
directionInfo.setTurnType(TurnType.OFFR);
|
directionInfo.setTurnType(TurnType.OFFR);
|
||||||
directionInfo.setDistanceTo((int) rh.getRouteDeviation());
|
directionInfo.setDistanceTo((int) rh.getRouteDeviation());
|
||||||
|
@ -1962,8 +1966,9 @@ public class OsmandAidlApi {
|
||||||
directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue());
|
directionInfo.setTurnType(ndi.directionInfo.getTurnType().getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (Entry<Long, IOsmAndAidlCallback> cb : callbacks.entrySet()) {
|
||||||
try {
|
try {
|
||||||
callbacks.get(updateCallbackId).updateNavigationInfo(directionInfo);
|
cb.getValue().updateNavigationInfo(directionInfo);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.debug(e.getMessage(), e);
|
LOG.debug(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
@ -1971,6 +1976,7 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface NavUpdateListener {
|
public interface NavUpdateListener {
|
||||||
void onNavUpdate();
|
void onNavUpdate();
|
||||||
|
|
|
@ -11,7 +11,6 @@ import android.os.RemoteException;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.aidl.OsmandAidlApi.DirectionsUpdateCallback;
|
|
||||||
import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback;
|
import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback;
|
||||||
import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback;
|
import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback;
|
||||||
import net.osmand.aidl.OsmandAidlApi.SearchCompleteCallback;
|
import net.osmand.aidl.OsmandAidlApi.SearchCompleteCallback;
|
||||||
|
|
Loading…
Reference in a new issue