• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.airbnb.lottie.samples
2 
3 import android.content.Context
4 import android.content.Intent
5 import android.graphics.PointF
6 import android.os.Bundle
7 import android.os.Vibrator
8 import androidx.appcompat.app.AppCompatActivity
9 import com.airbnb.lottie.samples.model.CompositionArgs
10 import com.dlazaro66.qrcodereaderview.QRCodeReaderView
11 import kotlinx.android.synthetic.main.activity_qrscan.*
12 
13 class QRScanActivity : AppCompatActivity(), QRCodeReaderView.OnQRCodeReadListener {
<lambda>null14     private val vibrator by lazy { getSystemService(Context.VIBRATOR_SERVICE) as Vibrator }
15 
16     // Sometimes the qr code is read twice in rapid succession. This prevents it from being read
17     // multiple times.
18     private var hasReadQrCode = false
19 
onCreatenull20     override fun onCreate(savedInstanceState: Bundle?) {
21         super.onCreate(savedInstanceState)
22         setContentView(R.layout.activity_qrscan)
23 
24         qrView.setQRDecodingEnabled(true)
25         qrView.setAutofocusInterval(2000L)
26         qrView.setBackCamera()
27         qrView.setOnQRCodeReadListener(this)
28         qrView.setOnClickListener { qrView.forceAutoFocus() }
29     }
30 
onResumenull31     override fun onResume() {
32         super.onResume()
33         qrView.startCamera()
34         hasReadQrCode = false
35     }
36 
onPausenull37     override fun onPause() {
38         super.onPause()
39         qrView.stopCamera()
40     }
41 
onQRCodeReadnull42     override fun onQRCodeRead(url: String, pointFS: Array<PointF>) {
43         if (hasReadQrCode) return
44         hasReadQrCode = true
45         vibrator.vibrateCompat(100)
46         finish()
47         startActivity(PlayerActivity.intent(this, CompositionArgs(url = url)))
48     }
49 
50     companion object {
intentnull51         fun intent(context: Context) = Intent(context, QRScanActivity::class.java)
52     }
53 }