diff --git a/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/SetupActivity.kt b/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/SetupActivity.kt index fd3f3dc..4d38ca8 100644 --- a/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/SetupActivity.kt +++ b/pretixscan/app/src/main/java/eu/pretix/pretixscan/droid/ui/SetupActivity.kt @@ -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 @@ -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 @@ -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 @@ -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)