1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

AndroidGCS: ObjectManagerActivity maintains a list of objects it is getting

updates from and disconnects them on onStop().  This should probably move to
onPause / onResume
This commit is contained in:
James Cotton 2012-08-10 08:49:40 -05:00
parent fcff84007e
commit 56dfa62682

View File

@ -29,10 +29,13 @@
*/ */
package org.openpilot.androidgcs; package org.openpilot.androidgcs;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import java.util.Set;
import org.openpilot.androidgcs.fragments.ObjectManagerFragment; import org.openpilot.androidgcs.fragments.ObjectManagerFragment;
import org.openpilot.androidgcs.telemetry.OPTelemetryService; import org.openpilot.androidgcs.telemetry.OPTelemetryService;
@ -128,13 +131,31 @@ public abstract class ObjectManagerActivity extends Activity {
* *
* the objectUpdated() method will be called in the original UI thread * the objectUpdated() method will be called in the original UI thread
*/ */
HashMap<Observer, UAVObject> listeners = new HashMap<Observer,UAVObject>();
protected void registerObjectUpdates(UAVObject object) { protected void registerObjectUpdates(UAVObject object) {
object.addUpdatedObserver(new ActivityUpdatedObserver(object)); Observer o = new ActivityUpdatedObserver(object);
object.addUpdatedObserver(o);
listeners.put(o, object);
}
/**
* Unregister all the objects connected to this activity
*/
protected void unregisterObjectUpdates()
{
Set<Observer> s = listeners.keySet();
Iterator<Observer> i = s.iterator();
while (i.hasNext()) {
Observer o = i.next();
UAVObject obj = listeners.get(o);
obj.removeUpdatedObserver(o);
}
listeners.clear();
} }
public void registerObjectUpdates(UAVObject object, public void registerObjectUpdates(UAVObject object,
ObjectManagerFragment frag) { ObjectManagerFragment frag) {
object.addUpdatedObserver(new FragmentUpdatedObserver(object, frag)); Observer o = new FragmentUpdatedObserver(object, frag);
object.addUpdatedObserver(o);
listeners.put(o, object);
} }
protected void registerObjectUpdates(List<List<UAVObject>> objects) { protected void registerObjectUpdates(List<List<UAVObject>> objects) {
ListIterator<List<UAVObject>> li = objects.listIterator(); ListIterator<List<UAVObject>> li = objects.listIterator();
@ -206,6 +227,9 @@ public abstract class ObjectManagerActivity extends Activity {
// Providing a null update triggers a disconnect on fragments // Providing a null update triggers a disconnect on fragments
connectionListeners.disconnected(); connectionListeners.disconnected();
// Disconnect from any UAVO updates
unregisterObjectUpdates();
} }
@Override @Override
@ -294,6 +318,9 @@ public abstract class ObjectManagerActivity extends Activity {
unbindService(mConnection); unbindService(mConnection);
unregisterReceiver(connectedReceiver); unregisterReceiver(connectedReceiver);
connectedReceiver = null; connectedReceiver = null;
// Disconnect from any UAVO updates
unregisterObjectUpdates();
} }
public void onBind() { public void onBind() {