Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created UI for login screen #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
25 changes: 16 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.concert_android">

<uses-permission android:name="android.permission.INTERNET" />


<application
tools:ignore="GoogleAppIndexingWarning"
android:fullBackupContent="true"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/appname"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MusicActivity"><intent-filter>
<action android:name="android.intent.action.MAIN" />
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".MusicActivity">

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter></activity>
<activity android:name=".MainActivity">
</activity>
</application>

Expand Down
106 changes: 106 additions & 0 deletions app/src/main/java/com/example/concert_android/LoginActivity.java
Original file line number Diff line number Diff line change
@@ -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<String>() {
@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<String>() {
@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<String, String> getInputParams() {
Map<String, String> MyData = new HashMap<String, String>();
MyData.put("username", username);
MyData.put("password", password);
return MyData;
}
};


MyRequestQueue.add(MyStringRequest);
}
}
14 changes: 0 additions & 14 deletions app/src/main/java/com/example/concert_android/MainActivity.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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">

<TextView
android:layout_width="wrap_content"
Expand Down