From 5bc18853d378e8d6c6f965a3e16f1c388cfb8210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Mon, 13 Feb 2012 20:15:39 +0100 Subject: Display discovered networks in user interface. --- .../src/main/java/com/orbekk/SameControllerActivity.java | 15 ++++----------- same-android/src/main/java/com/orbekk/SameService.java | 10 +++++----- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'same-android/src/main/java/com') diff --git a/same-android/src/main/java/com/orbekk/SameControllerActivity.java b/same-android/src/main/java/com/orbekk/SameControllerActivity.java index a2d5688..4fb1424 100644 --- a/same-android/src/main/java/com/orbekk/SameControllerActivity.java +++ b/same-android/src/main/java/com/orbekk/SameControllerActivity.java @@ -49,8 +49,10 @@ public class SameControllerActivity extends Activity { if (SameService.AVAILABLE_NETWORKS_UPDATE.equals(intent.getAction())) { ArrayList networkList = intent.getStringArrayListExtra( SameService.AVAILABLE_NETWORKS); - Toast.makeText(SameControllerActivity.this, networkList.toString(), - Toast.LENGTH_SHORT).show(); + ListView list = (ListView)findViewById(R.id.network_list); + list.setAdapter(new ArrayAdapter( + SameControllerActivity.this, + R.layout.list_text_item, networkList)); } } }; @@ -89,15 +91,6 @@ public class SameControllerActivity extends Activity { public void searchNetworks(View unused) { logger.info("SearchNetworks()"); -// Toast.makeText(this, "Discovering networks", Toast.LENGTH_SHORT).show(); -// final String[] listItems = new String[]{"First item", "Second item"}; -// ListView list = (ListView)findViewById(R.id.network_list); -// list.setAdapter(new ArrayAdapter(this, R.layout.list_text_item, -// listItems)); - -// Message message = Message.obtain(null, SameService.DISPLAY_MESSAGE, -// "Message from Activity!"); - Message searchMessage = Message.obtain(null, SameService.SEARCH_NETWORKS); try { sameService.send(searchMessage); diff --git a/same-android/src/main/java/com/orbekk/SameService.java b/same-android/src/main/java/com/orbekk/SameService.java index 305bf44..bc758ab 100644 --- a/same-android/src/main/java/com/orbekk/SameService.java +++ b/same-android/src/main/java/com/orbekk/SameService.java @@ -41,19 +41,19 @@ public class SameService extends Service { private SameController sameController = null; private Configuration configuration = null; - // A list with alternating network names and urls. - private ArrayList availableNetworks = new ArrayList(); + private ArrayList networkNames = new ArrayList(); + private ArrayList networkUrls = new ArrayList(); private NetworkNotificationListener networkListener = new NetworkNotificationListener() { @Override public void notifyNetwork(String networkName, String masterUrl) { logger.info("notifyNetwork({})", networkName); - availableNetworks.add(networkName); - availableNetworks.add(masterUrl); + networkNames.add(networkName); + networkUrls.add(masterUrl); Intent intent = new Intent(AVAILABLE_NETWORKS_UPDATE); intent.putStringArrayListExtra(AVAILABLE_NETWORKS, - availableNetworks); + networkNames); sendBroadcast(intent); } }; -- cgit v1.2.3