Skip to content

Commit

Permalink
Add support for HID qr code scanners to the pretixSCAN setup
Browse files Browse the repository at this point in the history
  • Loading branch information
robbi5 committed Nov 13, 2024
1 parent ecc4e9d commit 25b5eea
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.text.Editable
import android.util.Log
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import android.view.View
Expand All @@ -31,6 +33,8 @@ import org.json.JSONObject
import java.io.IOException
import java.lang.Exception
import javax.net.ssl.SSLException
import android.text.method.TextKeyListener.Capitalize
import android.text.method.TextKeyListener

class SetupActivity : AppCompatActivity(), ScannerView.ResultHandler {
lateinit var binding: ActivitySetupBinding
Expand All @@ -39,6 +43,8 @@ class SetupActivity : AppCompatActivity(), ScannerView.ResultHandler {
var lastScanValue = ""
var conf: AppConfig? = null
var currentOpenAlert: AppCompatDialog? = null
var tkl = TextKeyListener(Capitalize.NONE, false)
var keyboardEditable = Editable.Factory.getInstance().newEditable("")
private var ongoing_setup = false
private val dataWedgeHelper = DataWedgeHelper(this)
private val LOG_TAG = this::class.java.name
Expand Down Expand Up @@ -129,6 +135,25 @@ class SetupActivity : AppCompatActivity(), ScannerView.ResultHandler {
handleScan(rawResult.text)
}

override fun dispatchKeyEvent(event: KeyEvent): Boolean {
if (event.keyCode == KeyEvent.KEYCODE_ENTER) {
if (event.action == KeyEvent.ACTION_UP) {
handleScan(keyboardEditable.toString())
keyboardEditable.clear()
}
return true
}
val processed = when (event.action) {
KeyEvent.ACTION_DOWN -> tkl.onKeyDown(null, keyboardEditable, event.keyCode, event)
KeyEvent.ACTION_UP -> tkl.onKeyUp(null, keyboardEditable, event.keyCode, event)
else -> tkl.onKeyOther(null, keyboardEditable, event)
}
if (processed) {
return true
}
return super.dispatchKeyEvent(event)
}

fun handleScan(res: String) {
try {
val jd = JSONObject(res)
Expand Down

0 comments on commit 25b5eea

Please sign in to comment.