<commit_before>#include <UtH/Platform/Android/GooglePlayGameServices.hpp>
#include <UtH/Platform/Android/AndroidEngine.hpp>
#include <UtH/Platform/Debug.hpp>

// Android

using namespace uth;

//bool GooglePlayGameServices::is_auth_in_progress = false;
//std::unique_ptr<gpg::GameServices> GooglePlayGameServices::game_services;

GooglePlayGameServices::GooglePlayGameServices()
{
	//init();
}

GooglePlayGameServices::~GooglePlayGameServices()
{
	//deInit();
}

// Public

void JNI_gameActivity()
{
	// Javaenviroment: Loads enviroment from Android activity
	if (uthAndroidEngine.jni == NULL)
		uthAndroidEngine.app->activity->vm->AttachCurrentThread(&uthAndroidEngine.jni, NULL);

	// Loads our java master class GameActivity
	if (uthAndroidEngine.gameActivity == NULL)
	{
		uthAndroidEngine.gameActivity = uthAndroidEngine.jni->GetObjectClass(uthAndroidEngine.app->activity->clazz);
		if (!uthAndroidEngine.gameActivity)
			WriteError("No engine found!");
	}
}


// Achiements
void GooglePlayGameServices::Achievement::UnlockAchievement(std::string achievement_id)
{
	JNI_gameActivity();

	// Loading function
	jmethodID unlockAchFunc = NULL;
	unlockAchFunc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "UnlockAchievement", "(Ljava/lang/String;)V");
	if (unlockAchFunc == NULL)
		WriteError("No UnlockAchievement function found!");

	jstring stringArg = uthAndroidEngine.jni->NewStringUTF(achievement_id.c_str());

	uthAndroidEngine.jni->CallVoidMethod(uthAndroidEngine.app->activity->clazz, unlockAchFunc, stringArg);
}
void GooglePlayGameServices::Achievement::IncrementAchievement(std::string achievement_id, int steps)
{
	JNI_gameActivity();

	// Loading function
	jmethodID unlockAchFunc = NULL;
	unlockAchFunc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "IncrementAchievement", "(Ljava/lang/String;I)V");
	if (unlockAchFunc == NULL)
		WriteError("No IncrementAchievement function found!");

	jstring stringArg = uthAndroidEngine.jni->NewStringUTF(achievement_id.c_str());

	uthAndroidEngine.jni->CallVoidMethod(uthAndroidEngine.app->activity->clazz, unlockAchFunc, stringArg, steps);
}
void GooglePlayGameServices::Achievement::ShowAchievements()
{
	JNI_gameActivity();

	// Loading function
	jmethodID showAchFunc = NULL;
	showAchFunc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "ShowAchievements", "()V");
	if (showAchFunc == NULL)
		WriteError("No ShowAchievements function found!");

	uthAndroidEngine.jni->CallVoidMethod(uthAndroidEngine.app->activity->clazz, showAchFunc);
}

// Leaderboard
void GooglePlayGameServices::LeaderBoard::SubmitHighScore(std::string leaderboard_id, int score)
{
	JNI_gameActivity();

	// Loading function
	jmethodID submitScoreFunc = NULL;
	submitScoreFunc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "SubmitHighScore", "(Ljava/lang/String;I)V");
	if (submitScoreFunc == NULL)
		WriteError("No SubmitHighScore function found!");

	jstring stringArg = uthAndroidEngine.jni->NewStringUTF(leaderboard_id.c_str());

	uthAndroidEngine.jni->CallVoidMethod(uthAndroidEngine.app->activity->clazz, submitScoreFunc, stringArg, score);
}
void GooglePlayGameServices::LeaderBoard::ShowLeaderboard(std::string leaderboard_id)
{
	JNI_gameActivity();

	// Loading function
	jmethodID showLPFunc = NULL;
	showLPFunc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "ShowLeaderboard", "(Ljava/lang/String;)V");
	if (showLPFunc == NULL)
		WriteError("No ShowLeaderboard function found!");

	jstring stringArg = uthAndroidEngine.jni->NewStringUTF(leaderboard_id.c_str());

	uthAndroidEngine.jni->CallVoidMethod(uthAndroidEngine.app->activity->clazz, showLPFunc, stringArg);
}

