diff --git a/client/electrum4a.py b/client/electrum4a.py index bc96173c5..cedcbb137 100755 --- a/client/electrum4a.py +++ b/client/electrum4a.py @@ -18,6 +18,7 @@ + import android from interface import WalletSynchronizer from wallet import Wallet @@ -102,50 +103,15 @@ def protocol_dialog(host, z): return host + ':' + port + ':' + p -def qr_code_layout(addr): - return """ - - QR code - - - - - - -
-
- - -
- -
- -"""%addr - - -title = """ -""" - -def make_layout(s, scrollable): + +def make_layout(s, scrollable = False): content = """ - - + %s """%s @@ -208,6 +174,25 @@ def main_layout(): +def qr_layout(addr): + return make_layout(""" + + + + + """%addr) + payto_layout = make_layout(""" """% rows return output + def set_history_layout(n): values = get_history_values(n) i = 0 @@ -412,7 +398,6 @@ def set_history_layout(n): droid.fullSetProperty("hl_%d_col2"%i,"text", b) droid.fullSetProperty("hl_%d_col3"%i,"text", c) droid.fullSetProperty("hl_%d_col4"%i,"text", d) - i += 1 @@ -634,7 +619,10 @@ def receive_loop(): while out is None: event = droid.eventWait().result print "got event", event - out = 'main' + if event["name"]=="key": + if event["data"]["key"] == '4': + out = 'main' + return out def contacts_loop(): @@ -642,7 +630,10 @@ def contacts_loop(): while out is None: event = droid.eventWait().result print "got event", event - out = 'main' + if event["name"]=="key": + if event["data"]["key"] == '4': + out = 'main' + return out @@ -811,40 +802,62 @@ def add_menu(s): droid.addOptionsMenuItem("Password","password",None,"") droid.addOptionsMenuItem("Seed","seed",None,"") - - +def make_bitmap(addr): + # fixme: this is highly innefficient + droid.dialogCreateSpinnerProgress("please wait") + droid.dialogShow() + import pyqrnative, bmp + qr = pyqrnative.QRCode(4, pyqrnative.QRErrorCorrectLevel.H) + qr.addData(addr) + qr.make() + k = qr.getModuleCount() + bitmap = bmp.BitMap( 350, 350 ) + print len(bitmap.bitarray) + bitmap.bitarray = [] + assert k == 33 + + for r in range(35): + tmparray = [ 0 ] * 350 + + if 0 < r < 34: + for c in range(k): + if qr.isDark(r-1, c): + tmparray[ (1+c)*10:(1+c)*10 + 10] = [1]*10 + + for i in range(10): + bitmap.bitarray.append( tmparray[:] ) + + bitmap.saveFile( "/sdcard/sl4a/qrcode.bmp" ) + droid.dialogDismiss() + while True: add_menu(s) if s == 'main': droid.fullShow(main_layout()) s = main_loop() - droid.fullDismiss() + #droid.fullDismiss() elif s == 'send': droid.fullShow(payto_layout) s = payto_loop() - droid.fullDismiss() + #droid.fullDismiss() elif s == 'receive': - f = open('/sdcard/sl4a/scripts/recv.html',"w") - f.write(qr_code_layout(receive_addr)) - f.close() - wvs = droid.webViewShow("file:///sdcard/sl4a/scripts/recv.html") + make_bitmap(receive_addr) + droid.fullShow(qr_layout(receive_addr)) s = receive_loop() elif s == 'contacts': - f = open('/sdcard/sl4a/scripts/recv.html',"w") - f.write(qr_code_layout(contact_addr)) - f.close() - droid.webViewShow("file:///sdcard/sl4a/scripts/recv.html") + make_bitmap(contact_addr) + droid.fullShow(qr_layout(contact_addr)) s = contacts_loop() elif s == 'settings': droid.fullShow(settings_layout) s = settings_loop() - droid.fullDismiss() + #droid.fullDismiss() else: break