From 67145e053b5c71a5379411bbd2c83394329b5d65 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 19 Mar 2016 17:00:37 +0100 Subject: [PATCH] scan qrcodes with zxing embedded --- gui/kivy/main_window.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py index bb2caf219..637b97de5 100644 --- a/gui/kivy/main_window.py +++ b/gui/kivy/main_window.py @@ -330,6 +330,26 @@ class ElectrumWindow(App): except: self.show_error(_('Could not start Barcode Scanner.') + ' ' + _('Please install the Barcode Scanner app from ZXing')) + def scan_qr_zxing(self, on_complete): + # uses zxing embedded lib + if platform != 'android': + return + from jnius import autoclass + from android import activity + PythonActivity = autoclass('org.renpy.android.PythonActivity') + IntentIntegrator = autoclass('com.google.zxing.integration.android.IntentIntegrator') + integrator = IntentIntegrator(PythonActivity.mActivity) + def on_qr_result(requestCode, resultCode, intent): + if requestCode == 0: + if resultCode == -1: # RESULT_OK: + contents = intent.getStringExtra("SCAN_RESULT") + if intent.getStringExtra("SCAN_RESULT_FORMAT") == 'QR_CODE': + on_complete(contents) + else: + self.show_error("wrong format " + intent.getStringExtra("SCAN_RESULT_FORMAT")) + activity.bind(on_activity_result=on_qr_result) + integrator.initiateScan() + def build(self): return Builder.load_file('gui/kivy/main.kv')