// GPS
GooglePlayGameServices::Location GooglePlayGameServices::GPS::GetCurrentLocation()
{
	JNI_gameActivity();

	// Loading function
	jmethodID getCurLoc = NULL;
	getCurLoc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "GetCurrentLocation", "()Ljava/lang/String;");
	if (getCurLoc == NULL)
		WriteError("No GetCurrentLocation function found!");


	jstring location = (jstring)uthAndroidEngine.jni->CallObjectMethod(uthAndroidEngine.app->activity->clazz, getCurLoc);

	std::string returnable = uthAndroidEngine.jni->GetStringUTFChars( location, 0);

	std::string::size_type fused = returnable.find("fused");
	std::string::size_type acc = returnable.find("acc=");
	std::string::size_type et = returnable.find("et=");
	std::string::size_type timeEnd = returnable.find("]");

	std::string fusedString = returnable.substr(fused + 6, acc - fused - 7);
	std::string::size_type splitPos = fusedString.find(",", 4);

	std::string::size_type replacePos;

	std::string latitude = fusedString.substr(0, splitPos);
	replacePos = latitude.find(",");
	latitude.replace(replacePos, 1, ".");

	std::string longitude = fusedString.substr(splitPos + 1);
	replacePos = longitude.find(",");
	longitude.replace(replacePos, 1, ".");

	std::string accuracy = returnable.substr(acc + 4, 2);
	std::string time = returnable.substr(et + 4, timeEnd - et - 4);

	uthGPGS.curLocation.loc_latitude = atof(latitude.c_str());
	uthGPGS.curLocation.loc_longitude = atof(longitude.c_str());
	//curLocation.loc_accuracy = atof(accuracy.c_str());   // UnAccurate
	uthGPGS.curLocation.loc_accuracy = GetAccuracy();
	uthGPGS.curLocation.device_time_since_reboot = time;

	return uthGPGS.curLocation;<commit_msg>fixed android localization effects on position string<commit_after>#include <UtH/Platform/Android/GooglePlayGameServices.hpp>
#include <UtH/Platform/Android/AndroidEngine.hpp>
#include <UtH/Platform/Debug.hpp>

// Android

using namespace uth;

//bool GooglePlayGameServices::is_auth_in_progress = false;
//std::unique_ptr<gpg::GameServices> GooglePlayGameServices::game_services;

GooglePlayGameServices::GooglePlayGameServices()
{
	//init();
}

GooglePlayGameServices::~GooglePlayGameServices()
{
	//deInit();
}

// Public

void JNI_gameActivity()
{
	// Javaenviroment: Loads enviroment from Android activity
	if (uthAndroidEngine.jni == NULL)
		uthAndroidEngine.app->activity->vm->AttachCurrentThread(&uthAndroidEngine.jni, NULL);

	// Loads our java master class GameActivity
	if (uthAndroidEngine.gameActivity == NULL)
	{
		uthAndroidEngine.gameActivity = uthAndroidEngine.jni->GetObjectClass(uthAndroidEngine.app->activity->clazz);
		if (!uthAndroidEngine.gameActivity)
			WriteError("No engine found!");
	}
}


// Achiements
void GooglePlayGameServices::Achievement::UnlockAchievement(std::string achievement_id)
{
	JNI_gameActivity();

	// Loading function
	jmethodID unlockAchFunc = NULL;
	unlockAchFunc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "UnlockAchievement", "(Ljava/lang/String;)V");
	if (unlockAchFunc == NULL)
		WriteError("No UnlockAchievement function found!");

	jstring stringArg = uthAndroidEngine.jni->NewStringUTF(achievement_id.c_str());

	uthAndroidEngine.jni->CallVoidMethod(uthAndroidEngine.app->activity->clazz, unlockAchFunc, stringArg);
}
void GooglePlayGameServices::Achievement::IncrementAchievement(std::string achievement_id, int steps)
{
	JNI_gameActivity();

	// Loading function
	jmethodID unlockAchFunc = NULL;
	unlockAchFunc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "IncrementAchievement", "(Ljava/lang/String;I)V");
	if (unlockAchFunc == NULL)
		WriteError("No IncrementAchievement function found!");

	jstring stringArg = uthAndroidEngine.jni->NewStringUTF(achievement_id.c_str());

	uthAndroidEngine.jni->CallVoidMethod(uthAndroidEngine.app->activity->clazz, unlockAchFunc, stringArg, steps);
}
void GooglePlayGameServices::Achievement::ShowAchievements()
{
	JNI_gameActivity();

	// Loading function
	jmethodID showAchFunc = NULL;
	showAchFunc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "ShowAchievements", "()V");
	if (showAchFunc == NULL)
		WriteError("No ShowAchievements function found!");

	uthAndroidEngine.jni->CallVoidMethod(uthAndroidEngine.app->activity->clazz, showAchFunc);
}

