commit 0d92b907d2b0e6880ce0845381d2353e3bc99e94
parent 341d192dce3a61838f539c659c9e0441442511d9
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 29 Jan 2026 12:27:15 +0000
port android/termux client to use eculocate module
Diffstat:
| M | client/android.py | | | 119 | ++++++++++++++++++++++++++++--------------------------------------------------- |
1 file changed, 42 insertions(+), 77 deletions(-)
diff --git a/client/android.py b/client/android.py
@@ -1,89 +1,26 @@
#!/data/data/com.termux/files/usr/bin/python
+import eculocate
import termuxgui as tg
+import threading
import time
import sys
-import socket
-import threading
-import select
-import datetime
-from pathlib import Path
-import os
-from zeroconf import ServiceBrowser, ServiceListener, Zeroconf
-
-import eculocate
-
-peer_hostname = None
-peer_thread = None
-bytes_recorded = 0
-
-started = False
-
hosts = {}
-host_addresses = {}
-
-zeroconf = Zeroconf()
-
-
-def output_pathname():
- dir = Path("/storage") / "emulated" / "0" / "eculocate"
- dir.mkdir(0o777, False, True)
- name = f"{int(time.time())}.raw"
- return dir / name
def add_host(activity, name, parent):
- selected = (peer_hostname == name)
- if selected:
- label = f"* {name}"
- else:
- label = name
- button = tg.Button(activity, label, parent)
+ button = tg.Button(activity, "?", parent)
button.setlinearlayoutparams(0)
button.setheight(tg.View.WRAP_CONTENT)
hosts[name] = button
+ return button
with tg.Connection() as c:
- # create a new Activity. By default, a new Task as created.
a = tg.Activity(c)
- # you can find the Task under a.t
-
- def choose_hostname(hostname):
- global peer_hostname
- if hostname == None:
- started = False
- peer_hostname = hostname
- refresh_buttons()
-
- def refresh_buttons():
- for name, widget in hosts.items():
- if name == peer_hostname:
- label = f"* {name}"
- else:
- label = name
- widget.settext(label)
- if peer_hostname == None:
- start_button.settext("----")
- else:
- start_button.settext("STOP" if started else "START")
-
-
- def start_recording(start_or_stop):
- global started
- if start_or_stop and peer_hostname != None:
- started = True
- print("starting record")
- peer_thread = threading.Thread(eculocate.recorder, daemon = True)
- peer_thread.start()
- else:
- print("stopping record")
- started = False
-
vertical = tg.LinearLayout(a)
instances = tg.LinearLayout(a, vertical)
- browser = ServiceBrowser(zeroconf, "_keihin._udp.local.", ZListener(a, instances))
tg.Space(a, vertical)
@@ -99,17 +36,45 @@ with tg.Connection() as c:
# start_button.setwidth(tg.View.WRAP_CONTENT)
start_button.setgravity(1, 1)
+ def repaint(client):
+ if client.selected_service_name == None:
+ start_button.settext("----")
+ else:
+ start_button.settext("STOP" if client.started else "START")
+
+ class GuiClient(eculocate.Client):
+ def on_services_changed(self):
+ for name, service in self.host_addresses.items():
+ widget = hosts.get(name, None)
+ if widget == None:
+ widget = add_host(a, name, instances)
+ if name == self.selected_service_name:
+ label = f"* {name}"
+ else:
+ label = name
+ widget.settext(label)
+ print("hosts")
+ print(hosts)
+ repaint(self)
+
+ def fake_host_add(self):
+ self.host_addresses = {
+ 'Bike3._keihin._udp.local.': ('192.168.8.125', 5002)
+ }
+ self.on_services_changed()
+
+ def __init__(self):
+ super().__init__()
+ threading.Thread(target = self.fake_host_add, daemon = True).start()
+
+
+ client = GuiClient()
+
def update_byte_counter():
- global started
while True:
- label = f"recorded {bytes_recorded} bytes" if started else "not recording"
+ label = f"recorded {client.bytes_recorded} bytes" if client.started else "not recording"
status.settext(label)
time.sleep(1)
- for host, button in hosts.items():
- if button == 0:
- button.delete()
- elif button == None:
- add_host(a, host, instances)
threading.Thread(target = update_byte_counter, daemon = True).start()
@@ -119,7 +84,7 @@ with tg.Connection() as c:
if ev.type == tg.Event.click:
for k, v in hosts.items():
if v == ev.value["id"]:
- choose_hostname(k)
+ client.select_service_name(k)
if ev.value["id"] == start_button:
- start_recording(not started)
- refresh_buttons()
+ client.stop_recording() if client.started else client.start_recording()
+ repaint(client)