mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 17:05:38 +00:00
app: [Android] replace PlatformHandle with JavaVM, AppContext methods
Clearer and fewer types. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+8
-4
@@ -4,11 +4,15 @@ import (
|
|||||||
"gioui.org/app/internal/window"
|
"gioui.org/app/internal/window"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Handle window.Handle
|
// JavaVM returns the global JNI JavaVM.
|
||||||
|
func JavaVM() uintptr {
|
||||||
|
return window.JavaVM()
|
||||||
|
}
|
||||||
|
|
||||||
// PlatformHandle returns the Android platform-specific Handle.
|
// AppContext returns the global Application context as a JNI
|
||||||
func PlatformHandle() *Handle {
|
// jobject.
|
||||||
return (*Handle)(window.PlatformHandle)
|
func AppContext() uintptr {
|
||||||
|
return window.AppContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
// androidDriver is an interface that allows the Window's run method
|
// androidDriver is an interface that allows the Window's run method
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
package window
|
|
||||||
|
|
||||||
var PlatformHandle *Handle
|
|
||||||
|
|
||||||
type Handle struct {
|
|
||||||
// JVM is the JNI *JVM pointer.
|
|
||||||
JVM uintptr
|
|
||||||
// Context is a global reference to the application's
|
|
||||||
// android.content.Context instance.
|
|
||||||
Context uintptr
|
|
||||||
}
|
|
||||||
@@ -61,6 +61,8 @@ var dataDirChan = make(chan string, 1)
|
|||||||
|
|
||||||
var theJVM *C.JavaVM
|
var theJVM *C.JavaVM
|
||||||
|
|
||||||
|
var appContext C.jobject
|
||||||
|
|
||||||
var views = make(map[C.jlong]*window)
|
var views = make(map[C.jlong]*window)
|
||||||
|
|
||||||
var mainWindow = newWindowRendezvous()
|
var mainWindow = newWindowRendezvous()
|
||||||
@@ -91,15 +93,19 @@ func runGoMain(env *C.JNIEnv, class C.jclass, jdataDir C.jbyteArray, context C.j
|
|||||||
dataDir := C.GoStringN((*C.char)(unsafe.Pointer(dirBytes)), n)
|
dataDir := C.GoStringN((*C.char)(unsafe.Pointer(dirBytes)), n)
|
||||||
dataDirChan <- dataDir
|
dataDirChan <- dataDir
|
||||||
C.gio_jni_ReleaseByteArrayElements(env, jdataDir, dirBytes)
|
C.gio_jni_ReleaseByteArrayElements(env, jdataDir, dirBytes)
|
||||||
context = C.gio_jni_NewGlobalRef(env, context)
|
appContext = C.gio_jni_NewGlobalRef(env, context)
|
||||||
|
|
||||||
PlatformHandle = &Handle{
|
|
||||||
JVM: uintptr(unsafe.Pointer(theJVM)),
|
|
||||||
Context: uintptr(context),
|
|
||||||
}
|
|
||||||
runMain()
|
runMain()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func JavaVM() uintptr {
|
||||||
|
return uintptr(unsafe.Pointer(theJVM))
|
||||||
|
}
|
||||||
|
|
||||||
|
func AppContext() uintptr {
|
||||||
|
return uintptr(appContext)
|
||||||
|
}
|
||||||
|
|
||||||
func GetDataDir() string {
|
func GetDataDir() string {
|
||||||
return <-dataDirChan
|
return <-dataDirChan
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user