From dfbb6b1a8b7d33a2e2097187ddc07d379163bce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Sat, 25 Feb 2012 22:32:09 +0100 Subject: Add StateReceivers in SameService. --- same-android/src/main/java/com/orbekk/same/SameService.java | 11 +++++++++++ .../java/com/orbekk/same/android/SameInterfaceBridge.java | 11 +++++------ 2 files changed, 16 insertions(+), 6 deletions(-) (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 a58b0ec..78bc62a 100644 --- a/same-android/src/main/java/com/orbekk/same/SameService.java +++ b/same-android/src/main/java/com/orbekk/same/SameService.java @@ -24,6 +24,8 @@ public class SameService extends Service { public final static int SEARCH_NETWORKS = 2; public final static int CREATE_NETWORK = 3; public final static int JOIN_NETWORK = 4; + public final static int UPDATED_STATE_MESSAGE = 5; + public final static int ADD_STATE_RECEIVER = 6; public final static String AVAILABLE_NETWORKS_UPDATE = "com.orbekk.same.SameService.action.AVAILABLE_NETWORKS_UPDATE"; @@ -38,6 +40,7 @@ public class SameService extends Service { private Logger logger = LoggerFactory.getLogger(getClass()); private SameController sameController = null; private Configuration configuration = null; + private ArrayList stateReceivers = new ArrayList(); private ArrayList networkNames = new ArrayList(); private ArrayList networkUrls = new ArrayList(); @@ -88,6 +91,14 @@ public class SameService extends Service { logger.info("JOIN_NETWORK"); String masterUrl = (String)message.obj; sameController.getClient().joinNetwork(masterUrl); + case ADD_STATE_RECEIVER: + logger.info("ADD_STATE_RECEIVER: {}", message); + Messenger messenger = message.replyTo; + if (messenger != null) { + stateReceivers.add(messenger); + } else { + logger.error("ADD_STATE_RECEIVER: Missing Messenger."); + } default: super.handleMessage(message); } diff --git a/same-android/src/main/java/com/orbekk/same/android/SameInterfaceBridge.java b/same-android/src/main/java/com/orbekk/same/android/SameInterfaceBridge.java index 48e38cd..c049d37 100644 --- a/same-android/src/main/java/com/orbekk/same/android/SameInterfaceBridge.java +++ b/same-android/src/main/java/com/orbekk/same/android/SameInterfaceBridge.java @@ -39,14 +39,13 @@ public class SameInterfaceBridge implements ClientInterface { @Override public void onServiceConnected(ComponentName name, IBinder service) { serviceMessenger = new Messenger(service); - Message display_message = Message.obtain(null, - SameService.DISPLAY_MESSAGE); - display_message.obj = "Message from bridge."; - display_message.replyTo = responseMessenger; + Message message = Message.obtain(null, + SameService.ADD_STATE_RECEIVER); + message.replyTo = responseMessenger; try { - serviceMessenger.send(display_message); + serviceMessenger.send(message); } catch (RemoteException e) { - logger.error("Failed to send message to service."); + e.printStackTrace(); } } -- cgit v1.2.3