Commit b4c6599c authored by Daniel Niecke's avatar Daniel Niecke

code clean up

parent 9854b6ef
......@@ -21,7 +21,7 @@
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:name=".StoreKeyActivity"
android:label="Second Activity">
</activity>
<activity
......
......@@ -5,31 +5,25 @@ import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
//implement the OnClickListener interface
public class MainActivity extends Activity implements OnClickListener {
//create variables for storing message & button objects
EditText msgTextField;
Button sendButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.main_layout);
//make message text field object
msgTextField = (EditText) findViewById(R.id.EditTextName);
//get the Button reference
//Button is a subclass of View
//buttonClick if from main.xml "@+id/buttonClick"
View btnClick = findViewById(R.id.buttonClick);
//set event listener
btnClick.setOnClickListener(this);
}
......@@ -38,11 +32,11 @@ public class MainActivity extends Activity implements OnClickListener {
@Override
public void onClick(View arg0) {
if(arg0.getId() == R.id.buttonClick){
//define a new Intent for the second Activity
Intent intent = new Intent(this,SecondActivity.class);
//define a new Intent for the store_layout Activity
Intent intent = new Intent(this,StoreKeyActivity.class);
String msg = msgTextField.getText().toString();
System.out.println(msg);
//start the second Activity
//start the store_layout Activity
intent.putExtra("key", msg);
this.startActivity(intent);
}
......
......@@ -14,18 +14,6 @@ import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -41,7 +29,7 @@ public class SendUrlActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.send_url);
setContentView(R.layout.send_url_layout);
// Get the intent that started this activity
Intent intent = getIntent();
......@@ -51,34 +39,7 @@ public class SendUrlActivity extends AppCompatActivity {
final TextView selection = (TextView) findViewById(R.id.ShowIntent);
selection.setText(data);
final String url_extracted = this.extractUrls(data).get(0);
/*
String request_url = String.format("https://news.niecke-it.de/app?url=%s", url_extracted);
System.out.println(request_url);
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, request_url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
selection.setText("Response is: "+ response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
selection.setText("That didn't work!");
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
*/
final String url_extracted = extractUrls(data).get(0);
// Create data variable for sent values to server
RequestQueue MyRequestQueue = Volley.newRequestQueue(this);
......@@ -90,8 +51,6 @@ public class SendUrlActivity extends AppCompatActivity {
public void onResponse(String response) {
//This code is executed if the server responds, whether or not the response contains data.
//The String 'response' contains the server's response.
// findViewById(R.id.myCoordinatorLayout), R.string.email_sent,
// Snackbar.LENGTH_SHORT
Snackbar mySnackbar = Snackbar.make(findViewById(R.id.ShowIntent), R.string.url_was_sent, Snackbar.LENGTH_SHORT);
mySnackbar.show();
}
......@@ -120,15 +79,14 @@ public class SendUrlActivity extends AppCompatActivity {
/**
* Returns a list with all links contained in the input
*/
public static List<String> extractUrls(String text)
{
public static List<String> extractUrls(String text) {
List<String> containedUrls = new ArrayList<String>();
String urlRegex = "((https?|ftp|gopher|telnet|file):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)";
Pattern pattern = Pattern.compile(urlRegex, Pattern.CASE_INSENSITIVE);
Matcher urlMatcher = pattern.matcher(text);
while (urlMatcher.find())
{
while (urlMatcher.find()) {
containedUrls.add(text.substring(urlMatcher.start(0),
urlMatcher.end(0)));
}
......
......@@ -6,7 +6,7 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;
public class SecondActivity extends Activity {
public class StoreKeyActivity extends Activity {
// Create SharedPreferences and Editor
SharedPreferences sharedPref;
......@@ -15,7 +15,7 @@ public class SecondActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
setContentView(R.layout.store_layout);
TextView selection = (TextView) findViewById(R.id.ShowKey);
String key = getIntent().getStringExtra("key");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment