From cd22ae793f261976d29f2d02f852ef657be0c6bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Sat, 25 Feb 2012 22:39:07 +0100 Subject: Send state updates from SameService. --- same-android/src/main/java/com/orbekk/same/SameService.java | 11 +++++++++++ .../java/com/orbekk/same/android/SameInterfaceBridge.java | 5 +++++ 2 files changed, 16 insertions(+) (limited to 'same-android/src') 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 78bc62a..53742bd 100644 --- a/same-android/src/main/java/com/orbekk/same/SameService.java +++ b/same-android/src/main/java/com/orbekk/same/SameService.java @@ -15,6 +15,7 @@ import android.os.Messenger; import android.os.RemoteException; import android.widget.Toast; +import com.orbekk.same.State.Component; import com.orbekk.same.android.net.AndroidBroadcasterFactory; import com.orbekk.same.android.net.Broadcaster; import com.orbekk.same.config.Configuration; @@ -107,6 +108,16 @@ public class SameService extends Service { private final Messenger messenger = new Messenger(new InterfaceHandler()); + private StateChangedListener stateListener = new StateChangedListener() { + @Override + public void stateChanged(Component component) { + for (Messenger messenger : stateReceivers) { + Message message = Message.obtain(null, UPDATED_STATE_MESSAGE); + message.obj = component; + } + } + }; + private void initializeConfiguration() { Properties properties = new Properties(); String localIp = new Broadcaster(this) 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 c049d37..4d44a03 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 @@ -12,6 +12,7 @@ import android.os.IBinder; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; +import android.widget.Toast; import com.orbekk.same.ClientInterface; import com.orbekk.same.SameService; @@ -23,6 +24,10 @@ public class SameInterfaceBridge implements ClientInterface { class ResponseHandler extends Handler { @Override public void handleMessage(Message message) { switch (message.what) { + case SameService.UPDATED_STATE_MESSAGE: + State.Component component = (State.Component)message.obj; + Toast.makeText(context, "Updated: " + component, + Toast.LENGTH_SHORT).show(); default: logger.warn("Received unknown message from service: {}", message); -- cgit v1.2.3