Ejemplo n.º 1
0
// This function is based on
// (1) convert surface to Java BitMap object
// (2) call Java PrintHelper to do print job.
const char *SurfacePrint(SDL_Surface *surface)
{
    JNIEnv *mEnv = Android_JNI_GetEnv();
    jclass mBitmapClass = (*mEnv)->FindClass(mEnv, "android/graphics/Bitmap");
    jmethodID mCreateMethod = (*mEnv)->GetStaticMethodID(mEnv, mBitmapClass, "createBitmap", "([IIILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
    jintArray mSurfaceArray = (*mEnv)->NewIntArray(mEnv, surface->w * surface->h);
    (*mEnv)->SetIntArrayRegion(mEnv,mSurfaceArray, 0, surface->w * surface->h, surface->pixels);
    jclass mConfigClass = (*mEnv)->FindClass(mEnv, "android/graphics/Bitmap$Config");
    jfieldID mConfigField = (*mEnv)->GetStaticFieldID(mEnv, mConfigClass , "ARGB_8888", "Landroid/graphics/Bitmap$Config;");
    jobject mConfig = (*mEnv)->GetStaticObjectField(mEnv, mConfigClass, mConfigField);
    jobject mBitMap = (*mEnv)->CallStaticObjectMethod(mEnv, mBitmapClass, mCreateMethod, mSurfaceArray, surface->w, surface->h, mConfig);

    jobject mContext = (jobject)SDL_AndroidGetActivity();
    jclass mPrintClass = (*mEnv)->FindClass(mEnv, "android/support/v4/print/PrintHelper");
    // sometimes android v4 support library may be not ready
    if (mPrintClass == NULL)
        return "There is no android v4 support library.";
    jmethodID mInitMethod = (*mEnv)->GetMethodID(mEnv, mPrintClass, "<init>", "(Landroid/content/Context;)V");
    jobject mPrint = (*mEnv)->NewObject(mEnv, mPrintClass, mInitMethod, mContext);
    jmethodID mPrintMethod = (*mEnv)->GetMethodID(mEnv, mPrintClass, "printBitmap", "(Ljava/lang/String;Landroid/graphics/Bitmap;)V");
    jstring mString = (*mEnv)->NewStringUTF(mEnv, "TuxPaint");
    (*mEnv)->CallVoidMethod(mEnv, mPrint, mPrintMethod, mString, mBitMap);

    // clean up
    (*mEnv)->DeleteLocalRef(mEnv, mSurfaceArray);
    (*mEnv)->DeleteLocalRef(mEnv, mConfig);
    (*mEnv)->DeleteLocalRef(mEnv, mPrint);
    (*mEnv)->DeleteLocalRef(mEnv, mString);
    return NULL;
}
Ejemplo n.º 2
0
// Get the user's reply to the connection dialog (kDialogNo for No, kDialogYes
// for Yes), or kDialogWaiting if there is no result yet. Calling this consumes
// the result.
GPGMultiplayer::DialogResponse GPGMultiplayer::GetConnectionDialogResponse() {
#ifdef __ANDROID__
  // If we are set to automatically connect, pretend this is true.
  if (auto_connect_) {
    return kDialogYes;
  }
  JNIEnv* env = reinterpret_cast<JNIEnv*>(SDL_AndroidGetJNIEnv());
  jobject activity = reinterpret_cast<jobject>(SDL_AndroidGetActivity());
  jclass fpl_class = env->GetObjectClass(activity);
  jmethodID get_query_dialog_response =
      env->GetMethodID(fpl_class, "getQueryDialogResponse", "()I");
  int result = env->CallIntMethod(activity, get_query_dialog_response);
  if (result >= 0) {
    jmethodID reset_query_dialog_response =
        env->GetMethodID(fpl_class, "resetQueryDialogResponse", "()V");
    env->CallVoidMethod(activity, reset_query_dialog_response);
  }
  env->DeleteLocalRef(fpl_class);
  env->DeleteLocalRef(activity);

  switch (result) {
    case 0:
      return kDialogNo;
    case 1:
      return kDialogYes;
    default:
      return kDialogWaiting;
  }
#else
  return kDialogWaiting;
#endif
}
Ejemplo n.º 3
0
void Android_GetMethods()
{
	env = (JNIEnv*)SDL_AndroidGetJNIEnv();
	activity = (jobject)SDL_AndroidGetActivity();
	actcls = (*env)->GetObjectClass(env, activity);
	vibrmid = (*env)->GetMethodID(env, actcls, "vibrate", "(S)V");
}
Ejemplo n.º 4
0
bool GPGMultiplayer::Initialize(const std::string& service_id) {
  state_ = kIdle;
  is_hosting_ = false;
  allow_reconnecting_ = true;

  service_id_ = service_id;
  gpg::AndroidPlatformConfiguration platform_configuration;
  platform_configuration.SetActivity((jobject)SDL_AndroidGetActivity());

  gpg::NearbyConnections::Builder nearby_builder;
  nearby_connections_ = nearby_builder.SetDefaultOnLog(gpg::LogLevel::VERBOSE)
                            .SetServiceId(service_id_)
                            .Create(platform_configuration);
  discovery_listener_.reset(nullptr);
  message_listener_.reset(nullptr);

  if (nearby_connections_ == nullptr) {
    SDL_LogError(
        SDL_LOG_CATEGORY_APPLICATION,
        "GPGMultiplayer: Unable to build a NearbyConnections instance.");
    return false;
  }

  return true;
}
Ejemplo n.º 5
0
bool IsDirectory(const tstring& sPath)
{
	// Check first to see if it's in the assets folder.
	JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();
	jobject activity = (jobject)SDL_AndroidGetActivity();
	jclass activity_class = env->GetObjectClass(activity);
	jmethodID activity_class_assetIsDirectory = env->GetMethodID(activity_class, "assetIsDirectory", "(Ljava/lang/String;)Z");

	jstring assetIsDirectory_sFile = env->NewStringUTF(sPath.c_str());
	jboolean assetIsDirectory_result = env->CallBooleanMethod(activity, activity_class_assetIsDirectory, assetIsDirectory_sFile); // activity.assetIsDirectory(file);
	bool bIsDirectory = assetIsDirectory_result;
	env->DeleteLocalRef(assetIsDirectory_sFile);

	if (bIsDirectory)
		return true;

	struct stat stFileInfo;
	bool blnReturn;
	int intStat;

	// Attempt to get the file attributes
	intStat = stat(sPath.c_str(), &stFileInfo);
	if(intStat == 0 && S_ISDIR(stFileInfo.st_mode))
		return true;
	else
		return false;
}
Ejemplo n.º 6
0
float platform_get_default_scale() {
    JNIEnv *env = SDL_AndroidGetJNIEnv();

    jobject *activity = (jobject *) SDL_AndroidGetActivity();
    jclass *activityClass = (*env)->GetObjectClass(env, activity);
    jmethodID getDefaultScale = (*env)->GetMethodID(env, activityClass, "getDefaultScale", "()F");

    jfloat displayScale = (*env)->CallFloatMethod(env, activity, getDefaultScale);

    (*env)->DeleteLocalRef(env, activity);
    (*env)->DeleteLocalRef(env, activityClass);

    return displayScale;
}
Ejemplo n.º 7
0
// Show a dialog box, allowing the user to reply to a Yes or No question.
bool GPGMultiplayer::DisplayConnectionDialog(const char* title,
                                             const char* question_text,
                                             const char* yes_text,
                                             const char* no_text) {
#ifdef __ANDROID__
  if (auto_connect_) {
    return true;
  }
  bool question_shown = false;

  JNIEnv* env = reinterpret_cast<JNIEnv*>(SDL_AndroidGetJNIEnv());
  jobject activity = reinterpret_cast<jobject>(SDL_AndroidGetActivity());
  jclass fpl_class = env->GetObjectClass(activity);
  jmethodID is_text_dialog_open =
      env->GetMethodID(fpl_class, "isTextDialogOpen", "()Z");
  jboolean open = env->CallBooleanMethod(activity, is_text_dialog_open);
  jmethodID get_query_dialog_response =
      env->GetMethodID(fpl_class, "getQueryDialogResponse", "()I");
  int response = env->CallIntMethod(activity, get_query_dialog_response);

  if (!open && response == -1) {
    jmethodID show_query_dialog =
        env->GetMethodID(fpl_class, "showQueryDialog",
                         "(Ljava/lang/String;Ljava/lang/String;"
                         "Ljava/lang/String;Ljava/lang/String;)V");
    jstring titlej = env->NewStringUTF(title);
    jstring questionj = env->NewStringUTF(question_text);
    jstring yesj = env->NewStringUTF(yes_text);
    jstring noj = env->NewStringUTF(no_text);
    env->CallVoidMethod(activity, show_query_dialog, titlej, questionj, yesj,
                        noj);
    env->DeleteLocalRef(titlej);
    env->DeleteLocalRef(questionj);
    env->DeleteLocalRef(yesj);
    env->DeleteLocalRef(noj);
    question_shown = true;
  }
  env->DeleteLocalRef(fpl_class);
  env->DeleteLocalRef(activity);
  return question_shown;
#else
  (void)title;
  (void)question_text;
  (void)yes_text;
  (void)no_text;
  return false;
#endif
}
Ejemplo n.º 8
0
tvector<tstring> ListAndroidAssetsDirectory(const tstring& sDirectory, bool bDirectories)
{
	JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();
	jobject activity = (jobject)SDL_AndroidGetActivity();

	jclass activity_class = env->GetObjectClass(activity);
	jmethodID activity_class_assetOpenDir = env->GetMethodID(activity_class, "assetOpenDir", "(Ljava/lang/String;)Z");
	jstring assetOpenDir_sDirectory = env->NewStringUTF(sDirectory.c_str());
	jboolean assetOpenDir_success = env->CallBooleanMethod(activity, activity_class_assetOpenDir, assetOpenDir_sDirectory); // activity.assetOpenDir(sDirectory);
	env->DeleteLocalRef(assetOpenDir_sDirectory);

	if (!assetOpenDir_success)
		return tvector<tstring>();

	tvector<tstring> asResult;
	const char* pszDir;

	jmethodID activity_class_assetGetNext = env->GetMethodID(activity_class, "assetGetNext", "()Ljava/lang/String;");
	jmethodID activity_class_assetIsDirectory = env->GetMethodID(activity_class, "assetIsDirectory", "(Ljava/lang/String;)Z");

	jstring dir;

	while ((dir = (jstring)env->CallObjectMethod(activity, activity_class_assetGetNext)) != NULL)
	{
		const char* pszDir = env->GetStringUTFChars(dir, nullptr);
		tstring sDir = pszDir;
		env->ReleaseStringUTFChars(dir, pszDir);

		tstring sFullDir = sDirectory + "/" + sDir;

		if (!bDirectories)
		{
			jstring assetIsDirectory_sFile = env->NewStringUTF(sFullDir.c_str());
			jboolean assetIsDirectory_result = env->CallBooleanMethod(activity, activity_class_assetIsDirectory, assetIsDirectory_sFile); // activity.assetIsDirectory(file);
			bool bIsDirectory = assetIsDirectory_result;
			env->DeleteLocalRef(assetIsDirectory_sFile);

			if (bIsDirectory)
				continue;
		}

		asResult.push_back(sDir);
	}

	return asResult;
}
Ejemplo n.º 9
0
void InitializeAssetManager()
{
	if (!global_asset_manager)
	{
		JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();

		jobject activity = (jobject)SDL_AndroidGetActivity();

		jclass activity_class = env->GetObjectClass(activity);

		jmethodID activity_class_getAssets = env->GetMethodID(activity_class, "getAssets", "()Landroid/content/res/AssetManager;");
		jobject asset_manager = env->CallObjectMethod(activity, activity_class_getAssets); // activity.getAssets();
		global_asset_manager = env->NewGlobalRef(asset_manager);

		g_pAssetManager = AAssetManager_fromJava(env, global_asset_manager);
	}
}
Ejemplo n.º 10
0
void EnableMulticast()
{
	//WifiManager.MulticastLock mclock;
	//WifiManager wifimanager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
	//if (wifimanager != null)
	//{
	//	mclock = wifimanager.createMulticastLock("lock");
	//	mcLock.acquire();
	//}

	JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();
	jobject activity = (jobject)SDL_AndroidGetActivity();

	jclass activity_class = env->GetObjectClass(activity);
	jmethodID activity_class_getSystemService = env->GetMethodID(activity_class, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
	jstring getSystemService_wifi = env->NewStringUTF("wifi");
	jobject wifimanager = env->CallObjectMethod(activity, activity_class_getSystemService, getSystemService_wifi); // activity.getSystemService(Context.WIFI_SERVICE);
	env->DeleteLocalRef(getSystemService_wifi);

	if (wifimanager == nullptr)
	{
		DebugPrint("ERROR: Couldn't get WifiManager to enable multicast.\n");
		return;
	}

	jclass wifimanager_class = env->GetObjectClass(wifimanager);
	jmethodID wifimanager_class_createMulticastLock = env->GetMethodID(wifimanager_class, "createMulticastLock", "(Ljava/lang/String;)Landroid/net/wifi/WifiManager$MulticastLock;");
	jstring createMulticastLock_lock = env->NewStringUTF("tinker_multicast_lock");
	jobject mclock = env->CallObjectMethod(wifimanager, wifimanager_class_createMulticastLock, createMulticastLock_lock); // wifimanager.createMulticastLock("lock");
	env->DeleteLocalRef(createMulticastLock_lock);

	if (mclock == nullptr)
	{
		DebugPrint("ERROR: Couldn't get multicast lock object.\n");
		return;
	}

	jobject global_mclock = env->NewGlobalRef(mclock);

	jclass mclock_class = env->GetObjectClass(mclock);
	jmethodID mclock_class_acquire = env->GetMethodID(mclock_class, "acquire", "()V");
	env->CallVoidMethod(mclock, mclock_class_acquire); // mclock.acquire();

	DebugPrint("Acquired multicast lock.\n");
}
Ejemplo n.º 11
0
std::string AndroidGetPackageName()
{
	JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();

	jobject activity = (jobject)SDL_AndroidGetActivity();
	jclass clazz(env->GetObjectClass(activity));

	jmethodID method_id = env->GetMethodID(clazz, "getPackageName", "()Ljava/lang/String;");
	jstring packageName = (jstring)env->CallObjectMethod(activity,  method_id);
	const char* name = env->GetStringUTFChars(packageName, NULL);
	std::string result(name);
	env->ReleaseStringUTFChars(packageName, name);

	env->DeleteLocalRef(activity);
	env->DeleteLocalRef(clazz);

	return result;
}
Ejemplo n.º 12
0
void GetScreenDPI(float& xdpi, float& ydpi)
{
	JNIEnv* env = (JNIEnv*)SDL_AndroidGetJNIEnv();
	jobject activity = (jobject)SDL_AndroidGetActivity();

	jclass activity_class = env->GetObjectClass(activity);
	jmethodID activity_class_getResources = env->GetMethodID(activity_class, "getResources", "()Landroid/content/res/Resources;");
	jobject resources = env->CallObjectMethod(activity, activity_class_getResources); // activity.getResources();

	jclass resources_class = env->GetObjectClass(resources);
	jmethodID resources_class_getDisplayMetrics = env->GetMethodID(resources_class, "getDisplayMetrics", "()Landroid/util/DisplayMetrics;");
	jobject display_metrics = env->CallObjectMethod(resources, resources_class_getDisplayMetrics); // resources.getDisplayMetrics();

	jclass display_metrics_class = env->GetObjectClass(display_metrics);
	jfieldID xdpi_field = env->GetFieldID(display_metrics_class, "xdpi", "F");
	jfieldID ydpi_field = env->GetFieldID(display_metrics_class, "ydpi", "F");

	xdpi = env->GetFloatField(display_metrics, xdpi_field);
	ydpi = env->GetFloatField(display_metrics, ydpi_field);
}
Ejemplo n.º 13
0
void AndroidSetScalerResolution(const vec2i& resolution) {
  // Check against the real size of the device
  JNIEnv* env = reinterpret_cast<JNIEnv*>(SDL_AndroidGetJNIEnv());
  jobject activity = reinterpret_cast<jobject>(SDL_AndroidGetActivity());
  jclass fpl_class = env->GetObjectClass(activity);
  jmethodID get_size =
      env->GetMethodID(fpl_class, "GetLandscapedSize", "()[I");
  jintArray size = (jintArray)env->CallObjectMethod(activity, get_size);
  jint* size_ints = env->GetIntArrayElements(size, NULL);

  int width = std::min(size_ints[0], resolution.x());
  int height = std::min(size_ints[1], resolution.y());
  g_android_scaler_resolution = vec2i(width, height);

  // Update the underlying activity with the scaled resolution
  jmethodID set_resolution =
      env->GetMethodID(fpl_class, "SetHeadMountedDisplayResolution", "(II)V");
  env->CallVoidMethod(activity, set_resolution, width, height);

  env->ReleaseIntArrayElements(size, size_ints, JNI_ABORT);
  env->DeleteLocalRef(size);
  env->DeleteLocalRef(fpl_class);
  env->DeleteLocalRef(activity);
}
Ejemplo n.º 14
0
bool GooglePlayPersister::init() {
	info(LOG_SYSTEM, "GoolePlayPersister::init() initializing...");
#ifdef GOOGLEPLAY_ACTIVE
	GPLocalReferenceHolder refs;

	JNIEnv *env = static_cast<JNIEnv*>(SDL_AndroidGetJNIEnv());
	if (env == nullptr) {
		error(LOG_SYSTEM, "GoolePlayPersister::init() failed to init the google play persister - no env pointer");
		return false;
	}
	if (!refs.init(env)) {
		error(LOG_SYSTEM, "GoolePlayPersister::init(): could not init the ref holder");
		return false;
	}

	jobject activity = static_cast<jobject>(SDL_AndroidGetActivity());
	jclass cls = env->GetObjectClass(activity);

	_env = env;
	_cls = reinterpret_cast<jclass>(_env->NewGlobalRef(cls));

	_persisterInit = env->GetStaticMethodID(_cls, "persisterInit", "()Z");
	if (_persisterInit == 0) {
		error(LOG_SYSTEM, "Could not get the jni bindings for persisterInit");
		_env = nullptr;
		return false;
	}
	_persisterConnect = env->GetStaticMethodID(_cls, "persisterConnect", "()Z");
	if (_persisterConnect == 0) {
		error(LOG_SYSTEM, "Could not get the jni bindings for persisterConnect");
		_env = nullptr;
		return false;
	}
	_persisterDisconnect = env->GetStaticMethodID(_cls, "persisterDisconnect", "()Z");
	if (_persisterDisconnect == 0) {
		error(LOG_SYSTEM, "Could not get the jni bindings for persisterDisconnect");
		_env = nullptr;
		return false;
	}

	_saveGameState = _env->GetStaticMethodID(_cls, "saveGameState", "([B)V");
	if (_saveGameState == 0) {
		error(LOG_SYSTEM, "Could not get the jni bindings for saveGameState");
		_env = nullptr;
		return false;
	}

	_loadGameState = _env->GetStaticMethodID(_cls, "loadGameState", "()[B");
	if (_loadGameState == 0) {
		error(LOG_SYSTEM, "Could not get the jni bindings for loadGameState");
		_env = nullptr;
		return false;
	}

	_showLeaderBoard = _env->GetStaticMethodID(_cls, "showLeaderBoard", "(Ljava/lang/String;)V");
	if (_showLeaderBoard == 0) {
		error(LOG_SYSTEM, "Could not get the jni bindings for showLeaderBoard");
		_env = nullptr;
		return false;
	}

	_showAchievements = _env->GetStaticMethodID(_cls, "showAchievements", "()V");
	if (_showAchievements == 0) {
		error(LOG_SYSTEM, "Could not get the jni bindings for showAchievements");
		_env = nullptr;
		return false;
	}

	_addPointsToLeaderBoard  = _env->GetStaticMethodID(_cls, "addPointsToLeaderBoard", "(Ljava/lang/String;I)V");
	if (_addPointsToLeaderBoard == 0) {
		error(LOG_SYSTEM, "Could not get the jni bindings for addPointsToLeaderBoard");
		_env = nullptr;
		return false;
	}

	_env->CallStaticVoidMethod(_cls, _persisterInit);

	info(LOG_SYSTEM, "GoolePlayPersister::init() initialized");
#endif
	_delegate->init();
	if (Config.getConfigVar("googleplaystate")->getBoolValue()) {
		connect();
	}
	return true;
}
Ejemplo n.º 15
0
void Joystick_Init(void)
{
	joy[0] = 1;  // とりあえず一つ目だけ有効
	joy[1] = 0;
	JoyKeyState = 0;
	JoyKeyState0 = 0;
	JoyKeyState1 = 0;
	JoyState0[0] = 0xff;
	JoyState0[1] = 0xff;
	JoyState1[0] = 0xff;
	JoyState1[1] = 0xff;
	JoyPortData[0] = 0;
	JoyPortData[1] = 0;
#ifdef ANDROID
	float density;
	int i;

	JNIEnv *env = (JNIEnv *)SDL_AndroidGetJNIEnv();
	// DisplayMetrics
	jclass dispmetrics_class = (*env)->FindClass(env, "android/util/DisplayMetrics");
	// new DisplayMetrics()
	jmethodID dispmetrics_init = (*env)->GetMethodID(env, dispmetrics_class, "<init>", "()V");
	jobject *obj0;
	jobject *obj1;

	// SDLActivity.getContext
	obj0 = (jobject *)SDL_AndroidGetActivity();
	// SDLActivity.getContext.getWindowManager
	obj1 = (*env)->CallObjectMethod(
		env,
		obj0,
		(*env)->GetMethodID(env, (*env)->GetObjectClass(env, obj0),
                	"getWindowManager", "()Landroid/view/WindowManager;"));
	// SDLActivity.getContext.getWindowManager().getDefaultDisplay()
	obj0 = (*env)->CallObjectMethod(
		env,
		obj1,
		(*env)->GetMethodID(env, (*env)->GetObjectClass(env, obj1),
                	"getDefaultDisplay", "()Landroid/view/Display;"));
	// obj1 = new DisplayMetrics();
	obj1 = (*env)->NewObject(env, dispmetrics_class, dispmetrics_init);
	// SDLActivity.getContext.getWindowManager().getDefaultDisplay().getMetrics(obj1);
	(*env)->CallObjectMethod(
		env,
		obj0,
		(*env)->GetMethodID(env, (*env)->GetObjectClass(env, obj0),
                	"getMetrics", "(Landroid/util/DisplayMetrics;)V"),
		obj1);
	// density(C) = obj1.density
	density = (float)((*env)->GetFloatField(
		env,
		obj1,
		(*env)->GetFieldID(env, dispmetrics_class, "density", "F")));

	for (i = 0; i < VBTN_MAX; i++) {
		vbtn_state[i] = VBTN_NOUSE;
	}

	// 一辺64dpの正方形
	vbtn_width = vbtn_height = (int)(64 * density / realdisp_w * 800);

	// 左右上下 (上上下下左右左右BAではない)
	SET_VBTN(0, 16, 120, VBTN_REF_DOWN + VBTN_REF_LEFT);
	SET_VBTN(1, 176, 120, VBTN_REF_DOWN + VBTN_REF_LEFT);
	SET_VBTN(2, 96, 160, VBTN_REF_DOWN + VBTN_REF_LEFT);
	SET_VBTN(3, 96, 80, VBTN_REF_DOWN + VBTN_REF_LEFT);

	// ボタン
	SET_VBTN(4, 160, 80, VBTN_REF_DOWN + VBTN_REF_RIGHT);
	SET_VBTN(5, 80, 160, VBTN_REF_DOWN + VBTN_REF_RIGHT);
#endif
}
Ejemplo n.º 16
0
bool GPGManager::Initialize(bool ui_login) {
  state_ = kStart;
  do_ui_login_ = ui_login;
  event_data_initialized_ = false;
  achievement_data_initialized_ = false;
  player_data_.reset(nullptr);
#ifdef NO_GPG
  return true;
#endif

  /*
  // This code is here because we may be able to do this part of the
  // initialization here in the future, rather than relying on JNI_OnLoad below.
  auto env = reinterpret_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());
  JavaVM *vm = nullptr;
  auto ret = env->GetJavaVM(&vm);
  assert(ret >= 0);
  gpg::AndroidInitialization::JNI_OnLoad(vm);
  */
  gpg::AndroidPlatformConfiguration platform_configuration;
  platform_configuration.SetActivity((jobject)SDL_AndroidGetActivity());

  // Creates a games_services object that has lambda callbacks.
  game_services_ =
      gpg::GameServices::Builder()
          .SetDefaultOnLog(gpg::LogLevel::VERBOSE)
          .SetOnAuthActionStarted([this](gpg::AuthOperation op) {
            state_ =
                state_ == kAuthUILaunched ? kAuthUIStarted : kAutoAuthStarted;
            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
                        "GPG: Sign in started! (%d)", state_);
          })
          .SetOnAuthActionFinished([this](gpg::AuthOperation op,
                                          gpg::AuthStatus status) {
            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
                        "GPG: Sign in finished with a result of %d (%d)",
                        status, state_);
            if (op == gpg::AuthOperation::SIGN_IN) {
              state_ =
                  status == gpg::AuthStatus::VALID
                      ? kAuthed
                      : ((state_ == kAuthUIStarted || state_ == kAuthUILaunched)
                             ? kAuthUIFailed
                             : kAutoAuthFailed);
              if (state_ == kAuthed) {
                // If we just logged in, go fetch our data!
                FetchPlayer();
                FetchEvents();
                FetchAchievements();
              }
            } else if (op == gpg::AuthOperation::SIGN_OUT) {
              state_ = kStart;
              SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
                          "GPG: SIGN OUT finished with a result of %d", status);
            } else {
              SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
                          "GPG: unknown auth op %d", op);
            }
          })
          .Create(platform_configuration);

  if (!game_services_) {
    SDL_LogError(SDL_LOG_CATEGORY_ERROR, "GPG: failed to create GameServices!");
    return false;
  }

  SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "GPG: created GameServices");
  return true;
}
Ejemplo n.º 17
0
 jobject activity() {
     return (jobject)SDL_AndroidGetActivity();
 } //activity