hrm/hrm/os_android.go
Greg Pomerantz 689990639d Migrate to gioui.org v0.10.2; fix Android BLE flow, rendering, and circle.
Main changes:
- go.mod: gioui.org v0.10.2, go 1.24, git.wow.st/gmp/ble
  e53c7be (commitNowAllowingStateLoss + BLUETOOTH_SCAN/CONNECT
  permission request from BlessedConnect.onAttach).
- main.go: ported to the v0.10 API (app.Main + single-goroutine
  event loop, app.FrameEvent.Frame, material.* styles, op.Offset/
  Affine, clip.Path for the circle).
- On-demand rendering: no fixed 30 FPS ticker redraws. Frames are
  produced by Bluetooth events and input; 30 FPS only while the live
  stopwatch runs. The worker goroutine only polls the runtime
  permission (while a scan is pending) and starts the deferred scan.
- widget.Clickable.Clicked must be called before Layout in v0.10:
  the Clickable consumes its click events during Layout.
- circleClip: the clip.Path.Cube control points are relative to the
  pen; the second control point of each segment must be at (k-r),
  not (k). The old code drew a distorted, non-circular shape.
- Android: perm_android.go pins a worker goroutine to one OS thread
  attached to the JVM for the life of the app (repeated
  attach/detach stack-overflows ART); the BLE view handle and scan
  permission state are shared with the render loop under bleMu.
- os_android.go: AndroidViewEvent attach handling; os_others.go:
  no-op stubs for other platforms.

New:
- scripts/build.sh: gogio -> apktool decode -> inject
  BLUETOOTH_SCAN/BLUETOOTH_CONNECT into the manifest -> rebuild ->
  debug-sign -> install. Usage: ./scripts/build.sh [phone|emu]
  [--no-install].
- .gitignore: .DS_Store, *.idsig.
2026-08-22 07:50:05 -04:00

42 lines
810 B
Go

package main
import (
"log"
"gioui.org/app"
"gioui.org/io/event"
"git.wow.st/gmp/ble"
)
var confDir string
var fontSize float32 = 24
func getConfDir() string {
if confDir == "" {
var err error
confDir, err = app.DataDir()
if err != nil {
log.Fatal("Cannot get configuration directory")
}
}
return confDir
}
func handleEvent(e event.Event, b *ble.BLE, w *app.Window) {
switch e := e.(type) {
case app.AndroidViewEvent:
b.Enable(e.View)
bleMu.Lock()
bleView = e.View
bleMu.Unlock()
// The runtime permission is requested by BlessedConnect.onAttach;
// the worker goroutine starts the pending scan once the grant is
// observed. Invalidate for the first frame: nothing else redraws
// until a Bluetooth or input event arrives.
if e.Valid() {
w.Invalidate()
}
}
}