From 19194e36f49a5e2d5d51e0ba1e200c933df602b5 Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 11 Jun 2020 10:42:43 -0400 Subject: [PATCH] Bump gio version. --- examples/dex/main.go | 27 ++++++++++++++----------- examples/jni/main.go | 25 ++++++++++++++---------- examples/jni/os_other.go | 1 + examples/pgp/PgpConnect.java | 12 ++++++++++-- examples/pgp/jni_android.go | 4 ++-- examples/pgp/main.go | 30 +++++++++++++++++----------- examples/pgp/os_android.go | 38 ++++++++++++++++++++++++++---------- examples/pgp/os_other.go | 8 +++++++- examples/sensors/main.go | 25 ++++++++++++++---------- go.mod | 4 ++-- go.sum | 5 +++++ 11 files changed, 120 insertions(+), 59 deletions(-) diff --git a/examples/dex/main.go b/examples/dex/main.go index 0ffa0a0..427ec41 100644 --- a/examples/dex/main.go +++ b/examples/dex/main.go @@ -5,8 +5,9 @@ package main import ( "gioui.org/app" - "gioui.org/layout" "gioui.org/io/system" + "gioui.org/layout" + "gioui.org/op" "gioui.org/unit" "gioui.org/widget/material" @@ -17,6 +18,11 @@ var ( labchan chan string ) +type ( + D = layout.Dimensions + C = layout.Context +) + func main() { labchan = make(chan string) go eventloop() @@ -24,14 +30,13 @@ func main() { } func eventloop() { - gofont.Register() w := app.NewWindow(app.Title("Dex")) - th := material.NewTheme() - gtx := &layout.Context{Queue: w.Queue()} + th := material.NewTheme(gofont.Collection()) + var ops op.Ops sysinset := &layout.Inset{} margin := layout.UniformInset(unit.Dp(10)) - labels := []material.Label{} + labels := []material.LabelStyle{} list := &layout.List{Axis: layout.Vertical} go func() { @@ -49,18 +54,18 @@ func eventloop() { for { select { case x := <-labchan: - labels = append(labels, th.Body1(x)) + labels = append(labels, material.Body1(th, x)) case e := <-w.Events(): switch e := e.(type) { case system.DestroyEvent: return case system.FrameEvent: - gtx.Reset(e.Config, e.Size) + gtx := layout.NewContext(&ops, e) resetSysinset(e.Insets) - sysinset.Layout(gtx, func() { - margin.Layout(gtx, func() { - list.Layout(gtx, len(labels), func(i int) { - labels[i].Layout(gtx) + sysinset.Layout(gtx, func(gtx C) D { + return margin.Layout(gtx, func(gtx C) D { + return list.Layout(gtx, len(labels), func(gtx C, i int) D { + return labels[i].Layout(gtx) }) }) }) diff --git a/examples/jni/main.go b/examples/jni/main.go index 7137361..e05b494 100644 --- a/examples/jni/main.go +++ b/examples/jni/main.go @@ -8,6 +8,7 @@ import ( "gioui.org/app" "gioui.org/io/system" "gioui.org/layout" + "gioui.org/op" "gioui.org/unit" "gioui.org/widget/material" @@ -18,6 +19,11 @@ var ( labchan chan string ) +type ( + D = layout.Dimensions + C = layout.Context +) + func main() { labchan = make(chan string) log.Print("Staring event loop") @@ -27,16 +33,15 @@ func main() { } func eventloop() { - gofont.Register() w := app.NewWindow( app.Size(unit.Dp(400), unit.Dp(400)), app.Title("Hello")) - th := material.NewTheme() - gtx := &layout.Context{Queue: w.Queue()} + th := material.NewTheme(gofont.Collection()) + var ops op.Ops sysinset := &layout.Inset{} margin := layout.UniformInset(unit.Dp(10)) - labels := []material.Label{} + labels := []material.LabelStyle{} list := &layout.List{Axis: layout.Vertical} resetSysinset := func(x system.Insets) { @@ -52,18 +57,18 @@ func eventloop() { for { select { case x := <-labchan: - labels = append(labels, th.Body1(x)) + labels = append(labels, material.Body1(th, x)) case e := <-w.Events(): switch e := e.(type) { case system.DestroyEvent: return case system.FrameEvent: - gtx.Reset(e.Config, e.Size) + gtx := layout.NewContext(&ops, e) resetSysinset(e.Insets) - sysinset.Layout(gtx, func() { - margin.Layout(gtx, func() { - list.Layout(gtx, len(labels), func(i int) { - labels[i].Layout(gtx) + sysinset.Layout(gtx, func(gtx C) D { + return margin.Layout(gtx, func(gtx C) D { + return list.Layout(gtx, len(labels), func(gtx C, i int) D { + return labels[i].Layout(gtx) }) }) }) diff --git a/examples/jni/os_other.go b/examples/jni/os_other.go index 2f6fa48..7fc0c34 100644 --- a/examples/jni/os_other.go +++ b/examples/jni/os_other.go @@ -3,5 +3,6 @@ package main func callJni() { + labchan <- "nothing to do" } diff --git a/examples/pgp/PgpConnect.java b/examples/pgp/PgpConnect.java index db498f0..907f011 100644 --- a/examples/pgp/PgpConnect.java +++ b/examples/pgp/PgpConnect.java @@ -14,6 +14,8 @@ import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpServiceConnection; import android.content.Context; +import android.content.ClipboardManager; +import android.content.ClipData; import android.content.Intent; import android.util.Log; import android.app.Activity; @@ -31,13 +33,12 @@ public class PgpConnect extends Fragment { Context ctx; Handler handler; OpenPgpServiceConnection mServiceConnection; + ClipboardManager cb; PgpConnect(Activity act) { act = act; ctx = act.getApplicationContext(); this.handler = new Handler(ctx.getMainLooper()); - //this.mServiceConnection = new OpenPgpServiceConnection(ctx, "org.sufficientlysecure.keychain"); - //this.mServiceConnection.bindToService(); final FragmentManager fm = act.getFragmentManager(); final Fragment frag = this; @@ -57,8 +58,10 @@ public class PgpConnect extends Fragment { this.handler = new Handler(ctx.getMainLooper()); mServiceConnection = new OpenPgpServiceConnection(ctx, "org.sufficientlysecure.keychain"); mServiceConnection.bindToService(); + cb = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE); } + @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d("gio", "onActivityResult(" + requestCode + "): " + resultCode); super.onActivityResult(requestCode, resultCode, data); @@ -85,6 +88,11 @@ public class PgpConnect extends Fragment { } } + public void Clip(byte []dat) { + ClipData clip = ClipData.newPlainText("PgpConnect", new String(dat)); + cb.setPrimaryClip(clip); + } + public void Decrypt(byte []dat, int chint) { if (handler == null) { return; diff --git a/examples/pgp/jni_android.go b/examples/pgp/jni_android.go index b9dbac4..7f8601d 100644 --- a/examples/pgp/jni_android.go +++ b/examples/pgp/jni_android.go @@ -60,8 +60,8 @@ func CreateObject(env *C.JNIEnv, cls C.jclass) C.jobject { type PGP C.jobject -func NewPgpConnect(env *C.JNIEnv, act uintptr) PGP { - return (PGP)(C.NewPgpConnect(env, (C.jobject)(unsafe.Pointer(act)))) +func NewPgpConnect(env uintptr, act uintptr) PGP { + return (PGP)(C.NewPgpConnect((*C.JNIEnv)(unsafe.Pointer(env)), (C.jobject)(unsafe.Pointer(act)))) } var ( diff --git a/examples/pgp/main.go b/examples/pgp/main.go index c04c03f..8addc60 100644 --- a/examples/pgp/main.go +++ b/examples/pgp/main.go @@ -8,6 +8,7 @@ import ( "gioui.org/app" "gioui.org/io/system" "gioui.org/layout" + "gioui.org/op" "gioui.org/unit" "gioui.org/widget/material" @@ -18,6 +19,11 @@ var ( labchan chan string ) +type ( + D = layout.Dimensions + C = layout.Context +) + func main() { labchan = make(chan string) log.Print("Staring event loop") @@ -27,16 +33,15 @@ func main() { } func eventloop() { - gofont.Register() w := app.NewWindow( app.Size(unit.Dp(400), unit.Dp(400)), app.Title("Hello")) - th := material.NewTheme() - gtx := &layout.Context{Queue: w.Queue()} + th := material.NewTheme(gofont.Collection()) + var ops op.Ops sysinset := &layout.Inset{} margin := layout.UniformInset(unit.Dp(10)) - labels := []material.Label{} + labels := []material.LabelStyle{} list := &layout.List{Axis: layout.Vertical} resetSysinset := func(x system.Insets) { @@ -47,30 +52,33 @@ func eventloop() { } go func() { labchan <- "Starting" - callJni() + callJni(w) }() for { select { case x := <-labchan: - labels = append(labels, th.Body1(x)) + labels = append(labels, material.Body1(th, x)) w.Invalidate() case e := <-w.Events(): switch e := e.(type) { case system.DestroyEvent: return case system.FrameEvent: - gtx.Reset(e.Config, e.Size) + gtx := layout.NewContext(&ops, e) resetSysinset(e.Insets) - sysinset.Layout(gtx, func() { - margin.Layout(gtx, func() { - list.Layout(gtx, len(labels), func(i int) { - labels[i].Layout(gtx) + sysinset.Layout(gtx, func(gtx C) D { + return margin.Layout(gtx, func(gtx C) D { + return list.Layout(gtx, len(labels), func(gtx C, i int) D { + return labels[i].Layout(gtx) }) }) }) e.Frame(gtx.Ops) case system.StageEvent: log.Printf("stage event -- %s", e.Stage) + if e.Stage == system.StageRunning { + initPgp(w) + } case *system.CommandEvent: log.Print("command event") } diff --git a/examples/pgp/os_android.go b/examples/pgp/os_android.go index 8b69462..628ddf1 100644 --- a/examples/pgp/os_android.go +++ b/examples/pgp/os_android.go @@ -16,35 +16,53 @@ import ( var ( h *app.Handle connected bool + ready bool + wch chan struct{} + w *app.Window pgp PGP ) +func init() { + wch = make(chan struct{}) +} -func connect() { +func initPgp(x *app.Window) { + w = x + close(wch) +} + +func connect(w *app.Window) bool { + <-wch if !connected { log.Print("PlatformHandle()") h = app.PlatformHandle() log.Print("SetJVM()") - SetJVM(h.JVM, h.Activity) + SetJVM(h.JVM, h.Context) log.Print("SetJVM() returned") - RunInJVM(func(env *JNIEnv) { - log.Print("NewPgpConnect()") - pgp = NewPgpConnect(env, h.Activity) + log.Print("calling window.Run()()") + w.Run(func(env app.JNIEnv, act app.Activity) { + log.Print("in window.Run() -- NewPgpConnect()") + pgp = NewPgpConnect(env.JNIEnv, act.Activity) }) connected = true } + return true } -func checkPermission() bool { - connect() +func checkPermission(w *app.Window) bool { + if !connect(w) { + return false + } //return pgp.CheckPermission(env) return false } -func callJni() { - connect() +func callJni(w *app.Window) { + if !connect(w) { + return + } labchan <- fmt.Sprintf("JVM = %d", h.JVM) - labchan <- fmt.Sprintf("Activity = %d", h.Activity) + labchan <- fmt.Sprintf("Context = %d", h.Context) time.Sleep(time.Second / 5) val, err := pgp.Encrypt("greg_pomerantz@yahoo.com", "hi there") diff --git a/examples/pgp/os_other.go b/examples/pgp/os_other.go index 2f6fa48..379ff35 100644 --- a/examples/pgp/os_other.go +++ b/examples/pgp/os_other.go @@ -2,6 +2,12 @@ package main -func callJni() { +import ( + "gioui.org/app" +) + +func callJni(w *app.Window) { } +func initPgp(w *app.Window) { +} diff --git a/examples/sensors/main.go b/examples/sensors/main.go index 2c5374b..2419dc7 100644 --- a/examples/sensors/main.go +++ b/examples/sensors/main.go @@ -8,6 +8,7 @@ import ( "gioui.org/app" "gioui.org/io/system" "gioui.org/layout" + "gioui.org/op" "gioui.org/unit" "gioui.org/widget/material" @@ -18,6 +19,11 @@ var ( labchan chan string ) +type ( + D = layout.Dimensions + C = layout.Context +) + func main() { labchan = make(chan string) log.Print("Staring event loop") @@ -34,16 +40,15 @@ func diffInsets(x, y system.Insets) bool { } func eventloop() { - gofont.Register() w := app.NewWindow( app.Size(unit.Dp(400), unit.Dp(400)), app.Title("Hello")) - th := material.NewTheme() - gtx := &layout.Context{Queue: w.Queue()} + th := material.NewTheme(gofont.Collection()) + var ops op.Ops sysinset := &layout.Inset{} margin := layout.UniformInset(unit.Dp(10)) - labels := []material.Label{} + labels := []material.LabelStyle{} list := &layout.List{Axis: layout.Vertical} resetSysinset := func(x system.Insets) { @@ -59,18 +64,18 @@ func eventloop() { for { select { case x := <-labchan: - labels = append(labels, th.Body1(x)) + labels = append(labels, material.Body1(th, x)) case e := <-w.Events(): switch e := e.(type) { case system.DestroyEvent: return case system.FrameEvent: - gtx.Reset(e.Config, e.Size) + gtx := layout.NewContext(&ops, e) resetSysinset(e.Insets) - sysinset.Layout(gtx, func() { - margin.Layout(gtx, func() { - list.Layout(gtx, len(labels), func(i int) { - labels[i].Layout(gtx) + sysinset.Layout(gtx, func(gtx C) D { + return margin.Layout(gtx, func(gtx C) D { + return list.Layout(gtx, len(labels), func(gtx C, i int) D { + return labels[i].Layout(gtx) }) }) }) diff --git a/go.mod b/go.mod index dfd6d35..8323903 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module git.wow.st/gmp/android-go -go 1.13 +go 1.14 -require gioui.org v0.0.0-20191031200634-4e71f195ab51 +require gioui.org v0.0.0-20200611133933-6d5fbcba3f21 diff --git a/go.sum b/go.sum index 0ef599f..d5fed71 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,10 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= gioui.org v0.0.0-20191031200634-4e71f195ab51 h1:Epxo/e6oPvbDMMB8rrpmUlBe6ELeDpRuLzFUGfT6kJM= gioui.org v0.0.0-20191031200634-4e71f195ab51/go.mod h1:KqFFi2Dq5gYA3FJ0sDOt8OBXoMsuxMtE8v2f0JExXAY= +gioui.org v0.0.0-20191112235626-1bf2c7ef293c h1:jhUehzf6xTCgEewbJyjd+WE2Kq5pvPIxq2MahDph0mg= +gioui.org v0.0.0-20191112235626-1bf2c7ef293c/go.mod h1:KqFFi2Dq5gYA3FJ0sDOt8OBXoMsuxMtE8v2f0JExXAY= +gioui.org v0.0.0-20200611133933-6d5fbcba3f21 h1:VFB+0QxUPABMgEarfyJeHQvUNc++9TASnDVXcFgxLcA= +gioui.org v0.0.0-20200611133933-6d5fbcba3f21/go.mod h1:AHI9rFr6AEEHCb8EPVtb/p5M+NMJRKH58IOp8O3Je04= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -20,6 +24,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=