summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Lasseter <nathan@4574.co.uk>2013-05-22 17:39:57 +0100
committerNathan Lasseter <nathan@4574.co.uk>2013-05-22 17:39:57 +0100
commitdd525d0d032ef28e1eab0a8d89e32eb5e72654bb (patch)
tree104a224612a363774381755703825c89aa93cf2c
parenteab3b658b2e49cfd57d2eb3611eaba737b14e550 (diff)
Username & Password
-rw-r--r--res/layout/start.xml29
-rw-r--r--res/values/strings.xml2
-rw-r--r--src/user4574/texttransport/Start.java16
3 files changed, 44 insertions, 3 deletions
diff --git a/res/layout/start.xml b/res/layout/start.xml
index d0f7d30..0168774 100644
--- a/res/layout/start.xml
+++ b/res/layout/start.xml
@@ -1,6 +1,6 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
+ android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
@@ -39,13 +39,17 @@
android:layout_below="@+id/protocol"
android:ems="10"
android:hint="@string/uri"
- android:inputType="textUri" />
+ android:inputType="textUri">
+
+ <requestFocus />
+ </EditText>
<EditText
android:id="@+id/port"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
+ android:layout_alignRight="@+id/protocol"
android:layout_below="@+id/uri"
android:ems="10"
android:hint="@string/port"
@@ -59,4 +63,25 @@
android:layout_below="@+id/port"
android:text="@string/connect" />
+ <EditText
+ android:id="@+id/username"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_alignRight="@+id/password"
+ android:layout_below="@+id/connectbutton"
+ android:ems="10"
+ android:hint="@string/username"
+ android:inputType="text" />
+
+ <EditText
+ android:id="@+id/password"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_below="@+id/username"
+ android:ems="10"
+ android:hint="@string/password"
+ android:inputType="textPassword" />
+
</RelativeLayout> \ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2c832b0..23ecb7c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -8,5 +8,7 @@
<string name="tcp">TCP</string>
<string name="ssl">SSL</string>
<string name="port">Port</string>
+ <string name="username">Username</string>
+ <string name="password">Password</string>
</resources> \ No newline at end of file
diff --git a/src/user4574/texttransport/Start.java b/src/user4574/texttransport/Start.java
index 799a036..8f93bd9 100644
--- a/src/user4574/texttransport/Start.java
+++ b/src/user4574/texttransport/Start.java
@@ -1,6 +1,7 @@
package user4574.texttransport;
import org.eclipse.paho.client.mqttv3.MqttClient;
+import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import android.app.Activity;
@@ -17,6 +18,7 @@ import android.widget.RadioGroup;
public class Start extends Activity {
public static MqttClient client;
+ private MqttConnectOptions opts;
private SmsManager sms = SmsManager.getDefault();
private Button conn;
@@ -24,6 +26,8 @@ public class Start extends Activity {
private EditText port;
private RadioGroup rg;
private String uri = "";
+ private EditText un;
+ private EditText pw;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -39,6 +43,9 @@ public class Start extends Activity {
port = (EditText) findViewById(R.id.port);
rg = (RadioGroup) findViewById(R.id.protocol);
+
+ un = (EditText) findViewById(R.id.username);
+ pw = (EditText) findViewById(R.id.password);
}
protected void onResume() {
@@ -67,7 +74,14 @@ public class Start extends Activity {
try {
client = new MqttClient(server, MqttClient.generateClientId(), new AndroidPersistence());
client.setCallback(new MqttMsgCallback(sms));
- client.connect();
+ if (!un.getText().toString().equals("")) {
+ opts = new MqttConnectOptions();
+ opts.setUserName(un.getText().toString());
+ String pass = pw.getText().toString();
+ if (!pass.equals("")) opts.setPassword(pass.toCharArray());
+ client.connect(opts);
+ } else
+ client.connect();
client.subscribe("/texttransport/+/send");
ent.setEnabled(false);
conn.setText(R.string.disconnect);