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:
Elias Naur
2020-04-20 20:21:39 +02:00
parent 10f932137c
commit ae77377f7b
3 changed files with 19 additions and 20 deletions
+8 -4
View File
@@ -4,11 +4,15 @@ import (
"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.
func PlatformHandle() *Handle {
return (*Handle)(window.PlatformHandle)
// AppContext returns the global Application context as a JNI
// jobject.
func AppContext() uintptr {
return window.AppContext()
}
// androidDriver is an interface that allows the Window's run method
-11
View File
@@ -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
}
+11 -5
View File
@@ -61,6 +61,8 @@ var dataDirChan = make(chan string, 1)
var theJVM *C.JavaVM
var appContext C.jobject
var views = make(map[C.jlong]*window)
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)
dataDirChan <- dataDir
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()
}
func JavaVM() uintptr {
return uintptr(unsafe.Pointer(theJVM))
}
func AppContext() uintptr {
return uintptr(appContext)
}
func GetDataDir() string {
return <-dataDirChan
}