From a013eb3243639105c154a9844341c5a1657f1773 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Wed, 4 Dec 2019 17:03:00 -0600 Subject: [PATCH] Created UI for login screen --- app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 25 +++-- .../concert_android/LoginActivity.java | 106 ++++++++++++++++++ .../example/concert_android/MainActivity.java | 14 --- .../{activity_main.xml => activity_login.xml} | 3 +- 5 files changed, 125 insertions(+), 25 deletions(-) create mode 100644 app/src/main/java/com/example/concert_android/LoginActivity.java delete mode 100644 app/src/main/java/com/example/concert_android/MainActivity.java rename app/src/main/res/layout/{activity_main.xml => activity_login.xml} (97%) diff --git a/app/build.gradle b/app/build.gradle index 176f388..f62854d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,4 +27,6 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + + implementation 'com.android.volley:volley:1.1.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7c95576..89e9095 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,23 +1,30 @@ + + + - - + android:theme="@style/AppTheme" + tools:ignore="GoogleAppIndexingWarning"> + + + + + + + + + - - - diff --git a/app/src/main/java/com/example/concert_android/LoginActivity.java b/app/src/main/java/com/example/concert_android/LoginActivity.java new file mode 100644 index 0000000..639b71c --- /dev/null +++ b/app/src/main/java/com/example/concert_android/LoginActivity.java @@ -0,0 +1,106 @@ +package com.example.concert_android; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import com.android.volley.AuthFailureError; +import com.android.volley.Network; +import com.android.volley.NetworkResponse; +import com.android.volley.Request; +import com.android.volley.RequestQueue; +import com.android.volley.Response; +import com.android.volley.VolleyError; +import com.android.volley.VolleyLog; +import com.android.volley.toolbox.HttpHeaderParser; +import com.android.volley.toolbox.JsonObjectRequest; +import com.android.volley.toolbox.StringRequest; +import com.android.volley.toolbox.Volley; + +import org.json.JSONObject; + +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.Map; + +public class LoginActivity extends AppCompatActivity { + + private static final String TAG = "login"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + + final Button loginButton = findViewById(R.id.button); + loginButton.setOnClickListener(new View.OnClickListener() { + public void onClick(final View v) { + Log.d(TAG, "button clicked"); + String inputUsername = ((EditText)findViewById(R.id.username)).getText().toString(); + String inputPassword = ((EditText)findViewById(R.id.password)).getText().toString(); + callvolley(inputUsername, inputPassword); + //startAPICall(); + } + }); + } + + void startAPICall() { + try { + RequestQueue requestQueue = Volley.newRequestQueue(this); + String URL = "https://concert.acm.illinois.edu/login"; + JSONObject jsonBody = new JSONObject(); + jsonBody.put("username", ((EditText)findViewById(R.id.username)).getText().toString()); + jsonBody.put("password", ((EditText)findViewById(R.id.password)).getText().toString()); + final String requestBody = jsonBody.toString(); + + StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener() { + @Override + public void onResponse(String response) { + Log.i("VOLLEY", response); + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + Log.e("VOLLEY", error.toString()); + } + }) + ; + requestQueue.add(stringRequest); + } catch(Exception e) { + e.printStackTrace(); + } + } + + public void callvolley(final String username, final String password){ + RequestQueue MyRequestQueue = Volley.newRequestQueue(this); + String url = "https://concert.acm.illinois.edu/login"; // <----enter your post url here + StringRequest MyStringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener() { + @Override + 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. + Log.i("VOLLEY", response); + } + }, new Response.ErrorListener() { //Create an error listener to handle errors appropriately. + @Override + public void onErrorResponse(VolleyError error) { + //This code is executed if there is an error. + Log.e("VOLLEY", error.toString()); + } + }) { + protected Map getInputParams() { + Map MyData = new HashMap(); + MyData.put("username", username); + MyData.put("password", password); + return MyData; + } + }; + + + MyRequestQueue.add(MyStringRequest); + } +} diff --git a/app/src/main/java/com/example/concert_android/MainActivity.java b/app/src/main/java/com/example/concert_android/MainActivity.java deleted file mode 100644 index 06c6204..0000000 --- a/app/src/main/java/com/example/concert_android/MainActivity.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.example.concert_android; - -import androidx.appcompat.app.AppCompatActivity; - -import android.os.Bundle; - -public class MainActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - } -} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_login.xml similarity index 97% rename from app/src/main/res/layout/activity_main.xml rename to app/src/main/res/layout/activity_login.xml index 3ddb9de..54a6794 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -3,8 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" - tools:context=".MainActivity"> + android:layout_height="match_parent">