add pr fixes,
add AidlCallbackListener documentation
This commit is contained in:
parent
2ae02121c7
commit
055c403f14
3 changed files with 47 additions and 29 deletions
|
@ -3,7 +3,35 @@ package net.osmand.aidl;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface AidlCallbackListener {
|
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);
|
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);
|
boolean removeAidlCallback(long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return map of all callbacks. AidlCallbackParams contains method key and callback.
|
||||||
|
*/
|
||||||
Map<Long, OsmandAidlService.AidlCallbackParams> getAidlCallbacks();
|
Map<Long, OsmandAidlService.AidlCallbackParams> getAidlCallbacks();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,6 @@ import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -1961,11 +1959,11 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
navUpdateCallbacks.put(id, listener);
|
navUpdateCallbacks.put(id, listener);
|
||||||
app.getRoutingHelper().addDataUpdateListener(listener);
|
app.getRoutingHelper().addRouteDataListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregisterFromUpdates(long id) {
|
public void unregisterFromUpdates(long id) {
|
||||||
app.getRoutingHelper().removeDataUpdateListener(navUpdateCallbacks.get(id));
|
app.getRoutingHelper().removeRouteDataListener(navUpdateCallbacks.get(id));
|
||||||
navUpdateCallbacks.remove(id);
|
navUpdateCallbacks.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
|
||||||
|
|
||||||
import static net.osmand.plus.notifications.OsmandNotification.NotificationType.NAVIGATION;
|
import static net.osmand.plus.notifications.OsmandNotification.NotificationType.NAVIGATION;
|
||||||
|
|
||||||
|
@ -267,31 +266,29 @@ public class RoutingHelper {
|
||||||
transportRoutingHelper.addListener(l);
|
transportRoutingHelper.addListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDataUpdateListener(IRoutingDataUpdateListener listener) {
|
public void addRouteDataListener(IRoutingDataUpdateListener listener) {
|
||||||
List<WeakReference<IRoutingDataUpdateListener>> copyList = new ArrayList<>(updateListeners);
|
updateListeners = updateListenersList(new ArrayList<>(updateListeners), listener, true);
|
||||||
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 removeDataUpdateListener(IRoutingDataUpdateListener listener) {
|
public void removeRouteDataListener(IRoutingDataUpdateListener listener) {
|
||||||
List<WeakReference<IRoutingDataUpdateListener>> copyList = new ArrayList<>(updateListeners);
|
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();
|
Iterator<WeakReference<IRoutingDataUpdateListener>> it = copyList.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
WeakReference<IRoutingDataUpdateListener> ref = it.next();
|
WeakReference<IRoutingDataUpdateListener> ref = it.next();
|
||||||
IRoutingDataUpdateListener l = ref.get();
|
IRoutingDataUpdateListener l = ref.get();
|
||||||
if (l == null || l == listener) {
|
if (l == null || (l == listener)) {
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateListeners = copyList;
|
if (isNewListener) {
|
||||||
|
copyList.add(new WeakReference<>(listener));
|
||||||
|
}
|
||||||
|
return copyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeListener(IRouteInformationListener lt){
|
public boolean removeListener(IRouteInformationListener lt){
|
||||||
|
@ -533,16 +530,11 @@ public class RoutingHelper {
|
||||||
app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION);
|
app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION);
|
||||||
if (!updateListeners.isEmpty()) {
|
if (!updateListeners.isEmpty()) {
|
||||||
ArrayList<WeakReference<IRoutingDataUpdateListener>> tmp = new ArrayList<>(updateListeners);
|
ArrayList<WeakReference<IRoutingDataUpdateListener>> tmp = new ArrayList<>(updateListeners);
|
||||||
Iterator<WeakReference<IRoutingDataUpdateListener>> it = tmp.iterator();
|
for (WeakReference<IRoutingDataUpdateListener> ref : tmp) {
|
||||||
while (it.hasNext()) {
|
|
||||||
WeakReference<IRoutingDataUpdateListener> ref = it.next();
|
|
||||||
IRoutingDataUpdateListener l = ref.get();
|
IRoutingDataUpdateListener l = ref.get();
|
||||||
if (l == null) {
|
if (l != null) {
|
||||||
it.remove();
|
|
||||||
} else {
|
|
||||||
l.onRoutingDataUpdate();
|
l.onRoutingDataUpdate();
|
||||||
}
|
}
|
||||||
updateListeners = tmp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue