Exemplo n.º 1
0
const char* getPrefPath(){
	LOGD("getPrefPath called.");
	static char* path=0;
	if(path){
		return path;
	}
	LOGD("getPrefPath / getPathFromJava.");
	JNIEnv* env = attachJavaVM();
	LOGD("getPrefPath / attatched: %p / %p", env, actKlass);
	jmethodID method = (*env)->GetStaticMethodID(env, actKlass, "getPrefPath", "()Ljava/lang/String;");
	LOGD("getPrefPath / method: %p", method);
	jstring obj = (jstring)((*env)->CallStaticObjectMethod(env, actKlass, method));
	if( !obj ){
		detatchJavaVM();
		exit(-1);
	}
	const char* tmp = (*env)->GetStringUTFChars(env, obj, 0);
	int size=strlen(tmp);
	path=malloc(size+1);
	memcpy(path, tmp, size);
	path[size]=0;
	(*env)->ReleaseStringUTFChars(env,obj,tmp);
	detatchJavaVM();

	return path;

}
Exemplo n.º 2
0
void startDonationActivity()
{
	JNIEnv* const env = attachJavaVM();
	jclass intentClass = (*env)->FindClass(env, "android/content/Intent");
	jstring actionString = (*env)->NewStringUTF(env, "org.ledyba.noiz2sa.donation.DonationActivity");
	jmethodID newIntent = (*env)->GetMethodID(env, intentClass, "<init>", "()V");

	jobject intent = (*env)->AllocObject(env, intentClass);
	(*env)->CallVoidMethod(env, intent, newIntent);

	jmethodID setAction = (*env)->GetMethodID(env, intentClass, "setAction","(Ljava/lang/String;)Landroid/content/Intent;");
	(*env)->CallObjectMethod(env, intent, setAction, actionString);

	jclass activityClass = (*env)->FindClass(env, "android/app/Activity");
	jmethodID startActivity = (*env)->GetMethodID(env, activityClass,"startActivity", "(Landroid/content/Intent;)V");

	jobject intentObject = (*env)->NewObject(env, intentClass, newIntent);
	(*env)->CallVoidMethod(env, intentObject, setAction,actionString);

	useActivityKlass(env);
	jmethodID const mid = (*env)->GetStaticMethodID(env, actKlass, "getInstance", "()Lorg/ledyba/noiz2sa/Noiz2saActivity;");
	jobject actKlassObject = (*env)->CallStaticObjectMethod(env, actKlass, mid);
	
	(*env)->CallVoidMethod(env, actKlassObject, startActivity, intentObject);
	detatchJavaVM();
}
Exemplo n.º 3
0
float Window_getScale()
{
	static const char* method="getScale";
	JNIEnv* const env = attachJavaVM();
	if(!env){
		LOGE("getScale / env not found.");
		return 0;
	}
	useActivityKlass(env);
	jmethodID const mid = (*env)->GetStaticMethodID(env, actKlass, method, "()F");
	if( !mid ){
		LOGE("getScale / not found: %s", method);
		detatchJavaVM();
		return 0;
	}
	const float r = (*env)->CallStaticFloatMethod(env, actKlass, mid);
	detatchJavaVM();
	return r;
}
Exemplo n.º 4
0
static float padImpl(const char* method)
{
	JNIEnv* env = attachJavaVM();
	//LOGD("padImpl / attatched: %p", env);
	if(!env){
		LOGE("padImpl / env not found.");
		return 0;
	}
	jmethodID mid = (*env)->GetStaticMethodID(env, klass, method, "()F");
	if( !mid ){
		LOGE("padImpl / not found: %s", method);
		detatchJavaVM();
		return 0;
	}
	float r = (*env)->CallStaticFloatMethod(env, klass, mid);
	//LOGD("padImpl / r: %f", r);
	detatchJavaVM();
	return r;
}
Exemplo n.º 5
0
static int keyImpl(const char* method)
{
	JNIEnv* env = attachJavaVM();
	//LOGD("keyImpl / attatched: %p", env);
	if(!env){
		LOGE("keyImpl / env not found.");
		return 0;
	}
	jmethodID mid = (*env)->GetStaticMethodID(env, klass, method, "()I");
	if( !mid ){
		LOGE("keyImpl / not found: %s", method);
		detatchJavaVM();
		return 0;
	}
	int r = (*env)->CallStaticIntMethod(env, klass, mid);
	detatchJavaVM();
	//LOGD("keyImpl / r: %d", r);
	return r;
}
Exemplo n.º 6
0
AAssetManager* getAAssetManager()
{
	LOGD("getAAssetManager called.");
	JNIEnv* env = attachJavaVM();
	LOGD("getAAssetManager / attatched: %p", env);
	jmethodID getAssetManagerId =
		(*env)->GetStaticMethodID(env, klass, "getAssetManager", "()Landroid/content/res/AssetManager;");
	LOGD("getAAssetManager / method: %p", getAssetManagerId);
	if( getAssetManagerId ){
		LOGD("getAssetManagerId: %p", getAssetManagerId);
	}else{
		LOGE("getAssetManagerId is null.");
		detatchJavaVM();
		exit(-1);
	}
	AAssetManager* mgr =
		AAssetManager_fromJava(env, (*env)->CallStaticObjectMethod(env, klass, getAssetManagerId));
	LOGD("getAAssetManager / mgr: %p", mgr);
	detatchJavaVM();
	LOGD("getAAssetManager / detatched.");
	return mgr;
}
JNIEXPORT void JNICALL Java_org_jouvieje_fmoddesigner_InitFmodDesigner_attachJavaVM(JNIEnv *jenv, jclass jcls) {
	attachJavaVM(jenv);
}