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" "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
-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 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
} }