// Leaderboard
void GooglePlayGameServices::LeaderBoard::SubmitHighScore(std::string leaderboard_id, int score)
{
	JNI_gameActivity();

	// Loading function
	jmethodID submitScoreFunc = NULL;
	submitScoreFunc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "SubmitHighScore", "(Ljava/lang/String;I)V");
	if (submitScoreFunc == NULL)
		WriteError("No SubmitHighScore function found!");

	jstring stringArg = uthAndroidEngine.jni->NewStringUTF(leaderboard_id.c_str());

	uthAndroidEngine.jni->CallVoidMethod(uthAndroidEngine.app->activity->clazz, submitScoreFunc, stringArg, score);
}
void GooglePlayGameServices::LeaderBoard::ShowLeaderboard(std::string leaderboard_id)
{
	JNI_gameActivity();

	// Loading function
	jmethodID showLPFunc = NULL;
	showLPFunc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "ShowLeaderboard", "(Ljava/lang/String;)V");
	if (showLPFunc == NULL)
		WriteError("No ShowLeaderboard function found!");

	jstring stringArg = uthAndroidEngine.jni->NewStringUTF(leaderboard_id.c_str());

	uthAndroidEngine.jni->CallVoidMethod(uthAndroidEngine.app->activity->clazz, showLPFunc, stringArg);
}

// GPS
GooglePlayGameServices::Location GooglePlayGameServices::GPS::GetCurrentLocation()
{
	JNI_gameActivity();

	// Loading function
	jmethodID getCurLoc = NULL;
	getCurLoc = uthAndroidEngine.jni->GetMethodID(uthAndroidEngine.gameActivity, "GetCurrentLocation", "()Ljava/lang/String;");
	if (getCurLoc == NULL)
		WriteError("No GetCurrentLocation function found!");


	jstring location = (jstring)uthAndroidEngine.jni->CallObjectMethod(uthAndroidEngine.app->activity->clazz, getCurLoc);

	std::string returnable = uthAndroidEngine.jni->GetStringUTFChars( location, 0);

	std::string::size_type fused = returnable.find("fused");
	std::string::size_type acc = returnable.find("acc=");
	std::string::size_type et = returnable.find("et=");
	std::string::size_type timeEnd = returnable.find("]");

	std::string fusedString = returnable.substr(fused + 6, acc - fused - 7);
	std::string::size_type splitPos = fusedString.find(",", 4);

	std::string::size_type replacePos;

	std::string latitude = fusedString.substr(0, splitPos);
	replacePos = latitude.find(",");
	if (replacePos != std::string::npos)
		latitude.replace(replacePos, 1, ".");

	std::string longitude = fusedString.substr(splitPos + 1);
	replacePos = longitude.find(",");
	if (replacePos != std::string::npos)
		longitude.replace(replacePos, 1, ".");

	std::string accuracy = returnable.substr(acc + 4, 2);
	std::string time = returnable.substr(et + 4, timeEnd - et - 4);

	uthGPGS.curLocation.loc_latitude = atof(latitude.c_str());
	uthGPGS.curLocation.loc_longitude = atof(longitude.c_str());
	//curLocation.loc_accuracy = atof(accuracy.c_str());   // UnAccurate
	uthGPGS.curLocation.loc_accuracy = GetAccuracy();
	uthGPGS.curLocation.device_time_since_reboot = time;

	return uthGPGS.curLocation;
{'fraction_non_alphanumeric': 0.13365067740754302, 'fraction_numerical': 0.0021969974368363236, 'mean_word_length': 7.122676579925651, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6606154', 'n_tokens_mistral': 3644, 'n_tokens_neox': 3511, 'n_words': 565}