diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 5fd218a..a169371 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -9,6 +9,7 @@
android:targetSdkVersion="17" />
+
-
-
-
-
+ android:layout_height="wrap_content"
+ android:text="@string/discoverChild"
+ android:textSize="17sp" />
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/activity_discover_address.xml b/res/layout/activity_discover_address.xml
new file mode 100644
index 0000000..b3945d2
--- /dev/null
+++ b/res/layout/activity_discover_address.xml
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/activity_discover_mdns.xml b/res/layout/activity_discover_mdns.xml
new file mode 100644
index 0000000..386bbcf
--- /dev/null
+++ b/res/layout/activity_discover_mdns.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/activity_monitor.xml b/res/layout/activity_monitor.xml
index 07625b9..59c50b4 100644
--- a/res/layout/activity_monitor.xml
+++ b/res/layout/activity_monitor.xml
@@ -47,6 +47,44 @@
android:layout_width="match_parent"
android:layout_height="15dip" />
+
+
+
+
+
+
+
+
+
+
+
+
Connected To:
Disconnected
Listening...
-
+ Address:
+ Port:
+ Address and port that parent must pair to
+ Not connected to a Wi-Fi network
+ Enter the IP Address and port of a child and click Connect
+ Connect
+ 192.168.1.2
+ 10000
+ Either no port was entered or it is invalid
+ The address field needs to be filled out
+ Discover Child on Network
+ Select child from a list of discovered children on the network
+ Select Child by Address
+ Enter the address and port of the child
diff --git a/src/protect/babymonitor/DiscoverActivity.java b/src/protect/babymonitor/DiscoverActivity.java
index f75565c..69bc7be 100644
--- a/src/protect/babymonitor/DiscoverActivity.java
+++ b/src/protect/babymonitor/DiscoverActivity.java
@@ -27,7 +27,10 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
import android.widget.ListView;
+import android.widget.Toast;
public class DiscoverActivity extends Activity
{
@@ -47,9 +50,74 @@ public class DiscoverActivity extends Activity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_discover);
+ final Button discoverChildButton = (Button) findViewById(R.id.discoverChildButton);
+ discoverChildButton.setOnClickListener(new View.OnClickListener()
+ {
+ @Override
+ public void onClick(View v)
+ {
+ loadDiscoveryViaMdns();
+ }
+ });
+
+ final Button enterChildAddressButton = (Button) findViewById(R.id.enterChildAddressButton);
+ enterChildAddressButton.setOnClickListener(new View.OnClickListener()
+ {
+ @Override
+ public void onClick(View v)
+ {
+ loadDiscoveryViaAddress();
+ }
+ });
+ }
+
+ private void loadDiscoveryViaMdns()
+ {
+ setContentView(R.layout.activity_discover_mdns);
startServiceDiscovery("_babymonitor._tcp.");
}
+ private void loadDiscoveryViaAddress()
+ {
+ setContentView(R.layout.activity_discover_address);
+
+ final Button connectButton = (Button) findViewById(R.id.connectViaAddressButton);
+ connectButton.setOnClickListener(new View.OnClickListener()
+ {
+ @Override
+ public void onClick(View v)
+ {
+ Log.i(TAG, "Connecting to child device via address");
+
+ final EditText addressField = (EditText) findViewById(R.id.ipAddressField);
+ final EditText portField = (EditText) findViewById(R.id.portField);
+
+ final String addressString = addressField.getText().toString();
+ final String portString = portField.getText().toString();
+
+ if(addressString.length() == 0)
+ {
+ Toast.makeText(DiscoverActivity.this, R.string.invalidAddress, Toast.LENGTH_LONG).show();
+ return;
+ }
+
+ int port = 0;
+
+ try
+ {
+ port = Integer.parseInt(portString);
+ }
+ catch(NumberFormatException e)
+ {
+ Toast.makeText(DiscoverActivity.this, R.string.invalidPort, Toast.LENGTH_LONG).show();
+ return;
+ }
+
+ connectToChild(addressString, port, addressString);
+ }
+ });
+ }
+
@Override
protected void onDestroy()
{
@@ -83,13 +151,7 @@ public class DiscoverActivity extends Activity
int position, long id)
{
final ServiceInfoWrapper info = (ServiceInfoWrapper) parent.getItemAtPosition(position);
- final Intent i = new Intent(getApplicationContext(), ListenActivity.class);
- final Bundle b = new Bundle();
- b.putString("address", info.getAddress());
- b.putInt("port", info.getPort());
- b.putString("name", info.getName());
- i.putExtras(b);
- startActivity(i);
+ connectToChild(info.getAddress(), info.getPort(), info.getName());
}
});
@@ -181,6 +243,24 @@ public class DiscoverActivity extends Activity
nsdManager.discoverServices(
serviceType, NsdManager.PROTOCOL_DNS_SD, _discoveryListener);
}
+
+ /**
+ * Launch the ListenActivity to connect to the given child device
+ *
+ * @param address
+ * @param port
+ * @param name
+ */
+ private void connectToChild(final String address, final int port, final String name)
+ {
+ final Intent i = new Intent(getApplicationContext(), ListenActivity.class);
+ final Bundle b = new Bundle();
+ b.putString("address", address);
+ b.putInt("port", port);
+ b.putString("name", name);
+ i.putExtras(b);
+ startActivity(i);
+ }
}
class ServiceInfoWrapper
diff --git a/src/protect/babymonitor/MonitorActivity.java b/src/protect/babymonitor/MonitorActivity.java
index 7d3774c..4d5a3ac 100644
--- a/src/protect/babymonitor/MonitorActivity.java
+++ b/src/protect/babymonitor/MonitorActivity.java
@@ -28,7 +28,10 @@ import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.net.nsd.NsdManager;
import android.net.nsd.NsdServiceInfo;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
import android.os.Bundle;
+import android.text.format.Formatter;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -163,6 +166,29 @@ public class MonitorActivity extends Activity
}
});
_serviceThread.start();
+
+ MonitorActivity.this.runOnUiThread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ final TextView addressText = (TextView) findViewById(R.id.address);
+
+ final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
+ final WifiInfo info = wifiManager.getConnectionInfo();
+ final int address = info.getIpAddress();
+ if(address != 0)
+ {
+ @SuppressWarnings("deprecation")
+ final String ipAddress = Formatter.formatIpAddress(address);
+ addressText.setText(ipAddress);
+ }
+ else
+ {
+ addressText.setText(R.string.wifiNotConnected);
+ }
+ }
+ });
}
@Override
@@ -212,11 +238,11 @@ public class MonitorActivity extends Activity
_registrationListener = new NsdManager.RegistrationListener()
{
@Override
- public void onServiceRegistered(NsdServiceInfo NsdServiceInfo) {
+ public void onServiceRegistered(NsdServiceInfo nsdServiceInfo) {
// Save the service name. Android may have changed it in order to
// resolve a conflict, so update the name you initially requested
// with the name Android actually used.
- final String serviceName = NsdServiceInfo.getServiceName();
+ final String serviceName = nsdServiceInfo.getServiceName();
Log.i(TAG, "Service name: " + serviceName);
@@ -229,6 +255,9 @@ public class MonitorActivity extends Activity
final TextView serviceText = (TextView) findViewById(R.id.textService);
serviceText.setText(serviceName);
+
+ final TextView portText = (TextView) findViewById(R.id.port);
+ portText.setText(Integer.toString(port));
}
});
}