This commit is contained in:
Rumperuu 2018-09-15 16:32:24 +01:00
parent a01d4b81c7
commit 0c350c8553
5 changed files with 53 additions and 10 deletions

View File

@ -25,7 +25,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -16,9 +16,8 @@ class BallotVerifyActivity : AppCompatActivity() {
val extras = intent.extras
if (extras != null) {
val ballotHandle = extras.getString("ballotHandle")
val myWebView: WebView = findViewById(R.id.webview)
// myWebView.loadUrl("http://127.0.0.1:8000/event/audit?handle=$ballotHandle")
myWebView.loadUrl("https://en.wikipedia.org/")
val myWebView: WebView = findViewById<WebView>(R.id.webview)
myWebView.loadUrl("http://elections.lancaster.ac.uk:8000/event/audit?handle=$ballotHandle")
myWebView.settings.javaScriptEnabled = true
}

View File

@ -4,13 +4,9 @@ import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.TextView
import uk.ac.lancaster.auditor.barcode.BarcodeScanActivity
class MainActivity : AppCompatActivity() {
private lateinit var mResultTextView: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

View File

@ -2,10 +2,14 @@ package uk.ac.lancaster.auditor.barcode
import android.content.Intent
import android.os.Bundle
import android.os.Environment
import android.support.v7.app.AppCompatActivity
import android.util.Base64
import android.util.Log
import android.widget.Button
import android.widget.TextView
import java.io.File
import java.io.FileWriter
import com.google.android.gms.common.api.CommonStatusCodes
import com.google.android.gms.vision.barcode.Barcode
import uk.ac.lancaster.auditor.BallotVerifyActivity
@ -33,12 +37,50 @@ class BarcodeScanActivity : AppCompatActivity() {
if (resultCode == CommonStatusCodes.SUCCESS) {
if (data != null) {
val barcode = data.getParcelableExtra<Barcode>(BarcodeCaptureActivity.BarcodeObject)
val p = barcode.cornerPoints
mResultTextView.text = barcode.displayValue
val handle = barcode.displayValue.split(";")[0]
val hmac = String(Base64.decode(barcode.displayValue.split(";")[1], Base64.DEFAULT))
// save the ballot
if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
val dir = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "ballots")
if (!dir?.mkdirs()) {
Log.e(LOG_TAG, "Directory not created")
}
val ballotFile = File(dir, "$handle.ballot")
if (ballotFile.exists()) {
ballotFile.delete()
}
try {
val out = FileWriter(ballotFile)
out.write(handle)
out.flush()
out.close()
} catch (e: Exception) {
e.printStackTrace()
}
val hmacFile = File(dir, "$handle.hmac")
if (hmacFile.exists()) {
hmacFile.delete()
}
try {
val out = FileWriter(hmacFile)
out.write(hmac)
out.flush()
out.close()
} catch (e: Exception) {
e.printStackTrace()
}
}
//if some test of the QR = ballot handle
val intent = Intent(baseContext, BallotVerifyActivity::class.java)
intent.putExtra("ballotHandle", barcode.displayValue)
intent.putExtra("ballotHandle", handle)
startActivity(intent)
} else
mResultTextView.setText(R.string.no_barcode_captured)