diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-02-25 22:32:09 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-02-25 22:32:09 +0100 |
commit | dfbb6b1a8b7d33a2e2097187ddc07d379163bce7 (patch) | |
tree | 9aadd85716174f378a4920de5c27b5fa8f787dd5 /same-android/src | |
parent | 28ccfd5c38df380fc87461238c9b717ad7fd7dce (diff) |
Add StateReceivers in SameService.
Diffstat (limited to 'same-android/src')
-rw-r--r-- | same-android/src/main/java/com/orbekk/same/SameService.java | 11 | ||||
-rw-r--r-- | same-android/src/main/java/com/orbekk/same/android/SameInterfaceBridge.java | 11 |
2 files changed, 16 insertions, 6 deletions
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<Messenger> stateReceivers = new ArrayList<Messenger>(); private ArrayList<String> networkNames = new ArrayList<String>(); private ArrayList<String> networkUrls = new ArrayList<String>(); @@ -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(); } } |