summaryrefslogtreecommitdiff
path: root/same-android
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
parent980f590ef8db3c17567c343d279102a0caa022dd (diff)
Clean up Android code.
Diffstat (limited to 'same-android')
-rw-r--r--same-android/res/layout/main.xml12
-rw-r--r--same-android/src/main/java/com/orbekk/discovery/SameService.java32
2 files changed, 30 insertions, 14 deletions
diff --git a/same-android/res/layout/main.xml b/same-android/res/layout/main.xml
index 8a05563..a286b81 100644
--- a/same-android/res/layout/main.xml
+++ b/same-android/res/layout/main.xml
@@ -7,16 +7,16 @@
<Button
android:id="@+id/button1"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="Create"
- android:onClick="createNetwork" />
+ android:onClick="createNetwork"
+ android:text="Create" />
<Button
android:id="@+id/button2"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="Join"
- android:onClick="joinNetwork" />
+ android:onClick="joinNetwork"
+ android:text="Join" />
</LinearLayout>
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;
}