summaryrefslogtreecommitdiff
path: root/same-android/src/main
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-25 22:32:09 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-25 22:32:09 +0100
commitdfbb6b1a8b7d33a2e2097187ddc07d379163bce7 (patch)
tree9aadd85716174f378a4920de5c27b5fa8f787dd5 /same-android/src/main
parent28ccfd5c38df380fc87461238c9b717ad7fd7dce (diff)
Add StateReceivers in SameService.
Diffstat (limited to 'same-android/src/main')
-rw-r--r--same-android/src/main/java/com/orbekk/same/SameService.java11
-rw-r--r--same-android/src/main/java/com/orbekk/same/android/SameInterfaceBridge.java11
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();
}
}