From df19ffa05ec5dfc6bccb010bc9fd6231987bafcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Sat, 25 Feb 2012 23:02:13 +0100 Subject: SameService sends all state initially to new listeners. --- .../src/main/java/com/orbekk/same/SameService.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'same-android/src/main/java') diff --git a/same-android/src/main/java/com/orbekk/same/SameService.java b/same-android/src/main/java/com/orbekk/same/SameService.java index 55fb17c..dad4b50 100644 --- a/same-android/src/main/java/com/orbekk/same/SameService.java +++ b/same-android/src/main/java/com/orbekk/same/SameService.java @@ -97,6 +97,7 @@ public class SameService extends Service { Messenger messenger = message.replyTo; if (messenger != null) { stateReceivers.add(messenger); + sendAllState(messenger); } else { logger.error("ADD_STATE_RECEIVER: Missing Messenger."); } @@ -127,6 +128,21 @@ public class SameService extends Service { } }; + private void sendAllState(Messenger messenger) { + State state = sameController.getClient().getInterface().getState(); + for (Component c : state.getComponents()) { + Message message = Message.obtain(null, UPDATED_STATE_MESSAGE); + message.obj = c; + try { + messenger.send(message); + } catch (RemoteException e) { + logger.warn("Failed to send state."); + e.printStackTrace(); + return; + } + } + } + private void initializeConfiguration() { Properties properties = new Properties(); String localIp = new Broadcaster(this) -- cgit v1.2.3