コード例 #1
0
	int OutputStream::InitJNI()
	{
		JNIEnv* env = cocos2d::JniHelper::getEnv();

		{
			const char* strClass = "java/io/OutputStream";
#if ENABLE_VERBOSE_LOGGING
			__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Searching for %s", strClass);
#endif
			// system classes don't use `FAndroidApplication`
			jclass localRef = env->FindClass(strClass);
			if (localRef)
			{
#if ENABLE_VERBOSE_LOGGING
				__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Found %s", strClass);
#endif
				_jcOutputStream = (jclass)env->NewGlobalRef(localRef);
				env->DeleteLocalRef(localRef);
			}
			else
			{
				__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to find %s", strClass);
				return JNI_ERR;
			}
		}

		return FindJNI();
	}
	int GameModScreenshot::InitJNI()
	{
		JNIEnv* env = cocos2d::JniHelper::getEnv();

		{
			const char* strClass = "com/razerzone/store/sdk/content/GameModScreenshot";
#if ENABLE_VERBOSE_LOGGING
			__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Searching for %s", strClass);
#endif
			jclass localRef = cocos2d::JniHelper::getEnv()->FindClass(strClass);
			if (localRef)
			{
#if ENABLE_VERBOSE_LOGGING
				__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Found %s", strClass);
#endif
				_jcGameModScreenshot = (jclass)env->NewGlobalRef(localRef);
				env->DeleteLocalRef(localRef);
			}
			else
			{
				__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to find %s", strClass);
				return JNI_ERR;
			}
		}

		return FindJNI();
	}
コード例 #3
0
	const std::string& OuyaController::getDeviceName()
	{
		FindJNI();

		_deviceName = "Unavailable";

		if (!_instance)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_instance is not initialized");
			return _deviceName;
		}

		if (!_jmGetDeviceName)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_jmGetDeviceName is not initialized");
			return _deviceName;
		}

		jstring retVal = (jstring)_env->CallObjectMethod(_instance, _jmGetDeviceName);
		if (!retVal)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "getDeviceName returned null");
			return _deviceName;
		}

		const char* nativeString = _env->GetStringUTFChars(retVal, 0);
		_deviceName = nativeString;
		_env->ReleaseStringUTFChars(retVal, nativeString);
		_env->DeleteLocalRef(retVal);

		return _deviceName;
	}
コード例 #4
0
	OuyaController* OuyaController::getControllerByPlayer(int playerNum)
	{
		FindJNI();

		if (!_jcOuyaController)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_jcOuyaController is not initialized");
			return 0;
		}

		if (!_jmGetControllerByPlayer)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_jmGetControllerByPlayer is not initialized");
			return 0;
		}

		jint arg1 = playerNum;
		jobject retVal = _env->CallStaticObjectMethod(_jcOuyaController, _jmGetControllerByPlayer, arg1);
		if (!retVal)
		{
			// May return null if controller isn't connected
			//__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "getControllerByPlayer returned null");
			return 0;
		}

		OuyaController* result = new OuyaController();
		result->SetInstance(retVal);
		return result;
	}
コード例 #5
0
	std::string JSONObject::getString(const std::string& name) const
	{
#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "std::string JSONObject::getString(const std::string& name) const");
#endif
		FindJNI();

		JNIEnv* env = cocos2d::JniHelper::getEnv();

		if (!_instance)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Instance is not valid!");
			return std::string();
		}

		if (!_mGetString)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_mGetString is not valid!");
			return std::string();
		}

		jstring arg1 = env->NewStringUTF(name.c_str());
		jstring result = (jstring)env->CallObjectMethod(_instance, _mGetString, arg1);

		if (env->ExceptionCheck())
		{
			env->ExceptionDescribe();
			env->ExceptionClear();
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to get string");
			return std::string();
		}

		env->DeleteLocalRef(arg1);

		if (result)
		{
			const char* nativeString = env->GetStringUTFChars(result, 0);
			std::string retVal = std::string(nativeString);
			env->ReleaseStringUTFChars(result, nativeString);

#if ENABLE_VERBOSE_LOGGING
			__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Get string: %s", retVal.c_str());
#endif
			return retVal;
		}
		else
		{
			return std::string();
		}
	}
コード例 #6
0
	void OuyaController::showCursor(bool visible)
	{
		FindJNI();

		if (!_jcOuyaController)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_jcOuyaController is not initialized");
			return;
		}

		if (!_jmShowCursor)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_jmShowCursor is not initialized");
			return;
		}

		_env->CallStaticVoidMethod(_jcOuyaController, _jmShowCursor, visible);
	}
コード例 #7
0
	JSONObject JSONObject::put(const std::string& name, const std::string& value) const
	{
#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "JSONObject JSONObject::put(const std::string& name, const std::string& value) const");
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "put name=%s", name.c_str());
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "put value=%s", value.c_str());
#endif
		FindJNI();

		JNIEnv* env = cocos2d::JniHelper::getEnv();

		if (!_instance)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Instance is not valid!");
			return JSONObject(0);
		}

		if (!_mPut)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_mPut is not valid!");
			return JSONObject(0);
		}

		jstring arg1 = env->NewStringUTF(name.c_str());
		jstring arg2 = env->NewStringUTF(value.c_str());
		jobject retVal = env->CallObjectMethod(_instance, _mPut, arg1, arg2);

		if (env->ExceptionCheck())
		{
			env->ExceptionDescribe();
			env->ExceptionClear();
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to put");
			return JSONObject(0);
		}

#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success put");
#endif
		env->DeleteLocalRef(arg1);
		env->DeleteLocalRef(arg2);

		JSONObject result = JSONObject(retVal);
		return result;
	}
コード例 #8
0
	JSONObject::JSONObject(const std::string& buffer)
	{
#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Invoke JSONObject(const std::string& buffer)");
#endif
		FindJNI();

		JNIEnv* env = cocos2d::JniHelper::getEnv();

		_instance = env->AllocObject(_jcJsonObject);
		if (_instance)
		{
#if ENABLE_VERBOSE_LOGGING
			__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success allocate JSONObject");
#endif
		}
		else
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to allocate JSONObject");
			return;
		}

		if (!_mConstruct2)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_mConstruct2 is not valid!");
			return;
		}

		jstring arg1 = env->NewStringUTF(buffer.c_str());
		env->CallVoidMethod(_instance, _mConstruct2, arg1);

		if (env->ExceptionCheck())
		{
			env->ExceptionDescribe();
			env->ExceptionClear();
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to construct JSONObject");
			return;
		}

#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success constructed JSONObject");
#endif
		env->DeleteLocalRef(arg1);
	}
コード例 #9
0
	JSONObject::JSONObject()
	{
#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Invoke JSONObject()");
#endif
		FindJNI();

		JNIEnv* env = cocos2d::JniHelper::getEnv();

		jobject localRef = env->AllocObject(_jcJsonObject);
		if (localRef)
		{
#if ENABLE_VERBOSE_LOGGING
			__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success allocate JSONObject");
#endif
			_instance = env->NewGlobalRef(localRef);
			env->DeleteLocalRef(localRef);
		}
		else
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to allocate JSONObject");
			return;
		}

		if (!_mConstruct)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_mConstruct is not valid!");
			return;
		}

		env->CallVoidMethod(_instance, _mConstruct);

		if (env->ExceptionCheck())
		{
			env->ExceptionDescribe();
			env->ExceptionClear();
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to construct JSONObject");
			return;
		}

#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success constructed JSONObject");
#endif
	}
コード例 #10
0
	bool JSONObject::has(const std::string& name) const
	{
#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "bool JSONObject::has(const std::string& name) const");
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "has name=%s", name.c_str());
#endif
		FindJNI();

		JNIEnv* env = cocos2d::JniHelper::getEnv();

		if (!_instance)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Instance is not valid!");
			return false;
		}

		if (!_mHas)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_mHas is not valid!");
			return false;
		}

		jstring arg1 = env->NewStringUTF(name.c_str());
		jboolean result = env->CallBooleanMethod(_instance, _mHas, arg1);

		if (env->ExceptionCheck())
		{
			env->ExceptionDescribe();
			env->ExceptionClear();
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to has");
			return false;
		}

#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success has");
#endif
		env->DeleteLocalRef(arg1);

		return result;
	}
コード例 #11
0
	int Bundle::InitJNI(JavaVM* jvm)
	{
		_jvm = jvm;

		JNIEnv* env;
		if (_jvm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) {
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to get JNI environment!");
			return JNI_ERR;
		}

		if (!env)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "JNI must be initialized with a valid environment!");
			return JNI_ERR;
		}

		{
			const char* strClass = "android/os/Bundle";
#if ENABLE_VERBOSE_LOGGING
			__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Searching for %s", strClass);
#endif
			jclass localRef = env->FindClass(strClass);
			if (localRef)
			{
#if ENABLE_VERBOSE_LOGGING
				__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Found %s", strClass);
#endif
				_jcBundle = (jclass)env->NewGlobalRef(localRef);
				env->DeleteLocalRef(localRef);
			}
			else
			{
				__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to find %s", strClass);
				return JNI_ERR;
			}
		}

		return FindJNI();
	}
コード例 #12
0
	JSONObject JSONObject::getJSONObject(const std::string& name) const
	{
#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "JSONObject JSONObject::getJSONObject(const std::string& name) const");
#endif
		FindJNI();

		JNIEnv* env = cocos2d::JniHelper::getEnv();

		if (!_instance)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Instance is not valid!");
			return JSONObject(0);
		}

		if (!_mGetJsonObject)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_mGetJsonObject is not valid!");
			return JSONObject(0);
		}

		jstring arg1 = env->NewStringUTF(name.c_str());
		jobject result = env->CallObjectMethod(_instance, _mGetJsonObject, arg1);

		if (env->ExceptionCheck())
		{
			env->ExceptionDescribe();
			env->ExceptionClear();
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to get json object");
			return JSONObject(0);
		}

#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success got json object");
#endif
		env->DeleteLocalRef(arg1);

		return JSONObject(result);
	}
コード例 #13
0
	double JSONObject::getDouble(const std::string& name) const
	{
#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "double JSONObject::getDouble(const std::string& name) const");
#endif
		FindJNI();

		JNIEnv* env = cocos2d::JniHelper::getEnv();

		if (!_instance)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Instance is not valid!");
			return 0;
		}

		if (!_mGetDouble)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_mGetDouble is not valid!");
			return 0;
		}

		jstring arg1 = env->NewStringUTF(name.c_str());
		jdouble result = env->CallDoubleMethod(_instance, _mGetDouble, arg1);

		if (env->ExceptionCheck())
		{
			env->ExceptionDescribe();
			env->ExceptionClear();
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to get double");
			return 0;
		}

#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success get double: %f", (float)result);
#endif
		env->DeleteLocalRef(arg1);

		return (double)result;
	}