diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..c5f3f6b
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "java.configuration.updateBuildConfiguration": "interactive"
+}
\ No newline at end of file
diff --git a/MobileApp/app/build.gradle b/MobileApp/app/build.gradle
index 3c5ce5d..94cf0fe 100644
--- a/MobileApp/app/build.gradle
+++ b/MobileApp/app/build.gradle
@@ -14,6 +14,10 @@ android {
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+
+ Properties properties = new Properties()
+ properties.load(project.rootProject.file('local.properties').newDataInputStream())
+ buildConfigField "String", "SERVER_URL", "\"" + properties.getProperty('server_url') + "\""
}
buildTypes {
diff --git a/MobileApp/app/src/main/AndroidManifest.xml b/MobileApp/app/src/main/AndroidManifest.xml
index 0176b25..e76e9e1 100644
--- a/MobileApp/app/src/main/AndroidManifest.xml
+++ b/MobileApp/app/src/main/AndroidManifest.xml
@@ -1,18 +1,23 @@
+
+
+
@@ -22,10 +27,11 @@
-
+ android:theme="@style/zxing_CaptureTheme" />
\ No newline at end of file
diff --git a/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/MainActivity.java b/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/MainActivity.java
index 56b1a6d..2af43a0 100644
--- a/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/MainActivity.java
+++ b/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/MainActivity.java
@@ -3,44 +3,30 @@
import androidx.activity.result.ActivityResultLauncher;
import androidx.appcompat.app.AppCompatActivity;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
-import android.os.AsyncTask;
+import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
-import android.util.Log;
import android.view.View;
import android.widget.Button;
-import android.widget.EditText;
-import android.widget.Toast;
import com.journeyapps.barcodescanner.ScanContract;
import com.journeyapps.barcodescanner.ScanOptions;
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.Arrays;
-
public class MainActivity extends AppCompatActivity {
- Button scanBtn,submitBtn;
+ Button scanBtn;
+
+ Context context;
String token;
- EditText urlInput, server;
- ActivityResultLauncher barLaucher = registerForActivityResult(new ScanContract(), result->
+ ActivityResultLauncher barLauncher = registerForActivityResult(new ScanContract(), result->
{
if(result.getContents() !=null)
{
token = result.getContents();
- Log.i("TOKEN", "token: "+token);
- urlInput.setVisibility(View.VISIBLE);
- submitBtn.setVisibility(View.VISIBLE);
- server.setVisibility(View.VISIBLE);
- scanBtn.setVisibility(View.GONE);
+
+ Intent intent = new Intent(context, RedirectionActivity.class);
+ intent.putExtra("token",token);
+ context.startActivity(intent);
}else {
token = null;
@@ -51,14 +37,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+ context = this;
scanBtn = findViewById(R.id.scanbtn);
- submitBtn = findViewById(R.id.submit);
- urlInput = findViewById(R.id.urlInput);
- server = findViewById(R.id.server);
- submitBtn.setVisibility(View.GONE);
- urlInput.setVisibility(View.GONE);
- server.setVisibility(View.GONE);
scanBtn.setOnClickListener(new View.OnClickListener() {
@Override
@@ -67,14 +48,7 @@ public void onClick(View view) {
}
});
- submitBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (urlInput.getText().toString().length() != 0){ //needs improvement
- sendUrl(urlInput.getText().toString());
- }
- }
- });
+
}
private void scanQrCode()
@@ -83,64 +57,10 @@ private void scanQrCode()
options.setBeepEnabled(true);
options.setOrientationLocked(true);
options.setCaptureActivity(CaptureAct.class);
- barLaucher.launch(options);
+ barLauncher.launch(options);
}
- private void sendUrl(String url){
- if (token != null && server.getText().toString().length() != 0){
- MyTask task = new MyTask();
- task.execute(url);
- }else {
- Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG);
- }
- }
- private class MyTask extends AsyncTask {
- protected String doInBackground(String... params) {
- String responseBody;
- try {
- URL endpoint = new URL("http://"+server.getText().toString()+"/api");
- HttpURLConnection connection = (HttpURLConnection) endpoint.openConnection();
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type", "application/json");
- connection.setDoOutput(true);
-
- String requestBody = "{\"token\":\"" + token + "\", \"url\":\"" + params[0] + "\"}";
-
- OutputStream outputStream = connection.getOutputStream();
- outputStream.write(requestBody.getBytes());
- outputStream.flush();
- outputStream.close();
-
- int responseCode = connection.getResponseCode();
- if (responseCode == HttpURLConnection.HTTP_OK) {
- InputStream inputStream = connection.getInputStream();
- responseBody = readStream(inputStream);
- inputStream.close();
- } else {
- responseBody = "HTTP Error: " + responseCode;
- }
- connection.disconnect();
- } catch (Exception e) {
- responseBody = e.toString();
-
- }
- return responseBody;
- }
- private String readStream(InputStream inputStream) throws IOException {
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int bytesRead = 0;
- while ((bytesRead = inputStream.read(buffer)) != -1) {
- outputStream.write(buffer, 0, bytesRead);
- }
- return outputStream.toString();
- }
- protected void onPostExecute(String result) {
- Log.i("received", "message: "+result);
- }
- }
-
}
\ No newline at end of file
diff --git a/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/RedirectionActivity.java b/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/RedirectionActivity.java
new file mode 100644
index 0000000..86202ce
--- /dev/null
+++ b/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/RedirectionActivity.java
@@ -0,0 +1,166 @@
+package com.qrcodecopier.qrscanner;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.annotation.SuppressLint;
+import android.graphics.Color;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.util.Log;
+import android.util.Pair;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.qrcodecopier.qrscanner.utils.MyProperties;
+import com.qrcodecopier.qrscanner.utils.Utils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+public class RedirectionActivity extends AppCompatActivity {
+
+ Button submitBtn;
+ EditText urlInput;
+
+ TextView alertText, resultText;
+
+ String token;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_redirection);
+
+ submitBtn = findViewById(R.id.submit);
+ urlInput = findViewById(R.id.urlInput);
+ alertText = findViewById(R.id.alertmsg);
+ resultText = findViewById(R.id.resultmsg);
+
+
+ if (getIntent().hasExtra("token")){
+ processToken(getIntent().getStringExtra("token"));
+ }else {
+ processToken(null);
+ }
+
+ submitBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ String input = urlInput.getText().toString();
+ if (input.length() != 0){ //needs improvement
+ if (verifyUrl(input))
+ sendUrl(input);
+ }
+ }
+ });
+ }
+
+ private void showResult(String msg,boolean positive){
+ resultText.setText(msg);
+ if (positive){
+ resultText.setTextColor(Color.BLACK);
+ resultText.setBackgroundColor(Color.parseColor("#89FC00"));
+ }else {
+ resultText.setTextColor(Color.WHITE);
+ resultText.setBackgroundColor(Color.parseColor("#DC0073"));
+ }
+ }
+ private boolean verifyUrl(String url){
+ String regex = "^((http|https)://)?(www\\.)?[a-zA-Z0-9]+(\\.[a-zA-Z]{2,})+(/.*)?$";
+ return url.matches(regex);
+ }
+ private void processToken(String token){
+ String positiveMsg=getResources().getString(R.string.positive_msg);
+ String negativeMsg=getResources().getString(R.string.negative_msg);
+ if (token == null || notAsExpected(token)){
+ this.token = null;
+ alertText.setText(negativeMsg);
+ alertText.setTextColor(Color.WHITE);
+ alertText.setBackgroundColor(Color.parseColor("#DC0073"));
+ }else{
+ this.token = token;
+ alertText.setText(positiveMsg);
+ alertText.setTextColor(Color.BLACK);
+ alertText.setBackgroundColor(Color.parseColor("#89FC00"));
+ }
+ }
+
+ private boolean notAsExpected(String token){
+ return token.contains(" ;)({}:");
+ }
+ private void sendUrl(String url){
+ if (token != null){
+ MyTask task = new MyTask();
+ task.execute(url);
+ }else {
+ String error= "Error: No token included";
+ showResult(error,false);
+ }
+
+
+ }
+
+ @SuppressLint("StaticFieldLeak")
+ private class MyTask extends AsyncTask> {
+
+ MyProperties properties = MyProperties.getInstance();
+ protected Pair doInBackground(String... params) {
+ String responseBody;
+ boolean success = true;
+ try {
+ URL endpoint = new URL(properties.getServerURl());
+ HttpURLConnection connection = (HttpURLConnection) endpoint.openConnection();
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Content-Type", "application/json");
+ connection.setDoOutput(true);
+
+ String requestBody = Utils.buildRequestBody(token,params[0]);
+
+ OutputStream outputStream = connection.getOutputStream();
+ outputStream.write(requestBody.getBytes());
+ outputStream.flush();
+ outputStream.close();
+
+ int responseCode = connection.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK) {
+ InputStream inputStream = connection.getInputStream();
+ responseBody="Done. ";
+ responseBody += readStream(inputStream);
+ inputStream.close();
+ } else {
+ responseBody = "HTTP Error: " + responseCode;
+ success = false;
+ }
+ connection.disconnect();
+ } catch (Exception e) {
+ responseBody = e.toString();
+ success = false;
+
+ }
+ return new Pair<>(responseBody,success);
+ }
+ private String readStream(InputStream inputStream) throws IOException {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int bytesRead = 0;
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, bytesRead);
+ }
+ return outputStream.toString();
+ }
+ protected void onPostExecute(Pair result) {
+ showResult(result.first,result.second);
+ }
+ }
+}
\ No newline at end of file
diff --git a/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/utils/MyProperties.java b/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/utils/MyProperties.java
new file mode 100644
index 0000000..7ca0258
--- /dev/null
+++ b/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/utils/MyProperties.java
@@ -0,0 +1,29 @@
+package com.qrcodecopier.qrscanner.utils;
+
+import com.qrcodecopier.qrscanner.BuildConfig;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Properties;
+
+public class MyProperties {
+
+ Properties properties;
+
+ private static MyProperties instance;
+
+ private MyProperties(){
+ }
+
+ public static MyProperties getInstance(){
+ if (instance == null)
+ instance = new MyProperties();
+ return instance;
+ }
+
+ public String getServerURl(){
+ return BuildConfig.SERVER_URL;
+ }
+}
diff --git a/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/utils/Utils.java b/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/utils/Utils.java
new file mode 100644
index 0000000..7974f87
--- /dev/null
+++ b/MobileApp/app/src/main/java/com/qrcodecopier/qrscanner/utils/Utils.java
@@ -0,0 +1,10 @@
+package com.qrcodecopier.qrscanner.utils;
+
+public final class Utils {
+
+ private Utils(){}
+
+ public static String buildRequestBody(String token, String url){
+ return "{\"token\":\"" + token + "\", \"url\":\"" + url + "\"}";
+ }
+}
diff --git a/MobileApp/app/src/main/res/drawable/qr_code.png b/MobileApp/app/src/main/res/drawable/qr_code.png
new file mode 100644
index 0000000..4485fed
Binary files /dev/null and b/MobileApp/app/src/main/res/drawable/qr_code.png differ
diff --git a/MobileApp/app/src/main/res/drawable/qr_img.png b/MobileApp/app/src/main/res/drawable/qr_img.png
new file mode 100644
index 0000000..368072b
Binary files /dev/null and b/MobileApp/app/src/main/res/drawable/qr_img.png differ
diff --git a/MobileApp/app/src/main/res/layout/activity_main.xml b/MobileApp/app/src/main/res/layout/activity_main.xml
index 853d5bf..f5ac100 100644
--- a/MobileApp/app/src/main/res/layout/activity_main.xml
+++ b/MobileApp/app/src/main/res/layout/activity_main.xml
@@ -1,46 +1,51 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+
+
+
+
\ No newline at end of file
diff --git a/MobileApp/app/src/main/res/layout/activity_redirection.xml b/MobileApp/app/src/main/res/layout/activity_redirection.xml
new file mode 100644
index 0000000..4ad6099
--- /dev/null
+++ b/MobileApp/app/src/main/res/layout/activity_redirection.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MobileApp/app/src/main/res/values-night/themes.xml b/MobileApp/app/src/main/res/values-night/themes.xml
index c25d85a..cee34e5 100644
--- a/MobileApp/app/src/main/res/values-night/themes.xml
+++ b/MobileApp/app/src/main/res/values-night/themes.xml
@@ -1,13 +1,13 @@
-