improved QR scan
This commit is contained in:
parent
67595a949d
commit
257b6b6c88
|
@ -38,6 +38,7 @@ import android.text.TextUtils
|
||||||
import android.text.TextWatcher
|
import android.text.TextWatcher
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.view.View.OnClickListener
|
import android.view.View.OnClickListener
|
||||||
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
import android.widget.AdapterView.OnItemClickListener
|
import android.widget.AdapterView.OnItemClickListener
|
||||||
import android.widget.AdapterView.OnItemSelectedListener
|
import android.widget.AdapterView.OnItemSelectedListener
|
||||||
|
@ -85,7 +86,7 @@ class QuickSearchBarActivity : BaseActivity(), OnClickListener, LoaderCallbacks<
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
hasQrScanner = run {
|
hasQrScanner = run {
|
||||||
val scanIntent = Intent(ACTION_ZXING_SCAN)
|
val scanIntent = Intent(ACTION_ZXING_SCAN)
|
||||||
scanIntent.putExtra("SCAN_MODE", "QR_CODE_MODE")
|
scanIntent.putExtra(EXTRA_ZXING_SCAN_MODE, ZXING_SCAN_MODE_QR_CODE)
|
||||||
return@run scanIntent.resolveActivity(packageManager) != null
|
return@run scanIntent.resolveActivity(packageManager) != null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,8 +173,15 @@ class QuickSearchBarActivity : BaseActivity(), OnClickListener, LoaderCallbacks<
|
||||||
when (v) {
|
when (v) {
|
||||||
searchSubmit -> {
|
searchSubmit -> {
|
||||||
if (searchQuery.empty && hasQrScanner) {
|
if (searchQuery.empty && hasQrScanner) {
|
||||||
|
val currentFocus = currentFocus
|
||||||
|
if (currentFocus === searchQuery) {
|
||||||
|
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
|
imm.hideSoftInputFromWindow(currentFocus.windowToken, 0)
|
||||||
|
currentFocus.clearFocus()
|
||||||
|
}
|
||||||
|
|
||||||
val scanIntent = Intent(ACTION_ZXING_SCAN)
|
val scanIntent = Intent(ACTION_ZXING_SCAN)
|
||||||
scanIntent.putExtra("SCAN_MODE", "QR_CODE_MODE")
|
scanIntent.putExtra(EXTRA_ZXING_SCAN_MODE, ZXING_SCAN_MODE_QR_CODE)
|
||||||
try {
|
try {
|
||||||
startActivityForResult(scanIntent, REQUEST_SCAN_QR)
|
startActivityForResult(scanIntent, REQUEST_SCAN_QR)
|
||||||
} catch (e: ActivityNotFoundException) {
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
@ -191,7 +199,7 @@ class QuickSearchBarActivity : BaseActivity(), OnClickListener, LoaderCallbacks<
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
REQUEST_SCAN_QR -> {
|
REQUEST_SCAN_QR -> {
|
||||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||||
val scanResult = data.getStringExtra("SCAN_RESULT")
|
val scanResult = data.getStringExtra(EXTRA_ZXING_SCAN_RESULT)
|
||||||
val viewIntent = Intent(Intent.ACTION_VIEW, Uri.parse(scanResult)).apply {
|
val viewIntent = Intent(Intent.ACTION_VIEW, Uri.parse(scanResult)).apply {
|
||||||
`package` = BuildConfig.APPLICATION_ID
|
`package` = BuildConfig.APPLICATION_ID
|
||||||
putExtra(EXTRA_ACCOUNT_KEY, selectedAccountDetails?.key)
|
putExtra(EXTRA_ACCOUNT_KEY, selectedAccountDetails?.key)
|
||||||
|
@ -501,6 +509,9 @@ class QuickSearchBarActivity : BaseActivity(), OnClickListener, LoaderCallbacks<
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val ACTION_ZXING_SCAN = "com.google.zxing.client.android.SCAN"
|
const val ACTION_ZXING_SCAN = "com.google.zxing.client.android.SCAN"
|
||||||
|
const val EXTRA_ZXING_SCAN_MODE = "SCAN_MODE"
|
||||||
|
const val EXTRA_ZXING_SCAN_RESULT = "SCAN_RESULT"
|
||||||
|
const val ZXING_SCAN_MODE_QR_CODE = "QR_CODE_MODE"
|
||||||
const val REQUEST_SCAN_QR = 101
|
const val REQUEST_SCAN_QR = 101
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue