summaryrefslogtreecommitdiff
path: root/same-android/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'same-android/src/main/java/com')
-rw-r--r--same-android/src/main/java/com/orbekk/same/SameControllerActivity.java11
-rw-r--r--same-android/src/main/java/com/orbekk/same/SameService.java23
2 files changed, 26 insertions, 8 deletions
diff --git a/same-android/src/main/java/com/orbekk/same/SameControllerActivity.java b/same-android/src/main/java/com/orbekk/same/SameControllerActivity.java
index 041260c..31d3e18 100644
--- a/same-android/src/main/java/com/orbekk/same/SameControllerActivity.java
+++ b/same-android/src/main/java/com/orbekk/same/SameControllerActivity.java
@@ -57,10 +57,13 @@ public class SameControllerActivity extends Activity {
};
public void createNetwork(View unused) {
- logger.info("Creating network");
- Intent intent = new Intent(this, SameService.class);
- intent.setAction("create");
- startService(intent);
+ Message message = Message.obtain(null, SameService.CREATE_NETWORK);
+ try {
+ sameService.send(message);
+ } catch (RemoteException e) {
+ logger.error("Failed to create network", e);
+ throw new RuntimeException(e);
+ }
}
public void joinNetwork(View unused) {
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 ba29585..3237e61 100644
--- a/same-android/src/main/java/com/orbekk/same/SameService.java
+++ b/same-android/src/main/java/com/orbekk/same/SameService.java
@@ -23,7 +23,8 @@ import com.orbekk.same.config.Configuration;
public class SameService extends Service {
public final static int DISPLAY_MESSAGE = 1;
public final static int SEARCH_NETWORKS = 2;
-
+ public final static int CREATE_NETWORK = 3;
+
public final static String AVAILABLE_NETWORKS_UPDATE =
"com.orbekk.same.SameService.action.AVAILABLE_NETWORKS_UPDATE";
public final static String AVAILABLE_NETWORKS =
@@ -65,6 +66,10 @@ public class SameService extends Service {
logger.info("SEARCH_NETWORKS");
sameController.searchNetworks();
break;
+ case CREATE_NETWORK:
+ logger.info("CREATE_NETWORK");
+ create();
+ break;
default:
super.handleMessage(message);
}
@@ -75,15 +80,25 @@ public class SameService extends Service {
private void initializeConfiguration() {
Properties properties = new Properties();
+ String localIp = new Broadcaster(this)
+ .getWlanAddress().getHostAddress();
+ String localMaster = "http://" + localIp + ":" + SERVICE_PORT +
+ "/MasterService.json";
properties.setProperty("port", ""+SERVICE_PORT);
- properties.setProperty("localIp",
- new Broadcaster(this).getWlanAddress().getHostAddress());
- properties.setProperty("masterUrl", "http://10.0.0.6:10010/MasterService.json");
+ properties.setProperty("localIp", localIp);
+ properties.setProperty("masterUrl", localMaster);
properties.setProperty("enableDiscovery", "true");
properties.setProperty("discoveryPort", ""+DISCOVERY_PORT);
+ properties.setProperty("networkName", "AndroidNetwork");
configuration = new Configuration(properties);
}
+ /** Create a public network. */
+ private void create() {
+ sameController.getClient().joinNetwork(
+ configuration.get("masterUrl"));
+ }
+
@Override
public IBinder onBind(Intent intent) {
logger.info("onBind()");