summaryrefslogtreecommitdiff
path: root/same-android/src
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-30 12:05:33 +0200
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-30 12:05:33 +0200
commit058f9ba7650927d755cf408027dd19f78c92b7c2 (patch)
treef1815ffb75bec6e6d92f1e4566f151ba3caa4f14 /same-android/src
parentd87e94e9765c33ccf49d4743d2e4be94d65a5e76 (diff)
Add "kill master" button.
Diffstat (limited to 'same-android/src')
-rw-r--r--same-android/src/main/java/com/orbekk/same/android/SameControllerActivity.java13
-rw-r--r--same-android/src/main/java/com/orbekk/same/android/SameService.java7
2 files changed, 17 insertions, 3 deletions
diff --git a/same-android/src/main/java/com/orbekk/same/android/SameControllerActivity.java b/same-android/src/main/java/com/orbekk/same/android/SameControllerActivity.java
index 6e8d613..c0f60f8 100644
--- a/same-android/src/main/java/com/orbekk/same/android/SameControllerActivity.java
+++ b/same-android/src/main/java/com/orbekk/same/android/SameControllerActivity.java
@@ -63,8 +63,7 @@ public class SameControllerActivity extends Activity {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String networkName = networkNames.get(position);
- int networkIndex = networkNames.indexOf(networkName);
- String masterUrl = networkUrls.get(networkIndex);
+ String masterUrl = networkUrls.get(position);
joinNetwork(masterUrl);
}
};
@@ -87,6 +86,16 @@ public class SameControllerActivity extends Activity {
}
}
+ public void killMaster(View unused) {
+ Message message = Message.obtain(null, SameService.KILL_MASTER);
+ try {
+ sameService.send(message);
+ } catch (RemoteException e) {
+ logger.error("Failed to kill master", e);
+ throw new RuntimeException(e);
+ }
+ }
+
public void joinNetworkUrl(View unused) {
Intent intent = new Intent(this, SameService.class);
intent.setAction("join");
diff --git a/same-android/src/main/java/com/orbekk/same/android/SameService.java b/same-android/src/main/java/com/orbekk/same/android/SameService.java
index 559b521..c9ff39b 100644
--- a/same-android/src/main/java/com/orbekk/same/android/SameService.java
+++ b/same-android/src/main/java/com/orbekk/same/android/SameService.java
@@ -40,7 +40,7 @@ public class SameService extends Service {
public final static int JOIN_NETWORK = 4;
public final static int ADD_STATE_RECEIVER = 5;
public final static int REMOVE_STATE_RECEIVER = 6;
-
+
/**
* arg1: Operation number.
* bundle: A Bundle created with ComponentBundle
@@ -58,6 +58,8 @@ public class SameService extends Service {
* obj: Status message.
*/
public final static int OPERATION_STATUS_CALLBACK = 9;
+
+ public final static int KILL_MASTER = 10;
// TODO: Remove these and use messengers instead of broadcast intents.
public final static String AVAILABLE_NETWORKS_UPDATE =
@@ -137,6 +139,9 @@ public class SameService extends Service {
operationStatusCallback(op, id, message.replyTo);
logger.info("Callback sent.");
break;
+ case KILL_MASTER:
+ logger.info("Kill master.");
+ sameController.killMaster();
default:
super.handleMessage(message);
}