46 lines
1.6 KiB
Kotlin
46 lines
1.6 KiB
Kotlin
package com.github.mondei1.offpass
|
|
|
|
import android.content.Intent
|
|
import android.os.Bundle
|
|
import android.util.Log
|
|
import android.widget.Toast
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import com.google.zxing.integration.android.IntentIntegrator
|
|
import com.google.zxing.integration.android.IntentResult
|
|
import kotlinx.android.synthetic.main.activity_main.*
|
|
|
|
class MainActivity : AppCompatActivity() {
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
this.supportActionBar?.hide()
|
|
|
|
setContentView(R.layout.activity_main)
|
|
|
|
main_screen.setOnClickListener {
|
|
IntentIntegrator(this)
|
|
.setPrompt("Scan OffPass created QR-Code")
|
|
.setBeepEnabled(false)
|
|
.setBarcodeImageEnabled(false)
|
|
.initiateScan()
|
|
Log.i("Main", "Clicked on text")
|
|
}
|
|
}
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
var result: IntentResult =
|
|
IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
|
|
if (result != null) {
|
|
if (result.contents == null) {
|
|
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show()
|
|
} else {
|
|
Log.i("SCANNER", "Scanned: " + result.contents)
|
|
Toast.makeText(this, "Scanned: " + result.contents, Toast.LENGTH_LONG).show()
|
|
}
|
|
} else {
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
}
|
|
}
|
|
|
|
} |