Browse Source

layouts

283
ThomasV 13 years ago
parent
commit
e00c656ee6
  1. 159
      client/electrum4a.py

159
client/electrum4a.py

@ -36,10 +36,20 @@ wallet.read()
def select_from_contacts():
title = 'Contacts:'
droid.dialogCreateAlert(title)
droid.dialogSetItems(wallet.addressbook)
droid.dialogShow()
response = droid.dialogGetResponse()
result = response.result.get('item')
droid.dialogDismiss()
if result is not None:
addr = wallet.addressbook[result]
return addr
def select_from_addresses():
def show_addresses():
droid.dialogCreateAlert("Addresses:") droid.dialogCreateAlert("Addresses:")
l = [] l = []
for i in range(len(wallet.addresses)): for i in range(len(wallet.addresses)):
@ -48,17 +58,19 @@ def show_addresses():
droid.dialogSetItems(l) droid.dialogSetItems(l)
droid.dialogShow() droid.dialogShow()
response = droid.dialogGetResponse().result response = droid.dialogGetResponse()
result = response.result.get('item')
droid.dialogDismiss() droid.dialogDismiss()
if result is not None:
addr = wallet.addresses[result]
return addr
# show qr code
print response
title = """ title = """
<TextView android:id="@+id/titleTextView" <TextView android:id="@+id/titleTextView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="100"
android:text="Electrum" android:text="Electrum"
android:textAppearance="?android:attr/textAppearanceLarge" android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center" android:gravity="center"
@ -109,11 +121,6 @@ def main_layout():
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/linearLayout1"> android:id="@+id/linearLayout1">
<TableRow> <TableRow>
<Button android:id="@+id/buttonHistory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="History">
</Button>
<Button android:id="@+id/buttonSend" <Button android:id="@+id/buttonSend"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -211,16 +218,38 @@ payto_layout="""<?xml version="1.0" encoding="utf-8"?>
"""%title """%title
settings_layout = """<?xml version="1.0" encoding="utf-8"?>
def make_layout(s):
return """<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background" android:id="@+id/background"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#ff000000"> android:background="#ff000000">
%s %s
%s
</LinearLayout>"""%(title,s)
receive_layout = make_layout("""
<TextView android:id="@+id/receiveTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Addr"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="left">
</TextView>""")
contacts_layout = make_layout("""
<TextView android:id="@+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contacts"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="left">
</TextView>""")
settings_layout = make_layout("""
<TextView android:id="@+id/serverTextView" <TextView android:id="@+id/serverTextView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -243,11 +272,7 @@ settings_layout = """<?xml version="1.0" encoding="utf-8"?>
android:layout_height="wrap_content" android:text="Save"></Button> android:layout_height="wrap_content" android:text="Save"></Button>
<Button android:id="@+id/buttonCancel" android:layout_width="wrap_content" <Button android:id="@+id/buttonCancel" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Cancel"></Button> android:layout_height="wrap_content" android:text="Cancel"></Button>
</LinearLayout> </LinearLayout>""")
</LinearLayout>
"""%title
@ -362,19 +387,6 @@ def update_layout():
def recipient_dialog():
title = 'Pay to:'
message = ('Select recipient')
droid.dialogCreateAlert(title, message)
droid.dialogSetItems(wallet.addressbook)
droid.dialogShow()
response = droid.dialogGetResponse()
result = response.result.get('item')
droid.dialogDismiss()
if result is not None:
addr = wallet.addressbook[result]
return addr
def pay_to(recipient, amount, fee, label): def pay_to(recipient, amount, fee, label):
@ -456,7 +468,8 @@ else:
def add_menu(): def add_menu():
droid.addOptionsMenuItem("Settings","settings",None,"") droid.addOptionsMenuItem("Network","settings",None,"")
droid.addOptionsMenuItem("New contact","newcontact",None,"")
droid.addOptionsMenuItem("Quit","quit",None,"") droid.addOptionsMenuItem("Quit","quit",None,"")
add_menu() add_menu()
@ -481,12 +494,45 @@ def main_loop():
if id=="buttonSend": if id=="buttonSend":
out = 'payto' out = 'payto'
if id=="buttonContacts":
global contact_addr
contact_addr = select_from_contacts()
if contact_addr:
out = 'contacts'
elif id=="buttonReceive": elif id=="buttonReceive":
show_addresses() global receive_addr
receive_addr = select_from_addresses()
if receive_addr:
out = 'receive'
elif event["name"]=="settings": elif event["name"]=="settings":
out = 'settings' out = 'settings'
elif event["name"]=="newcontact":
code = droid.scanBarcode()
r = code.result
if r:
address = r['extras']['SCAN_RESULT']
if address:
if wallet.is_valid(address):
droid.dialogCreateAlert('Add to contacts?', address)
droid.dialogSetPositiveButtonText('OK')
droid.dialogSetNegativeButtonText('Cancel')
droid.dialogShow()
response = droid.dialogGetResponse().result
droid.dialogDismiss()
print response
if response.get('which') == 'positive':
wallet.addressbook.append(address)
wallet.save()
else:
droid.dialogCreateAlert('Invalid address', address)
droid.dialogSetPositiveButtonText('OK')
droid.dialogShow()
response = droid.dialogGetResponse().result
droid.dialogDismiss()
elif event["name"]=="key": elif event["name"]=="key":
if event["data"]["key"] == '4': if event["data"]["key"] == '4':
out = 'quit' out = 'quit'
@ -494,11 +540,6 @@ def main_loop():
elif event["name"]=="quit": elif event["name"]=="quit":
out = 'quit' out = 'quit'
# print droid.fullSetProperty("background","backgroundColor","0xff7f0000")
# elif event["name"]=="screen":
# if event["data"]=="destroy":
# out = 'exit'
return out return out
def payto_loop(): def payto_loop():
@ -530,7 +571,7 @@ def payto_loop():
out = 'main' out = 'main'
elif id=="buttonContacts": elif id=="buttonContacts":
addr = recipient_dialog() addr = select_from_contacts()
droid.fullSetProperty("recipient","text",addr) droid.fullSetProperty("recipient","text",addr)
elif id=="buttonQR": elif id=="buttonQR":
@ -561,13 +602,17 @@ def payto_loop():
return out return out
def history_loop(): receive_addr = ''
layout = get_history_layout(15) contact_addr = ''
droid.fullShow(layout)
def receive_loop():
droid.fullShow(receive_layout)
droid.fullSetProperty("receiveTextView","text", receive_addr)
out = None out = None
while out is None: while out is None:
event = droid.eventWait().result event = droid.eventWait().result
print "got event in history loop", event print "got event", event
if event["name"] == "click": if event["name"] == "click":
if event["data"]["text"] == "OK": if event["data"]["text"] == "OK":
@ -577,12 +622,27 @@ def history_loop():
if event["data"]["key"] == '4': if event["data"]["key"] == '4':
out = 'main' out = 'main'
#elif event["name"]=="screen": return out
# if event["data"]=="destroy":
# out = 'main' def contacts_loop():
droid.fullShow(contacts_layout)
droid.fullSetProperty("contactTextView","text", contact_addr)
out = None
while out is None:
event = droid.eventWait().result
print "got event", event
if event["name"] == "click":
if event["data"]["text"] == "OK":
out = 'main'
elif event["name"]=="key":
if event["data"]["key"] == '4':
out = 'main'
return out return out
def server_dialog(plist): def server_dialog(plist):
droid.dialogCreateAlert("servers") droid.dialogCreateAlert("servers")
droid.dialogSetItems( plist.keys() ) droid.dialogSetItems( plist.keys() )
@ -593,6 +653,7 @@ def server_dialog(plist):
response = plist.keys()[i] response = plist.keys()[i]
return response return response
def protocol_dialog(plist): def protocol_dialog(plist):
options=["TCP","HTTP","native"] options=["TCP","HTTP","native"]
droid.dialogCreateAlert("Protocol") droid.dialogCreateAlert("Protocol")
@ -661,10 +722,12 @@ while True:
s = main_loop() s = main_loop()
elif s == 'payto': elif s == 'payto':
s = payto_loop() s = payto_loop()
elif s == 'receive':
s = receive_loop()
elif s == 'contacts':
s = contacts_loop()
elif s == 'settings': elif s == 'settings':
s = settings_loop() s = settings_loop()
elif s == 'history':
s = history_loop()
elif s == 'contacts': elif s == 'contacts':
s = contacts_loop() s = contacts_loop()
else: else:

Loading…
Cancel
Save