From 07acf381666c7160ebb4c6f1a3ac5e1f2f1e1461 Mon Sep 17 00:00:00 2001 From: upcharlie <41019313+upcharlie@users.noreply.github.com> Date: Sat, 2 Mar 2019 20:39:12 +0000 Subject: [PATCH] Commit scanner project --- .gitignore | 11 ++ .idea/codeStyles/Project.xml | 29 +++ .idea/gradle.xml | 18 ++ .idea/misc.xml | 38 ++++ .idea/runConfigurations.xml | 12 ++ .idea/vcs.xml | 6 + app/.gitignore | 1 + app/build.gradle | 35 ++++ app/proguard-rules.pro | 21 +++ .../ExampleInstrumentedTest.java | 26 +++ app/src/main/AndroidManifest.xml | 36 ++++ .../nophp/attendancescanner/MainActivity.java | 167 +++++++++++++++++ .../drawable-v24/ic_launcher_foreground.xml | 34 ++++ .../res/drawable/ic_launcher_background.xml | 170 +++++++++++++++++ app/src/main/res/layout/activity_main.xml | 22 +++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2963 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4905 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2060 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2783 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4490 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6895 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6387 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10413 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9128 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15132 bytes app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 11 ++ .../attendancescanner/ExampleUnitTest.java | 17 ++ .../attendancescanner/MainActivityTest.java | 90 +++++++++ build.gradle | 27 +++ gradle.properties | 15 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes gradle/wrapper/gradle-wrapper.properties | 5 + gradlew | 172 ++++++++++++++++++ gradlew.bat | 84 +++++++++ settings.gradle | 1 + 39 files changed, 1067 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/nophp/attendancescanner/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/nophp/attendancescanner/MainActivity.java create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/nophp/attendancescanner/ExampleUnitTest.java create mode 100644 app/src/test/java/com/nophp/attendancescanner/MainActivityTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd45b12 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*.iml +.gradle +/local.properties +/.idea/caches/build_file_checksums.ser +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e0d5b93 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..92892fa --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'com.android.application' + +repositories { + jcenter() +} + +android { + compileSdkVersion 28 + + defaultConfig { + applicationId "com.nophp.attendancescanner" + minSdkVersion 22 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation 'me.dm7.barcodescanner:zxing:1.9.8' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'com.journeyapps:zxing-android-embedded:3.6.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/nophp/attendancescanner/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/nophp/attendancescanner/ExampleInstrumentedTest.java new file mode 100644 index 0000000..2428564 --- /dev/null +++ b/app/src/androidTest/java/com/nophp/attendancescanner/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.nophp.attendancescanner; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.nophp.attendancescanner", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..842b145 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/nophp/attendancescanner/MainActivity.java b/app/src/main/java/com/nophp/attendancescanner/MainActivity.java new file mode 100644 index 0000000..e2be88d --- /dev/null +++ b/app/src/main/java/com/nophp/attendancescanner/MainActivity.java @@ -0,0 +1,167 @@ +package com.nophp.attendancescanner; + +import android.app.Activity; +import android.content.Intent; +import android.os.StrictMode; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; + +import com.google.zxing.client.android.BeepManager; +import com.google.zxing.integration.android.IntentIntegrator; +import com.google.zxing.integration.android.IntentResult; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Scanner; + +public class MainActivity extends AppCompatActivity +{ + private Button scanner; + public BeepManager beep; + + @Override + protected void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + if (android.os.Build.VERSION.SDK_INT > 9) + { + StrictMode.ThreadPolicy policy = new + StrictMode.ThreadPolicy.Builder().permitAll().build(); + StrictMode.setThreadPolicy(policy); + } + + scanner = (Button) findViewById(R.id.scan); + scanner.setOnClickListener(new View.OnClickListener() + { + @Override + public void onClick(View view) { + scan(); + } + }); + scan(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) + { + beep = new BeepManager(this); + IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); + String resultString = result.getContents(); + if (resultString != null) + { + if (result.getContents() == null) + { + Toast.makeText(this, "Scanning Cancelled", Toast.LENGTH_LONG).show(); + + } + else + { + String text = "https://ziemni.me/rwp/scanner.php?qr=" + result.getContents(); + System.out.println(text); + + String textReturn = readWeb(text.toLowerCase()); + if (errorCheck(textReturn) == "Success!") + { + beep.playBeepSound(); + } + Toast.makeText(this, errorCheck(textReturn), Toast.LENGTH_LONG).show(); + + scan(); + } + } + else + { + super.onActivityResult(requestCode, resultCode, data); + } + } + + public String errorCheck(String hashed) + { + + String segments[] = hashed.split("\""); + + String text = segments[segments.length - 3]; + System.out.println(text); + + String toastMessage = "?"; + + if (text.contains("0")) + { + toastMessage = "Success!"; + } + + else if (text.contains("1")) + { + toastMessage = "Error 1: Incorrect hash"; + } + + else if (text.contains("2")) + { + toastMessage = "Error 2: Scanner ID is not an integer"; + } + + else if (text.contains("3")) + { + toastMessage = "Error 3: Issue reaching database, try again!"; + } + + else if (text.contains("4")) + { + toastMessage = "Error 4: QR code does not match"; + } + + else if (text.contains("5")) + { + toastMessage = "Error 5: QR code expired"; + } + else if (text == "FAIL") + { + toastMessage = "Error A1: Failure to establish internet connection"; + } + + return toastMessage; + } + + public void scan() + { + final Activity activity = this; + IntentIntegrator integrator = new IntentIntegrator(activity); + integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE); + integrator.setPrompt(""); + integrator.setCameraId(0); + integrator.setBeepEnabled(false); + integrator.setBarcodeImageEnabled(false); + integrator.setOrientationLocked(false); + integrator.initiateScan(); + } + + public String readWeb(String text) + { + try (Scanner scanner = new Scanner(new URL(text).openStream(), StandardCharsets.UTF_8.toString())) + { + scanner.useDelimiter("\\A"); + return scanner.hasNext() ? scanner.next() : ""; + } + catch (MalformedURLException e) + { + System.out.println("Malformed URL: " + e.getMessage()); + } + catch (IOException e) + { + System.out.println("I/O Error: " + e.getMessage()); + } + return "FAIL"; + } + +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..5f00d54 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,22 @@ + + + + + +