Browse Source

use zxing to scan qr codes

283
ThomasV 9 years ago
parent
commit
584cc5d31f
  1. 20
      gui/kivy/main_window.py
  2. 6
      gui/kivy/uix/screens.py

20
gui/kivy/main_window.py

@ -1,6 +1,8 @@
import sys import sys
import datetime import datetime
from android import activity
from electrum import WalletStorage, Wallet from electrum import WalletStorage, Wallet
from electrum.i18n import _, set_language from electrum.i18n import _, set_language
from electrum.contacts import Contacts from electrum.contacts import Contacts
@ -206,7 +208,7 @@ class ElectrumWindow(App):
def set_url(self, instance, url): def set_url(self, instance, url):
self.gui_object.set_url(url) self.gui_object.set_url(url)
def scan_qr(self, on_complete): def old_scan_qr(self, on_complete):
dlg = Cache.get('electrum_widgets', 'QrScannerDialog') dlg = Cache.get('electrum_widgets', 'QrScannerDialog')
if not dlg: if not dlg:
dlg = Factory.QrScannerDialog() dlg = Factory.QrScannerDialog()
@ -214,6 +216,22 @@ class ElectrumWindow(App):
dlg.bind(on_complete=on_complete) dlg.bind(on_complete=on_complete)
dlg.open() dlg.open()
def scan_qr(self, on_complete):
from jnius import autoclass
PythonActivity = autoclass('org.renpy.android.PythonActivity')
Intent = autoclass('android.content.Intent')
intent = Intent("com.google.zxing.client.android.SCAN")
intent.putExtra("SCAN_MODE", "QR_CODE_MODE")
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':
uri = App.get_running_app().decode_uri(contents)
on_complete(uri)
activity.bind(on_activity_result=on_qr_result)
PythonActivity.mActivity.startActivityForResult(intent, 0)
def build(self): def build(self):
global Builder global Builder
if not Builder: if not Builder:

6
gui/kivy/uix/screens.py

@ -101,14 +101,10 @@ class MainScreen(Factory.Screen):
class ScreenSend(CScreen): class ScreenSend(CScreen):
def set_qr_data(self, dialog, uri): def set_qr_data(self, uri):
self.ids.payto_e.text = uri.get('address', '') self.ids.payto_e.text = uri.get('address', '')
self.ids.message_e.text = uri.get('message', '') self.ids.message_e.text = uri.get('message', '')
self.ids.amount_e.text = uri.get('amount', '') self.ids.amount_e.text = uri.get('amount', '')
#label = uri.get('label')
#if label:
# TODO: update label, add to contacts
class ScreenReceive(CScreen): class ScreenReceive(CScreen):
pass pass

Loading…
Cancel
Save