Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

Commit

Permalink
feat: added cancel for ux (#198)
Browse files Browse the repository at this point in the history
* feat: added cancel for ux

* re(feat): apply cancel functionality to merged

* fix: return true

* fix(syntax): flashButton and cancelButton

* fix: syntax
  • Loading branch information
iRaySpace committed Apr 20, 2020
1 parent 228ec10 commit a6af2f5
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler {

companion object {
const val TOGGLE_FLASH = 200
const val CANCEL = 300
const val EXTRA_CONFIG = "config"
const val EXTRA_RESULT = "scan_result"
const val EXTRA_ERROR_CODE = "error_code"
Expand Down Expand Up @@ -76,8 +77,12 @@ class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler {
if (scannerView?.flash == true) {
buttonText = config.stringsMap["flash_off"]
}
val item = menu.add(0, TOGGLE_FLASH, 0, buttonText)
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
val flashButton = menu.add(0, TOGGLE_FLASH, 0, buttonText)
flashButton.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)

val cancelButton = menu.add(0, CANCEL, 0, config.stringsMap["cancel"])
cancelButton.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)

return super.onCreateOptionsMenu(menu)
}

Expand All @@ -87,6 +92,11 @@ class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler {
this.invalidateOptionsMenu()
return true
}
if (item.itemId == CANCEL) {
setResult(RESULT_CANCELED)
finish()
return true
}
return super.onOptionsItemSelected(item)
}

Expand Down Expand Up @@ -151,4 +161,4 @@ class BarcodeScannerActivity : Activity(), ZXingScannerView.ResultHandler {

return types
}
}
}

0 comments on commit a6af2f5

Please sign in to comment.