Exemplo n.º 1
0
func main(f func(App)) {
	mainUserFn = f
	// TODO: merge the runInputQueue and mainUI functions?
	go func() {
		if err := mobileinit.RunOnJVM(runInputQueue); err != nil {
			log.Fatalf("app: %v", err)
		}
	}()
	// Preserve this OS thread for:
	//	1. the attached JNI thread
	//	2. the GL context
	if err := mobileinit.RunOnJVM(mainUI); err != nil {
		log.Fatalf("app: %v", err)
	}
}
Exemplo n.º 2
0
func initAL() {
	err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error {
		C.al_init(C.uintptr_t(vm), C.uintptr_t(env), C.jobject(ctx), &alHandle)
		if alHandle == nil {
			return errors.New("al: cannot load libopenal.so")
		}
		return nil
	})
	if err != nil {
		log.Fatalf("al: %v", err)
	}

	alEnableFunc = C.LPALENABLE(fn("alEnable"))
	alDisableFunc = C.LPALDISABLE(fn("alDisable"))
	alIsEnabledFunc = C.LPALISENABLED(fn("alIsEnabled"))
	alGetIntegerFunc = C.LPALGETINTEGER(fn("alGetInteger"))
	alGetIntegervFunc = C.LPALGETINTEGERV(fn("alGetIntegerv"))
	alGetFloatFunc = C.LPALGETFLOAT(fn("alGetFloat"))
	alGetFloatvFunc = C.LPALGETFLOATV(fn("alGetFloatv"))
	alGetBooleanFunc = C.LPALGETBOOLEAN(fn("alGetBoolean"))
	alGetBooleanvFunc = C.LPALGETBOOLEANV(fn("alGetBooleanv"))
	alGetStringFunc = C.LPALGETSTRING(fn("alGetString"))
	alDistanceModelFunc = C.LPALDISTANCEMODEL(fn("alDistanceModel"))
	alDopplerFactorFunc = C.LPALDOPPLERFACTOR(fn("alDopplerFactor"))
	alDopplerVelocityFunc = C.LPALDOPPLERVELOCITY(fn("alDopplerVelocity"))
	alSpeedOfSoundFunc = C.LPALSPEEDOFSOUND(fn("alSpeedOfSound"))
	alGetErrorFunc = C.LPALGETERROR(fn("alGetError"))
	alGenSourcesFunc = C.LPALGENSOURCES(fn("alGenSources"))
	alSourcePlayvFunc = C.LPALSOURCEPLAYV(fn("alSourcePlayv"))
	alSourcePausevFunc = C.LPALSOURCEPAUSEV(fn("alSourcePausev"))
	alSourceStopvFunc = C.LPALSOURCESTOPV(fn("alSourceStopv"))
	alSourceRewindvFunc = C.LPALSOURCEREWINDV(fn("alSourceRewindv"))
	alDeleteSourcesFunc = C.LPALDELETESOURCES(fn("alDeleteSources"))
	alGetSourceiFunc = C.LPALGETSOURCEI(fn("alGetSourcei"))
	alGetSourcefFunc = C.LPALGETSOURCEF(fn("alGetSourcef"))
	alGetSourcefvFunc = C.LPALGETSOURCEFV(fn("alGetSourcefv"))
	alSourceiFunc = C.LPALSOURCEI(fn("alSourcei"))
	alSourcefFunc = C.LPALSOURCEF(fn("alSourcef"))
	alSourcefvFunc = C.LPALSOURCEFV(fn("alSourcefv"))
	alSourceQueueBuffersFunc = C.LPALSOURCEQUEUEBUFFERS(fn("alSourceQueueBuffers"))
	alSourceUnqueueBuffersFunc = C.LPALSOURCEUNQUEUEBUFFERS(fn("alSourceUnqueueBuffers"))
	alGetListenerfFunc = C.LPALGETLISTENERF(fn("alGetListenerf"))
	alGetListenerfvFunc = C.LPALGETLISTENERFV(fn("alGetListenerfv"))
	alListenerfFunc = C.LPALLISTENERF(fn("alListenerf"))
	alListenerfvFunc = C.LPALLISTENERFV(fn("alListenerfv"))
	alGenBuffersFunc = C.LPALGENBUFFERS(fn("alGenBuffers"))
	alDeleteBuffersFunc = C.LPALDELETEBUFFERS(fn("alDeleteBuffers"))
	alGetBufferiFunc = C.LPALGETBUFFERI(fn("alGetBufferi"))
	alBufferDataFunc = C.LPALBUFFERDATA(fn("alBufferData"))
	alIsBufferFunc = C.LPALISBUFFER(fn("alIsBuffer"))

	alcGetErrorFunc = C.LPALCGETERROR(fn("alcGetError"))
	alcOpenDeviceFunc = C.LPALCOPENDEVICE(fn("alcOpenDevice"))
	alcCloseDeviceFunc = C.LPALCCLOSEDEVICE(fn("alcCloseDevice"))
	alcCreateContextFunc = C.LPALCCREATECONTEXT(fn("alcCreateContext"))
	alcMakeContextCurrentFunc = C.LPALCMAKECONTEXTCURRENT(fn("alcMakeContextCurrent"))
	alcDestroyContextFunc = C.LPALCDESTROYCONTEXT(fn("alcDestroyContext"))
}
Exemplo n.º 3
0
func main(f func(App)) {
	mainUserFn = f
	// Preserve this OS thread for:
	//	1. the attached JNI thread
	//	2. the GL context
	if err := mobileinit.RunOnJVM(mainUI); err != nil {
		log.Fatalf("app: %v", err)
	}
}
Exemplo n.º 4
0
func assetInit() {
	err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error {
		C.asset_manager_init(C.uintptr_t(vm), C.uintptr_t(env), C.jobject(ctx))
		return nil
	})
	if err != nil {
		log.Fatalf("asset: %v", err)
	}
}
Exemplo n.º 5
0
func (an *androidNotification) Close() {
	err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error {
		C.notification_close(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx), C.jint(an.id))
		return nil
	})
	if err != nil {
		log.Fatalf("Notification.Close: %v", err)
	}
}
Exemplo n.º 6
0
func stopLocationUpdates() {
	err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error {
		C.location_manager_stopLocationUpdates(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx))
		return nil
	})
	if err != nil {
		log.Fatalf("stopLocationUpdates: %v", err)
	}
	log.Print("stopLocationUpdates succeeded")
}
Exemplo n.º 7
0
func locationManagerInit() {
	err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error {
		C.location_manager_init(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx))
		return nil
	})
	if err != nil {
		log.Fatalf("location: %v", err)
	}
	locationManager = &androidLocationManager{}
	log.Print("location initialized")
}
Exemplo n.º 8
0
func requestLocationUpdates(provider string, minTime int64, minDistance float32) {
	err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error {
		cProvider := C.CString(provider)
		defer C.free(unsafe.Pointer(cProvider))
		C.location_manager_requestLocationUpdates(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx), cProvider, C.jlong(minTime), C.jfloat(minDistance))
		return nil
	})
	if err != nil {
		log.Fatalf("requestLocationUpdates: %v", err)
	}
	log.Print("requestLocationUpdates succeeded")
}
Exemplo n.º 9
0
func show(message string, long bool) {
	err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error {
		cMessage := C.CString(message)
		defer C.free(unsafe.Pointer(cMessage))
		duration := C.jint(0) // TOAST_SHORT
		if long {
			duration = C.jint(1) // TOAST_LONG
		}
		C.toast_show(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx), cMessage, duration)
		return nil
	})
	if err != nil {
		log.Fatalf("showToast: %v", err)
	}
}
Exemplo n.º 10
0
func Notify(title, text string) Notification {
	var id int
	err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error {
		cTitle := C.CString(title)
		defer C.free(unsafe.Pointer(cTitle))
		cText := C.CString(text)
		defer C.free(unsafe.Pointer(cText))
		id = int(C.notification_notify(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx), cTitle, cText))
		return nil
	})
	if err != nil {
		log.Fatalf("Notify: %v", err)
	}
	return &androidNotification{
		id: id,
	}
}