summaryrefslogtreecommitdiff
path: root/same-android/src/main/java/com/orbekk
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-26 19:34:25 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-26 19:34:25 +0100
commitb35173cc4c9cab138168c2df6d6331837d0cde12 (patch)
treef98b0215d381d8c456b8989020b8cc88f6a60760 /same-android/src/main/java/com/orbekk
parent980f590ef8db3c17567c343d279102a0caa022dd (diff)
Clean up Android code.
Diffstat (limited to 'same-android/src/main/java/com/orbekk')
-rw-r--r--same-android/src/main/java/com/orbekk/discovery/SameService.java32
1 files changed, 24 insertions, 8 deletions
diff --git a/same-android/src/main/java/com/orbekk/discovery/SameService.java b/same-android/src/main/java/com/orbekk/discovery/SameService.java
index 154239f..7ca9778 100644
--- a/same-android/src/main/java/com/orbekk/discovery/SameService.java
+++ b/same-android/src/main/java/com/orbekk/discovery/SameService.java
@@ -12,6 +12,7 @@ import android.widget.Toast;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.orbekk.same.ClientApp;
import com.orbekk.same.MasterApp;
public class SameService extends Service {
@@ -52,11 +53,30 @@ public class SameService extends Service {
}
};
+ private void createNetwork() {
+ if (discoveryThread == null) {
+ synchronized (this) {
+ discoveryThread = new DiscoveryThread();
+ discoveryThread.start();
+ }
+ }
+ new Thread() {
+ @Override public void run() {
+ new MasterApp().run(PORT+1);
+ }
+ }.start();
+ }
+
private void sendBroadcastDiscovery() {
byte[] data = "Discover".getBytes();
new Broadcast(this).sendBroadcast(data, PORT);
}
+ private void joinNetwork() {
+ sendBroadcastDiscovery();
+ new ClientApp().run(PORT+2, "ClientNetwork", null);
+ }
+
@Override
public IBinder onBind(Intent intent) {
return null;
@@ -66,14 +86,10 @@ public class SameService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "service start: " + intent.getAction(),
Toast.LENGTH_SHORT).show();
- if (discoveryThread == null) {
- synchronized (this) {
- discoveryThread = new DiscoveryThread();
- discoveryThread.start();
- }
- }
- if (intent.getAction().equals("join")) {
- sendBroadcastDiscovery();
+ if (intent.getAction().equals("create")) {
+ createNetwork();
+ } else if (intent.getAction().equals("join")) {
+ joinNetwork();
}
return START_STICKY;
}