Update
This commit is contained in:
parent
a01d4b81c7
commit
0c350c8553
5 changed files with 53 additions and 10 deletions
|
@ -25,7 +25,7 @@
|
||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</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" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal 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>
|
|
@ -16,9 +16,8 @@ class BallotVerifyActivity : AppCompatActivity() {
|
||||||
val extras = intent.extras
|
val extras = intent.extras
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
val ballotHandle = extras.getString("ballotHandle")
|
val ballotHandle = extras.getString("ballotHandle")
|
||||||
val myWebView: WebView = findViewById(R.id.webview)
|
val myWebView: WebView = findViewById<WebView>(R.id.webview)
|
||||||
// myWebView.loadUrl("http://127.0.0.1:8000/event/audit?handle=$ballotHandle")
|
myWebView.loadUrl("http://elections.lancaster.ac.uk:8000/event/audit?handle=$ballotHandle")
|
||||||
myWebView.loadUrl("https://en.wikipedia.org/")
|
|
||||||
myWebView.settings.javaScriptEnabled = true
|
myWebView.settings.javaScriptEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,9 @@ import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.TextView
|
|
||||||
import uk.ac.lancaster.auditor.barcode.BarcodeScanActivity
|
import uk.ac.lancaster.auditor.barcode.BarcodeScanActivity
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var mResultTextView: TextView
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
|
@ -2,10 +2,14 @@ package uk.ac.lancaster.auditor.barcode
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Environment
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
|
import android.util.Base64
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.TextView
|
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.common.api.CommonStatusCodes
|
||||||
import com.google.android.gms.vision.barcode.Barcode
|
import com.google.android.gms.vision.barcode.Barcode
|
||||||
import uk.ac.lancaster.auditor.BallotVerifyActivity
|
import uk.ac.lancaster.auditor.BallotVerifyActivity
|
||||||
|
@ -33,12 +37,50 @@ class BarcodeScanActivity : AppCompatActivity() {
|
||||||
if (resultCode == CommonStatusCodes.SUCCESS) {
|
if (resultCode == CommonStatusCodes.SUCCESS) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
val barcode = data.getParcelableExtra<Barcode>(BarcodeCaptureActivity.BarcodeObject)
|
val barcode = data.getParcelableExtra<Barcode>(BarcodeCaptureActivity.BarcodeObject)
|
||||||
val p = barcode.cornerPoints
|
|
||||||
mResultTextView.text = barcode.displayValue
|
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
|
//if some test of the QR = ballot handle
|
||||||
val intent = Intent(baseContext, BallotVerifyActivity::class.java)
|
val intent = Intent(baseContext, BallotVerifyActivity::class.java)
|
||||||
intent.putExtra("ballotHandle", barcode.displayValue)
|
intent.putExtra("ballotHandle", handle)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
} else
|
} else
|
||||||
mResultTextView.setText(R.string.no_barcode_captured)
|
mResultTextView.setText(R.string.no_barcode_captured)
|
||||||
|
|
Reference in a new issue