Port to gio gioui.org@20200829.

This commit is contained in:
Greg 2020-09-05 14:12:29 -04:00
parent b0b310a7b0
commit 90ab682a44
7 changed files with 35 additions and 20 deletions

BIN
Ble.jar

Binary file not shown.

View File

@ -1,6 +1,7 @@
package st.wow.git.ble; package st.wow.git.ble;
import java.lang.String; import java.lang.String;
import java.lang.Runnable;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import android.app.Activity; import android.app.Activity;
@ -19,6 +20,7 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.Manifest; import android.Manifest;
import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -40,11 +42,18 @@ public class BlessedConnect extends Fragment {
public void register(View view) { public void register(View view) {
Log.d("gio", "BlessedConnect: register()"); Log.d("gio", "BlessedConnect: register()");
Activity act = (Activity)view.getContext(); Context ctx = view.getContext();
Handler handler = new Handler(ctx.getMainLooper());
BlessedConnect inst = this;
handler.post(new Runnable() {
public void run() {
Activity act = (Activity)ctx;
FragmentTransaction ft = act.getFragmentManager().beginTransaction(); FragmentTransaction ft = act.getFragmentManager().beginTransaction();
ft.add(this, "BlessedConnect"); ft.add(inst, "BlessedConnect");
ft.commitNow(); ft.commitNow();
} }
});
}
@Override public void onAttach(Context ctx) { @Override public void onAttach(Context ctx) {
super.onAttach(ctx); super.onAttach(ctx);

View File

@ -223,16 +223,13 @@ func NewBLE() *BLE {
} }
//Enable //Enable
func (b *BLE) Enable(w *app.Window) { func (b *BLE) Enable(view uintptr) {
log.Printf("ble.Enable()") log.Printf("ble.Enable()")
setJVM(app.JavaVM()) setJVM(app.JavaVM())
go w.Do(func(view uintptr) { runInJVM(func(env *JNIEnv) {
log.Printf("ble.Enable(): inside w.Do()")
runInJVM(func(env *C.JNIEnv) {
log.Printf("ble.Enable(): inside runInJVM()") log.Printf("ble.Enable(): inside runInJVM()")
C.registerFragment(env, (C.jobject)(unsafe.Pointer(view))) C.registerFragment(env, (C.jobject)(unsafe.Pointer(view)))
}) })
})
} }
// Go callbacks from Java // Go callbacks from Java

View File

@ -8,8 +8,6 @@ import (
"time" "time"
"unsafe" "unsafe"
"gioui.org/app"
"git.wow.st/gmp/ble/gatt" "git.wow.st/gmp/ble/gatt"
"git.wow.st/gmp/ble/ns" "git.wow.st/gmp/ble/ns"
) )
@ -204,7 +202,7 @@ func NewBLE() *BLE {
} }
//Enable is not required for Darwin. //Enable is not required for Darwin.
func (b *BLE) Enable(w *app.Window) { func (b *BLE) Enable(v uintptr) {
} }
// Core Bluetooth callback functions // Core Bluetooth callback functions

2
go.mod
View File

@ -2,4 +2,4 @@ module git.wow.st/gmp/ble
go 1.13 go 1.13
require gioui.org v0.0.0-20200619121558-88ced59dad93 require gioui.org v0.0.0-20200829162755-829ee4559c5a

2
go.sum
View File

@ -5,6 +5,8 @@ gioui.org v0.0.0-20200612151431-2dc19a36959c h1:sGUKyRMv2bbfbsRyG8ghOI12l+WCGta+
gioui.org v0.0.0-20200612151431-2dc19a36959c/go.mod h1:AHI9rFr6AEEHCb8EPVtb/p5M+NMJRKH58IOp8O3Je04= gioui.org v0.0.0-20200612151431-2dc19a36959c/go.mod h1:AHI9rFr6AEEHCb8EPVtb/p5M+NMJRKH58IOp8O3Je04=
gioui.org v0.0.0-20200619121558-88ced59dad93 h1:Llh4Tigdbu++FrRXL/KzqDHnH2Q5LPmAEk0djh6NLwk= gioui.org v0.0.0-20200619121558-88ced59dad93 h1:Llh4Tigdbu++FrRXL/KzqDHnH2Q5LPmAEk0djh6NLwk=
gioui.org v0.0.0-20200619121558-88ced59dad93/go.mod h1:jiUwifN9cRl/zmco43aAqh0aV+s9GbhG13KcD+gEpkU= gioui.org v0.0.0-20200619121558-88ced59dad93/go.mod h1:jiUwifN9cRl/zmco43aAqh0aV+s9GbhG13KcD+gEpkU=
gioui.org v0.0.0-20200829162755-829ee4559c5a h1:mciXRGzQwU0TbgCILZzl6L1nYIWU31lDGIb+8RYige8=
gioui.org v0.0.0-20200829162755-829ee4559c5a/go.mod h1:Y+uS7hHMvku1Q+ooaoq6fYD5B2LGoT8JtFgvmYmRzTw=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 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= 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= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

View File

@ -5,11 +5,20 @@
void void
registerFragment(JNIEnv *env, jobject view) { registerFragment(JNIEnv *env, jobject view) {
jclass cls = (*env)->FindClass(env, "st/wow/git/ble/BlessedConnect"); jclass cls = (*env)->GetObjectClass(env, view);
jmethodID reg = (*env)->GetMethodID(env, cls, "register", "(Landroid/view/View;)V"); jmethodID mid = (*env)->GetMethodID(env, cls, "getContext", "()Landroid/content/Context;");
jmethodID init = (*env)->GetMethodID(env, cls, "<init>", "()V"); jobject ctx = (*env)->CallObjectMethod(env, view, mid);
jobject inst = (*env)->NewObject(env, cls, init); cls = (*env)->GetObjectClass(env, ctx);
(*env)->CallVoidMethod(env, inst, reg, view); mid = (*env)->GetMethodID(env, cls, "getClassLoader", "()Ljava/lang/ClassLoader;");
jobject loader = (*env)->CallObjectMethod(env, ctx, mid);
cls = (*env)->GetObjectClass(env, loader);
mid = (*env)->GetMethodID(env, cls, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
jstring str = (*env)->NewStringUTF(env, "st/wow/git/ble/BlessedConnect");
cls = (*env)->CallObjectMethod(env, loader, mid, str);
mid = (*env)->GetMethodID(env, cls, "<init>", "()V");
jobject inst = (*env)->NewObject(env, cls, mid);
mid = (*env)->GetMethodID(env, cls, "register", "(Landroid/view/View;)V");
(*env)->CallVoidMethod(env, inst, mid, view);
} }
jboolean jboolean