add pr fixes,

add AidlCallbackListener documentation
This commit is contained in:
madwasp79 2019-04-19 10:24:53 +03:00
parent 2ae02121c7
commit 055c403f14
3 changed files with 47 additions and 29 deletions

View file

@ -3,7 +3,35 @@ package net.osmand.aidl;
import java.util.Map;
public interface AidlCallbackListener {
/**
* Add AidlCallbackListener to OsmandAidlService's map of listeners. Key is unique to each AIDL
* method that wants to register callback and used to access only "own" callbacks.
*
* @param callback
* @param key - every AIDL method which uses that register callbacks in service need to use its own bit key
* 1 - key for registerForUpdates(...)
* 2 - key for registerForNavigationUpdates(...)
* 4 - key for onContextMenuButtonClicked(...)
* 8 - key for... future use
* 16 - key for... future use
* @return long - unique id of callback. Could be used for unregistering callback
*/
long addAidlCallback(IOsmAndAidlCallback callback, int key);
/**
* Unregister AidlCallbackListener from OsmandAidlService's map
*
* @param id - unique id of callback
* @return - true if callback successfully unregistered
*/
boolean removeAidlCallback(long id);
/**
*
* @return map of all callbacks. AidlCallbackParams contains method key and callback.
*/
Map<Long, OsmandAidlService.AidlCallbackParams> getAidlCallbacks();
}

View file

@ -25,8 +25,6 @@ import android.text.TextUtils;
import android.view.View;
import android.widget.ArrayAdapter;
import java.util.HashMap;
import java.util.Map.Entry;
import net.osmand.CallbackWithObject;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
@ -1961,11 +1959,11 @@ public class OsmandAidlApi {
}
};
navUpdateCallbacks.put(id, listener);
app.getRoutingHelper().addDataUpdateListener(listener);
app.getRoutingHelper().addRouteDataListener(listener);
}
public void unregisterFromUpdates(long id) {
app.getRoutingHelper().removeDataUpdateListener(navUpdateCallbacks.get(id));
app.getRoutingHelper().removeRouteDataListener(navUpdateCallbacks.get(id));
navUpdateCallbacks.remove(id);
}

View file

@ -30,7 +30,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import static net.osmand.plus.notifications.OsmandNotification.NotificationType.NAVIGATION;
@ -267,31 +266,29 @@ public class RoutingHelper {
transportRoutingHelper.addListener(l);
}
public void addDataUpdateListener(IRoutingDataUpdateListener listener) {
List<WeakReference<IRoutingDataUpdateListener>> copyList = new ArrayList<>(updateListeners);
Iterator<WeakReference<IRoutingDataUpdateListener>> it = copyList.iterator();
while (it.hasNext()) {
WeakReference<IRoutingDataUpdateListener> ref = it.next();
IRoutingDataUpdateListener l = ref.get();
if (l == null) {
it.remove();
}
}
copyList.add(new WeakReference<>(listener));
updateListeners = copyList;
public void addRouteDataListener(IRoutingDataUpdateListener listener) {
updateListeners = updateListenersList(new ArrayList<>(updateListeners), listener, true);
}
public void removeDataUpdateListener(IRoutingDataUpdateListener listener) {
List<WeakReference<IRoutingDataUpdateListener>> copyList = new ArrayList<>(updateListeners);
public void removeRouteDataListener(IRoutingDataUpdateListener listener) {
updateListeners = updateListenersList(new ArrayList<>(updateListeners), listener, false);
}
private List<WeakReference<IRoutingDataUpdateListener>> updateListenersList(
List<WeakReference<IRoutingDataUpdateListener>> copyList,
IRoutingDataUpdateListener listener, boolean isNewListener) {
Iterator<WeakReference<IRoutingDataUpdateListener>> it = copyList.iterator();
while (it.hasNext()) {
WeakReference<IRoutingDataUpdateListener> ref = it.next();
IRoutingDataUpdateListener l = ref.get();
if (l == null || l == listener) {
if (l == null || (l == listener)) {
it.remove();
}
}
updateListeners = copyList;
if (isNewListener) {
copyList.add(new WeakReference<>(listener));
}
return copyList;
}
public boolean removeListener(IRouteInformationListener lt){
@ -533,16 +530,11 @@ public class RoutingHelper {
app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION);
if (!updateListeners.isEmpty()) {
ArrayList<WeakReference<IRoutingDataUpdateListener>> tmp = new ArrayList<>(updateListeners);
Iterator<WeakReference<IRoutingDataUpdateListener>> it = tmp.iterator();
while (it.hasNext()) {
WeakReference<IRoutingDataUpdateListener> ref = it.next();
for (WeakReference<IRoutingDataUpdateListener> ref : tmp) {
IRoutingDataUpdateListener l = ref.get();
if (l == null) {
it.remove();
} else {
if (l != null) {
l.onRoutingDataUpdate();
}
updateListeners = tmp;
}
}
} else {