mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
ui/app: call main from Android and iOS
Android can only run c-shared libraries which means that every Gio program must create its window and event loop from an init function. The same applies to iOS but for a more benign reason: the gio tool builds programs in c-archive mode for iOS and links the binary with a Objective-C driver. Allow Gio programs to run off its main function by linking to and invoking main even from Android libraries and iOS ditto. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+9
-10
@@ -27,7 +27,6 @@ import java.io.UnsupportedEncodingException;
|
||||
public class GioView extends SurfaceView implements Choreographer.FrameCallback {
|
||||
private final static Object initLock = new Object();
|
||||
private static boolean jniLoaded;
|
||||
private static String dataDir;
|
||||
|
||||
private final SurfaceHolder.Callback callbacks;
|
||||
private final InputMethodManager imm;
|
||||
@@ -39,20 +38,19 @@ public class GioView extends SurfaceView implements Choreographer.FrameCallback
|
||||
if (jniLoaded) {
|
||||
return;
|
||||
}
|
||||
dataDir = appCtx.getFilesDir().getAbsolutePath();
|
||||
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);
|
||||
jniLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
static byte[] dataDir() {
|
||||
try {
|
||||
return dataDir.getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public GioView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -221,6 +219,7 @@ 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);
|
||||
|
||||
private static class InputConnection extends BaseInputConnection {
|
||||
private final Editable editable;
|
||||
|
||||
Reference in New Issue
Block a user