mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 23:55:39 +00:00
app/internal/headless: [Android] expose Java initialization method
Android apps may want to run Go code independent of the Gio Android Activity. Expose a Gio.init Java method public for early loading and initialization of the Go library. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -42,24 +42,6 @@ public class GioView extends SurfaceView implements Choreographer.FrameCallback
|
||||
private final Handler handler;
|
||||
private long nhandle;
|
||||
|
||||
private static synchronized void initialize(Context appCtx) {
|
||||
synchronized (initLock) {
|
||||
if (jniLoaded) {
|
||||
return;
|
||||
}
|
||||
String dataDir = appCtx.getFilesDir().getAbsolutePath();
|
||||
byte[] dataDirUTF8;
|
||||
try {
|
||||
dataDirUTF8 = dataDir.getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.loadLibrary("gio");
|
||||
runGoMain(dataDirUTF8, appCtx);
|
||||
jniLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public GioView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -69,7 +51,7 @@ public class GioView extends SurfaceView implements Choreographer.FrameCallback
|
||||
|
||||
handler = new Handler();
|
||||
// Late initialization of the Go runtime to wait for a valid context.
|
||||
initialize(context.getApplicationContext());
|
||||
Gio.init(context.getApplicationContext());
|
||||
|
||||
nhandle = onCreateView(this);
|
||||
imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
@@ -260,7 +242,6 @@ public class GioView extends SurfaceView implements Choreographer.FrameCallback
|
||||
static private native void onFrameCallback(long handle, long nanos);
|
||||
static private native boolean onBack(long handle);
|
||||
static private native void onFocusChange(long handle, boolean focus);
|
||||
static private native void runGoMain(byte[] dataDir, Context context);
|
||||
|
||||
private static class InputConnection extends BaseInputConnection {
|
||||
private final Editable editable;
|
||||
|
||||
Reference in New Issue
Block a user