commit d6541baa0f7b7b3e2b3d05327f80b6d32b9d6239
parent e1b9bae1b17afdc95066ae5833d97e9d43007b25
Author: David Engel <david@absentmindedproductions.ca>
Date: Sun, 24 May 2015 00:56:52 -0600
android: can send custom messages from homescreen
Diffstat:
2 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/kd/app/src/main/java/kd/shared_lists/HomeScreen.java b/kd/app/src/main/java/kd/shared_lists/HomeScreen.java
@@ -1,6 +1,9 @@
package kd.shared_lists;
+import android.animation.AnimatorSet;
+import android.app.Dialog;
import android.content.Context;
+import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
@@ -8,8 +11,15 @@ import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
import android.widget.TextView;
+import org.w3c.dom.Text;
+
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
@@ -20,16 +30,34 @@ import java.net.Socket;
public class HomeScreen extends ActionBarActivity {
private TextView tv;
+ public String number;
+ EditText numbertv;
+ EditText nametv;
+ public String name;
public static final int SERVERPORT = 5437;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- testNet();
- new sendMessageTask().execute("foobar");
+ setContentView(R.layout.layout_home_screen);
+ Button sendMsgButton = new Button(this);
+ numbertv = new EditText(this);
+ numbertv.setText("4039235990");
+ nametv = new EditText(this);
+ nametv.setText("puffdaddy");
+ sendMsgButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new sendMessageTask().execute("foobar", "joobar");
+ }
+ });
+ LinearLayout rl = (LinearLayout) findViewById(R.id.mainlayout);
+ sendMsgButton.setText("Send Message");
+ rl.addView(sendMsgButton);
+ rl.addView(numbertv);
+ rl.addView(nametv);
}
private void testNet() {
- setContentView(R.layout.layout_home_screen);
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
tv = (TextView) findViewById(R.id.hellotext);
@@ -49,33 +77,38 @@ public class HomeScreen extends ActionBarActivity {
}
public void sendMessage() {
+// setContentView(R.layout.layout_home_screen);
// new lists need title, kyle sends me id
try {
InetAddress addr = InetAddress.getByName("104.236.186.39");
//InetAddress addr = InetAddress.getByName("127.0.0.0");
+ number = numbertv.getText().toString();
+ name = nametv.getText().toString();
+ //tv = (TextView) findViewById(R.id.hellotext);
+ //tv.setText(number + "\0" + name);
Socket socket = new Socket(addr, SERVERPORT);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
if (out != null) {
if (!out.checkError()) {
- tv.setText("sending");
- String message = "4039235990\0bob";
+// tv.setText("sending");
+ String message = number + "\0" + name;
String type = "1";
int length = message.length();
out.println(type + length + message);
- tv.setText("Sent: " + type + length + message);
+ // tv.setText("Sent: " + type + length + message);
} else {
- tv.setText("errror");
+ // tv.setText("errror");
}
} else {
- tv.setText("null");
+ // tv.setText("null");
}
out.flush();
socket.close();
//tv.setText("Sent");
} catch (java.net.UnknownHostException e) {
- tv.setText("unknown host");
+ //tv.setText("unknown host");
} catch (java.io.IOException e) {
- tv.setText("io exception");
+ //tv.setText("io exception");
}
}
diff --git a/kd/app/src/main/res/layout/layout_home_screen.xml b/kd/app/src/main/res/layout/layout_home_screen.xml
@@ -1,4 +1,4 @@
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout android:id="@+id/mainlayout" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
@@ -8,4 +8,4 @@
<TextView android:id="@+id/hellotext" android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
-</RelativeLayout>
+</LinearLayout>