Skip to content

Instantly share code, notes, and snippets.

@spritle
Created October 15, 2012 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spritle/3892292 to your computer and use it in GitHub Desktop.
Save spritle/3892292 to your computer and use it in GitHub Desktop.
Scanner Code
#application.rb
# Avoid, the scanner gets auto started when device starts up.
# Avoid, the scanner gets auto started when application start.
def on_activate_app
begin
Scanner.stop
rescue
end
end
#app/layout.erb
<meta http-equiv="PowerOn" content="PowerOnEvent:url('/app/TransferDetail/stop_scanner')">
# In controller's we use
def activate_scanner
Scanner.enabled = "SCN2"
# Only a sample code, the actual callback event method is controller and context specific.
Scanner.decodeEvent = "/app/TransferDetail/take_barcode_callback?hardware_scan=false"
end
# This will be called after we call activate_scanner method
# The method set_scanner_status will toggle "start" and "stop". This is used by "soft button".
def set_scanner_status
if Rho::RhoConfig.SCANNER_STATUS == "0" || Rho::RhoConfig.SCANNER_STATUS == ""
Scanner.start
WebView.execute_js("toggleScannerUI(1)")
Rho::RhoConfig.SCANNER_STATUS = "1"
else
Scanner.stop
WebView.execute_js("toggleScannerUI(0)")
Rho::RhoConfig.SCANNER_STATUS = "0"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment