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;
import java.lang.String;
import java.lang.Runnable;
import java.util.List;
import java.util.UUID;
import android.app.Activity;
@ -19,6 +20,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.Manifest;
import android.os.Handler;
import android.util.Log;
import android.view.View;
@ -40,10 +42,17 @@ public class BlessedConnect extends Fragment {
public void register(View view) {
Log.d("gio", "BlessedConnect: register()");
Activity act = (Activity)view.getContext();
FragmentTransaction ft = act.getFragmentManager().beginTransaction();
ft.add(this, "BlessedConnect");
ft.commitNow();
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();
ft.add(inst, "BlessedConnect");
ft.commitNow();
}
});
}
@Override public void onAttach(Context ctx) {

View File

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

View File

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

2
go.mod
View File

@ -2,4 +2,4 @@ module git.wow.st/gmp/ble
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-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-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/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=

View File

@ -5,11 +5,20 @@
void
registerFragment(JNIEnv *env, jobject view) {
jclass cls = (*env)->FindClass(env, "st/wow/git/ble/BlessedConnect");
jmethodID reg = (*env)->GetMethodID(env, cls, "register", "(Landroid/view/View;)V");
jmethodID init = (*env)->GetMethodID(env, cls, "<init>", "()V");
jobject inst = (*env)->NewObject(env, cls, init);
(*env)->CallVoidMethod(env, inst, reg, view);
jclass cls = (*env)->GetObjectClass(env, view);
jmethodID mid = (*env)->GetMethodID(env, cls, "getContext", "()Landroid/content/Context;");
jobject ctx = (*env)->CallObjectMethod(env, view, mid);
cls = (*env)->GetObjectClass(env, ctx);
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