/** @name init @text Initialize Twitter. @in string consumerKey OAuth consumer key @in string consumerSecret OAuth consumer secret @in string callbackUrl Available in Twitter developer settings. @out nil */ int MOAITwitterAndroid::_init ( lua_State* L ) { MOAILuaState state ( L ); cc8* consumerKey = lua_tostring ( state, 1 ); cc8* consumerSecret = lua_tostring ( state, 2 ); cc8* callbackUrl = lua_tostring ( state, 3 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( consumerKey , jconsumerKey ); JNI_GET_JSTRING ( consumerSecret , jconsumerSecret ); JNI_GET_JSTRING ( callbackUrl , jcallbackUrl ); jclass twitter = env->FindClass ( "com/ziplinegames/moai/MoaiTwitter" ); if ( twitter == NULL ) { ZLLog::Print ( "MOAITwitterAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiTwitter" ); } else { jmethodID init = env->GetStaticMethodID ( twitter, "init", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V" ); if ( init == NULL ) { ZLLog::Print ( "MOAITwitterAndroid: Unable to find static java method %s", "init" ); } else { env->CallStaticVoidMethod ( twitter, init, jconsumerKey, jconsumerSecret, jcallbackUrl); } } return 0; }
int MYMMOAIAmazonAnalytics::_init(lua_State* L) { MOAILuaState state(L); cc8* appKey = lua_tostring(state, 1); cc8* privateKey = lua_tostring(state, 2); JNI_GET_ENV (jvm, env); JNI_GET_JSTRING (appKey, jappKey); JNI_GET_JSTRING (privateKey, jprivateKey); jclass analytics = env->FindClass("com/meyume/moai/MYMAmazonAnalytics"); if (analytics == NULL) { ZLLog::LogF ( ZLLog::CONSOLE, "MYMMOAIAmazonAnalytics: Unable to find java class %s", "com/meyume/moai/MYMAmazonAnalytics"); } else { jmethodID init = env->GetStaticMethodID (analytics, "init", "(Ljava/lang/String;Ljava/lang/String;)V"); if (init == NULL) { ZLLog::LogF ( ZLLog::CONSOLE, "MYMMOAIAmazonAnalytics: Unable to find static java method %s", "init"); } else { env->CallStaticVoidMethod(analytics, init, jappKey, jprivateKey); } } return 0; }
/** @name sendMail @text Send a mail with the passed in default values @in string recipient @in string subject @in string message @out nil */ int MOAIAppAndroid::_sendMail ( lua_State* L ) { MOAILuaState state ( L ); cc8* recipient = state.GetValue < cc8* >( 1, "" ); cc8* subject = state.GetValue < cc8* >( 2, "" ); cc8* message = state.GetValue < cc8* >( 3, "" ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( recipient, jrecipient ); JNI_GET_JSTRING ( subject, jsubject ); JNI_GET_JSTRING ( message, jmessage ); jclass moai = env->FindClass ( "com/ziplinegames/moai/Moai" ); if ( moai == NULL ) { ZLLog::Print ( "MOAIAppAndroid: Unable to find java class %s", "com/ziplinegames/moai/Moai" ); } else { jmethodID sendMail = env->GetStaticMethodID ( moai, "sendMail", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V" ); if ( sendMail == NULL ) { ZLLog::Print ( "MOAIAppAndroid: Unable to find static java method %s", "sendMail" ); } else { env->CallStaticVoidMethod ( moai, sendMail, jrecipient, jsubject, jmessage ); } } return 0; }
/** * Create Android Bundle from the Lua stack * @param L The Lua stack * @param The index to convert */ jobject JniUtils::bundleFromLua ( lua_State* L, int index ) { MOAILuaState state ( L ); JNI_GET_ENV ( jvm, env ); STLString className = "android.os.Bundle"; jobject bundle = JniUtils::createObjectOfClass( className ); jmethodID put = JniUtils::getMethod( className, "putString", "(Ljava/lang/String;Ljava/lang/String;)V" ); // table is in the stack at index 'index' lua_pushnil ( state ); // first key while ( lua_next ( state, index ) != 0 ) { // use the 'key' (at index -2) and 'value' (at index -1) cc8* key = lua_tostring( state, -2 ); if( key != NULL ) { cc8* value = lua_tostring( state, -1 ); if ( value != NULL ) { JNI_GET_JSTRING ( key, jkey ); JNI_GET_JSTRING ( value, jvalue ); env->CallObjectMethod( bundle, put, jkey, jvalue ); } } // removes 'value'; keeps 'key' for next iteration lua_pop ( state, 1 ); } return bundle; }
/** @name setAccessToken @text Set the access token that authenticates the user. @in string token OAuth token @in string tokenSecret OAuth token secret @out nil */ int MOAITwitterAndroid::_setAccessToken ( lua_State* L ) { MOAILuaState state ( L ); cc8* token = lua_tostring ( state, 1 ); cc8* tokenSecret = lua_tostring ( state, 2 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( token , jtoken ); JNI_GET_JSTRING ( tokenSecret , jtokenSecret ); jclass twitter = env->FindClass ( "com/ziplinegames/moai/MoaiTwitter" ); if ( twitter == NULL ) { ZLLog::Print ( "MOAITwitterAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiTwitter" ); } else { jmethodID setAccessToken = env->GetStaticMethodID ( twitter, "setAccessToken", "(Ljava/lang/String;Ljava/lang/String;)V" ); if ( setAccessToken == NULL ) { ZLLog::Print ( "MOAITwitterAndroid: Unable to find static java method %s", "setAccessToken" ); } else { env->CallStaticVoidMethod ( twitter, setAccessToken, jtoken, jtokenSecret ); } } return 0; }
/** @lua setPoint @text Records a point to the leaderboard @in string score ( convert number to string in Lua ) @in string pointName ( score + "points" or score + "rubies" ) @out nil */ int MOAITstoreGamecenterAndroid::_setPoint ( lua_State* L ) { MOAILuaState state ( L ); cc8* score = lua_tostring ( state, 1 ); cc8* name = lua_tostring ( state, 2 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( name, jname ) JNI_GET_JSTRING ( score, jscore ) jclass tstore = env->FindClass ( "com/ziplinegames/moai/MoaiTstoreGamecenter" ); if ( tstore == NULL ) { ZLLog::LogF ( ZLLog::CONSOLE, "MOAITstoreGamecenterAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiTstoreGamecenter" ); } else { jmethodID setPoint = env->GetStaticMethodID ( tstore, "setPoint", "(Ljava/lang/String;Ljava/lang/String;)V" ); if ( setPoint == NULL ) { ZLLog::LogF ( ZLLog::CONSOLE, "MOAITstoreGamecenterAndroid: Unable to find static java method %s", "setPoint" ); } else { env->CallStaticVoidMethod ( tstore, setPoint, jscore, jname ); } } return 0; }
/** @name init @text Initialize ChartBoost. @in string appId Available in ChartBoost dashboard settings. @in string appSignature Available in ChartBoost dashboard settings. @out nil */ int MOAIChartBoostAndroid::_init ( lua_State* L ) { MOAILuaState state ( L ); cc8* identifier = lua_tostring ( state, 1 ); cc8* signature = lua_tostring ( state, 2 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( identifier, jidentifier ); JNI_GET_JSTRING ( signature, jsignature ); jclass chartboost = env->FindClass ( "com/ziplinegames/moai/MoaiChartBoost" ); if ( chartboost == NULL ) { ZLLog::Print ( "MOAIChartBoostAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiChartBoost" ); } else { jmethodID init = env->GetStaticMethodID ( chartboost, "init", "(Ljava/lang/String;Ljava/lang/String;)V" ); if ( init == NULL ) { ZLLog::Print ( "MOAIChartBoostAndroid: Unable to find static java method %s", "init" ); } else { env->CallStaticVoidMethod ( chartboost, init, jidentifier, jsignature ); } } return 0; }
/** @name share @text Open a generic Android dialog to allow the user to share via email, SMS, Facebook, Twitter, etc. @in string prompt The prompt to show the user. @in string subject The subject of the message to share. @in string text The text of the message to share. @out nil */ int MOAIAppAndroid::_share ( lua_State* L ) { MOAILuaState state ( L ); cc8* prompt = lua_tostring ( state, 1 ); cc8* subject = lua_tostring ( state, 2 ); cc8* text = lua_tostring ( state, 3 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( prompt, jprompt ); JNI_GET_JSTRING ( subject, jsubject ); JNI_GET_JSTRING ( text, jtext ); jclass moai = env->FindClass ( "com/ziplinegames/moai/Moai" ); if ( moai == NULL ) { USLog::Print ( "MOAIAppAndroid: Unable to find java class %s", "com/ziplinegames/moai/Moai" ); } else { jmethodID share = env->GetStaticMethodID ( moai, "share", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V" ); if ( share == NULL ) { USLog::Print ( "MOAIAppAndroid: Unable to find static java method %s", "share" ); } else { env->CallStaticVoidMethod ( moai, share, jprompt, jsubject, jtext ); } } return 0; }
/** @name showDialog @text Show a native dialog to the user. @in string title The title of the dialog box. Can be nil. @in string message The message to show the user. Can be nil. @in string positive The text for the positive response dialog button. Can be nil. @in string neutral The text for the neutral response dialog button. Can be nil. @in string negative The text for the negative response dialog button. Can be nil. @in bool cancelable Specifies whether or not the dialog is cancelable @opt function callback A function to callback when the dialog is dismissed. Default is nil. @out nil */ int MOAIDialogAndroid::_showDialog ( lua_State* L ) { MOAILuaState state ( L ); cc8* title = lua_tostring ( state, 1 ); cc8* message = lua_tostring ( state, 2 ); cc8* positive = lua_tostring ( state, 3 ); cc8* neutral = lua_tostring ( state, 4 ); cc8* negative = lua_tostring ( state, 5 ); bool cancelable = lua_toboolean ( state, 6 ); if ( state.IsType ( 7, LUA_TFUNCTION )) { // NOTE: This is fragile. We're storing the callback function in a global variable, // effectively. Invoking the showDialog method multiple times in succession can // therefore lead to unpredictable results. In fact, it's unknown how Android itself // handles multiple invocations - are they queued? On iOS, UIAlertView is LIFO and // new invocations supersede previous ones, but once dismissed, the system continues // down the alert stack. MOAIDialogAndroid::Get ().mDialogCallback.SetStrongRef ( state, 7 ); } JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( title, jtitle ); JNI_GET_JSTRING ( message, jmessage ); JNI_GET_JSTRING ( positive, jpositive ); JNI_GET_JSTRING ( neutral, jneutral ); JNI_GET_JSTRING ( negative, jnegative ); jclass moai = env->FindClass ( "com/ziplinegames/moai/Moai" ); if ( moai == NULL ) { ZLLog::Print ( "MOAIDialogAndroid: Unable to find java class %s", "com/ziplinegames/moai/Moai" ); } else { jmethodID showDialog = env->GetStaticMethodID ( moai, "showDialog", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V" ); if ( showDialog == NULL ) { ZLLog::Print ( "MOAIDialogAndroid: Unable to find static java method %s", "showDialog" ); } else { env->CallStaticVoidMethod ( moai, showDialog, jtitle, jmessage, jpositive, jneutral, jnegative, cancelable ); } } return 0; }
/** @lua unlockAchievement @text Grants an achievement to the player @in string achievementID @out nil */ int MOAIGooglePlayServicesAndroid::_unlockAchievement ( lua_State* L ) { JNI_GET_ENV ( jvm, env ); MOAILuaState state ( L ); cc8* ach = lua_tostring ( state, 1 ); MOAIJString jach = JNI_GET_JSTRING ( ach ); jclass playserv = env->FindClass ( "com/moaisdk/googleplayservices/MoaiGooglePlayServices" ); if ( playserv == NULL ) { ZLLog::LogF ( 1, ZLLog::CONSOLE, "MOAIGooglePlayServicesAndroid: Unable to find java class %s", "com/moaisdk/googleplayservices/MoaiGooglePlayServices" ); } else { jmethodID unlockAchievement = env->GetStaticMethodID ( playserv, "unlockAchievement", "(Ljava/lang/String;)V" ); if ( unlockAchievement == NULL ) { ZLLog::LogF ( 1, ZLLog::CONSOLE, "MOAIGooglePlayServicesAndroid: Unable to find static java method %s", "unlockAchievement" ); } else { env->CallStaticVoidMethod ( playserv, unlockAchievement, ( jstring )jach ); } } return 0; }
int MYMMOAIAmazonAnalytics::_recordEvent(lua_State* L) { MOAILuaState state(L); JNI_GET_ENV (jvm, env); cc8* event = lua_tostring(state, 1); int count = lua_tointeger(state, 2); int top = state.GetTop (); jobjectArray array = (jobjectArray)env->NewObjectArray(top, env->FindClass("java/lang/String"), env->NewStringUTF("")); for ( int i = 3; i <= top; ++i ) { if ( state.IsType ( i, LUA_TSTRING )) { cc8* p = state.GetValue < cc8* >( i, "" ); env->SetObjectArrayElement(array, i - 3, env->NewStringUTF(p)); } } JNI_GET_JSTRING (event, jevent); jclass analytics = env->FindClass("com/meyume/moai/MYMAmazonAnalytics"); if (analytics == NULL) { ZLLog::LogF ( ZLLog::CONSOLE, "MYMAmazonAnalytics: Unable to find java class %s", "com/meyume/moai/MYMAmazonAnalytics"); } else { jmethodID recordEvent = env->GetStaticMethodID (analytics, "recordEvent", "(Ljava/lang/String;I[Ljava/lang/String;)V"); if (recordEvent == NULL) { ZLLog::LogF ( ZLLog::CONSOLE, "MYMAmazonAnalytics: Unable to find static java method %s", "recordEvent"); } else { env->CallStaticVoidMethod(analytics, recordEvent, jevent, count, array); } } return 0; }
/** @name showBanner @text Show AdMob banner. @in string adUnitId @out nil */ int MOAIAdMobAndroid::_showBanner ( lua_State* L ) { MOAILuaState state ( L ); cc8* adUnitId = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( adUnitId, jadUnitId ); jclass admob = env->FindClass ( "com/ziplinegames/moai/MoaiAdMob" ); if ( admob == NULL ) { USLog::Print ( "MOAIAdMobAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiAdMob" ); } else { jmethodID showBanner = env->GetStaticMethodID ( admob, "showBanner", "(Ljava/lang/String;)V" ); if ( showBanner == NULL ) { USLog::Print ( "MOAIAdMobAndroid: Unable to find static java method %s", "showBanner" ); } else { env->CallStaticVoidMethod ( admob, showBanner, jadUnitId ); } } return 0; }
/** @name setTimer @text Sets the timer value. @in id Id @in value Timer value @out nil */ int MOAIAppAndroid::_setTimer ( lua_State* L ) { MOAILuaState state ( L ); cc8* id = lua_tostring ( state, 1 ); int value = lua_tointeger ( state, 2 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( id, jid ); jclass moai = env->FindClass ( "com/ziplinegames/moai/Moai" ); if ( moai == NULL ) { USLog::Print ( "MOAIAppAndroid: Unable to find java class %s", "com/ziplinegames/moai/Moai" ); } else { jmethodID setTimer = env->GetStaticMethodID ( moai, "setTimer", "(Ljava/lang/String;I)V" ); if ( setTimer == NULL ) { USLog::Print ( "MOAIAppAndroid: Unable to find static java method %s", "setTimer" ); } else { env->CallStaticVoidMethod ( moai, setTimer, jid, value ); } } return 0; }
/** @name getTimer @text Gets the timer value. @in id Id @out value Timer value */ int MOAIAppAndroid::_getTimer ( lua_State* L ) { MOAILuaState state ( L ); cc8* id = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( id, jid ); int outVal = 0; jclass moai = env->FindClass ( "com/ziplinegames/moai/Moai" ); if ( moai == NULL ) { USLog::Print ( "MOAIAppAndroid: Unable to find java class %s", "com/ziplinegames/moai/Moai" ); } else { jmethodID getTimer = env->GetStaticMethodID ( moai, "getTimer", "(Ljava/lang/String;)I" ); if ( getTimer == NULL ) { USLog::Print ( "MOAIAppAndroid: Unable to find static java method %s", "getTimer" ); } else { outVal = env->CallStaticIntMethod ( moai, getTimer, jid ); } } lua_pushnumber ( L, outVal ); return 1; }
/** @name setToken @text Set the Facebook login token. @in string token The login token. See Facebook documentation. @out nil */ int MOAIFacebookAndroid::_setToken ( lua_State* L ) { MOAILuaState state ( L ); cc8* token = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( token, jtoken ); jclass facebook = env->FindClass ( "com/ziplinegames/moai/MoaiFacebook" ); if ( facebook == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiFacebook" ); } else { jmethodID setToken = env->GetStaticMethodID ( facebook, "setToken", "(Ljava/lang/String;)V" ); if ( setToken == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find static java method %s", "setToken" ); } else { env->CallStaticVoidMethod ( facebook, setToken, jtoken ); } } return 0; }
/** @name init @text Initialize Facebook. @in string appId Available in Facebook developer settings. @out nil */ int MOAIFacebookAndroid::_init ( lua_State* L ) { MOAILuaState state ( L ); cc8* identifier = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( identifier, jidentifier ); jclass facebook = env->FindClass ( "com/ziplinegames/moai/MoaiFacebook" ); if ( facebook == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiFacebook" ); } else { jmethodID init = env->GetStaticMethodID ( facebook, "init", "(Ljava/lang/String;)V" ); if ( init == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find static java method %s", "init" ); } else { env->CallStaticVoidMethod ( facebook, init, jidentifier ); } } return 0; }
/** * Create a jobjectArray from the Lua stack * @param lua_state The lua Stack * @param index The index to convert */ jobjectArray JniUtils::arrayFromLua ( lua_State* L, int index ) { MOAILuaState state ( L ); JNI_GET_ENV ( jvm, env ); int numEntries = 0; for ( int key = 1; ; ++key ) { state.GetField ( 1, key ); cc8* value = JniUtils::parseLuaTable ( state, -1 ); lua_pop ( state, 1 ); if ( !value ) { numEntries = key - 1; break; } } jobjectArray array = env->NewObjectArray ( numEntries, env->FindClass( "java/lang/String" ), 0 ); for ( int key = 1; ; ++key ) { state.GetField ( 1, key ); cc8* value = JniUtils::parseLuaTable ( state, -1 ); lua_pop ( state, 1 ); if ( value ) { JNI_GET_JSTRING ( value, jvalue ); env->SetObjectArrayElement ( array, key - 1, jvalue ); } else { break; } } return array; }
/** @lua submitScore @text Submits a score for the passed in leaderboard @in string leaderboardID @in number score @out nil */ int MOAIGooglePlayServicesAndroid::_submitScore ( lua_State* L ) { JNI_GET_ENV ( jvm, env ); MOAILuaState state ( L ); cc8* board = lua_tostring ( state, 1 ); jlong score = lua_tonumber ( state, 2 ); MOAIJString jboard = JNI_GET_JSTRING ( board ); jclass playserv = env->FindClass ( "com/moaisdk/googleplayservices/MoaiGooglePlayServices" ); if ( playserv == NULL ) { ZLLog::LogF ( 1, ZLLog::CONSOLE, "MOAIGooglePlayServicesAndroid: Unable to find java class %s", "com/moaisdk/googleplayservices/MoaiGooglePlayServices" ); } else { jmethodID submitScore = env->GetStaticMethodID ( playserv, "submitScore", "(Ljava/lang/String;J)V" ); if ( submitScore == NULL ) { ZLLog::LogF ( 1, ZLLog::CONSOLE, "MOAIGooglePlayServicesAndroid: Unable to find static java method %s", "submitScore" ); } else { env->CallStaticVoidMethod ( playserv, submitScore, ( jstring )jboard, score ); } } return 0; }
/** @name showLeaderboard @text Shows the desired leaderboard @in string leaderboardID @out nil */ int MOAIGooglePlayServicesAndroid::_showLeaderboard ( lua_State* L ) { JNI_GET_ENV ( jvm, env ); MOAILuaState state ( L ); cc8* board = lua_tostring ( state, 1 ); JNI_GET_JSTRING ( board, jboard ); jclass playserv = env->FindClass ( "com/ziplinegames/moai/MoaiGooglePlayServices" ); if ( playserv == NULL ) { USLog::Print ( "MOAIGooglePlayServicesAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiGooglePlayServices" ); } else { jmethodID showLeaderboard = env->GetStaticMethodID ( playserv, "showLeaderboard", "(Ljava/lang/String;)V" ); if ( showLeaderboard == NULL ) { USLog::Print ( "MOAIGooglePlayServicesAndroid: Unable to find static java method %s", "showLeaderboard" ); } else { env->CallStaticVoidMethod ( playserv, showLeaderboard, jboard ); } } return 0; }
/** @name videoReadyForZone @text Check the readiness of a video ad for a given zone. @in string zone The zone from which to check for a video ad. @out boolean isReady True, if a video ad is ready to play. */ int MOAIAdColonyAndroid::_videoReadyForZone ( lua_State *L ) { MOAILuaState state ( L ); cc8* zone = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( zone, jzone ); jclass adcolony = env->FindClass ( "com/ziplinegames/moai/MoaiAdColony" ); if ( adcolony == NULL ) { ZLLog::Print ( "MOAIAdColonyAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiAdColony" ); } else { jmethodID isVideoReady = env->GetStaticMethodID ( adcolony, "isVideoReady", "(Ljava/lang/String;)Z" ); if ( isVideoReady == NULL ) { ZLLog::Print ( "MOAIAdColonyAndroid: Unable to find static java method %s", "isVideoReady" ); } else { jboolean jready = ( jboolean )env->CallStaticBooleanMethod ( adcolony, isVideoReady, jzone ); lua_pushboolean ( state, jready ); return 1; } } lua_pushboolean ( state, false ); return 1; }
/** @name openURL @text Open the given URL in the device browser. @in string url The URL to open. @out nil */ int MOAIAppAndroid::_openURL ( lua_State* L ) { MOAILuaState state ( L ); cc8* url = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( url, jurl ); jclass moai = env->FindClass ( "com/ziplinegames/moai/Moai" ); if ( moai == NULL ) { USLog::Print ( "MOAIAppAndroid: Unable to find java class %s", "com/ziplinegames/moai/Moai" ); } else { jmethodID openURL = env->GetStaticMethodID ( moai, "openURL", "(Ljava/lang/String;)V" ); if ( openURL == NULL ) { USLog::Print ( "MOAIAppAndroid: Unable to find static java method %s", "openURL" ); } else { env->CallStaticVoidMethod ( moai, openURL, jurl ); } } return 0; }
/** @name playVideo @text Play an AdColony video ad. @in string zone The zone from which to play a video ad. @opt boolean prompt Determines whether the user is asked whether they want to play a video ad or not. Default is true. @opt boolean confirm Determines whether the user is presented with a confirmation dialog after video ad playback completes. Default is true. @out nil */ int MOAIAdColonyAndroid::_playVideo ( lua_State* L ) { MOAILuaState state ( L ); cc8* zone = lua_tostring ( state, 1 ); bool prompt = state.GetValue < bool >( 2, true ); bool confirmation = state.GetValue < bool >( 3, true ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( zone, jzone ); jclass adcolony = env->FindClass ( "com/ziplinegames/moai/MoaiAdColony" ); if ( adcolony == NULL ) { ZLLog::Print ( "MOAIAdColonyAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiAdColony" ); } else { jmethodID playVideo = env->GetStaticMethodID ( adcolony, "playVideo", "(Ljava/lang/String;ZZ)V" ); if ( playVideo == NULL ) { ZLLog::Print ( "MOAIAdColonyAndroid: Unable to find static java method %s", "playVideo" ); } else { env->CallStaticVoidMethod ( adcolony, playVideo, jzone, prompt, confirmation ); } } return 0; }
/** @name setUser @text Sets an identifier for a user @in string identifier A string identifying the user. @out nil */ int MOAICrittercismAndroid::_setUser ( lua_State* L ) { MOAILuaState state ( L ); cc8* ident = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( ident, jident ); jclass crittercism = env->FindClass ( "com/ziplinegames/moai/MoaiCrittercism" ); if ( crittercism == NULL ) { USLog::Print ( "MOAICrittercismAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiCrittercism" ); } else { jmethodID setUser = env->GetStaticMethodID ( crittercism, "setUser", "(Ljava/lang/String;)V" ); if ( setUser == NULL ) { USLog::Print ( "MOAICrittercismAndroid: Unable to find static java method %s", "setUser" ); } else { env->CallStaticVoidMethod ( crittercism, setUser, jident ); } } return 0; }
/** @name leaveBreadcrumb @text Leave a breadcrumb (log statement) to trace execution. @in string breadcrumb A string describing the code location. @out nil */ int MOAICrittercismAndroid::_leaveBreadcrumb ( lua_State* L ) { MOAILuaState state ( L ); cc8* breadcrumb = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( breadcrumb, jbreadcrumb ); jclass crittercism = env->FindClass ( "com/ziplinegames/moai/MoaiCrittercism" ); if ( crittercism == NULL ) { USLog::Print ( "MOAICrittercismAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiCrittercism" ); } else { jmethodID leaveBreadcrumb = env->GetStaticMethodID ( crittercism, "leaveBreadcrumb", "(Ljava/lang/String;)V" ); if ( leaveBreadcrumb == NULL ) { USLog::Print ( "MOAICrittercismAndroid: Unable to find static java method %s", "leaveBreadcrumb" ); } else { env->CallStaticVoidMethod ( crittercism, leaveBreadcrumb, jbreadcrumb ); } } return 0; }
/** @name loadInterstitial @text Request that an interstitial ad be cached for later display. @opt string locationId Optional location ID. @out nil */ int MOAIChartBoostAndroid::_loadInterstitial ( lua_State* L ) { MOAILuaState state ( L ); cc8* location = NULL; //lua_tostring ( state, 1 ); At the moment, the ChartBoost caching API for Android does not support locations. JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( location, jlocation ); jclass chartboost = env->FindClass ( "com/ziplinegames/moai/MoaiChartBoost" ); if ( chartboost == NULL ) { ZLLog::Print ( "MOAIChartBoostAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiChartBoost" ); } else { jmethodID loadInterstitial = env->GetStaticMethodID ( chartboost, "loadInterstitial", "(Ljava/lang/String;)V" ); if ( loadInterstitial == NULL ) { ZLLog::Print ( "MOAIChartBoostAndroid: Unable to find static java method %s", "loadInterstitial" ); } else { env->CallStaticVoidMethod ( chartboost, loadInterstitial, jlocation ); } } return 0; }
/** @lua init @text Initialize the video player with the URL of a video to play. @in string url The URL of the video to play. @out nil */ int MOAIMoviePlayerAndroid::_init ( lua_State* L ) { MOAILuaState state ( L ); cc8* url = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( url, jurl ); jclass movie = env->FindClass ( "com/ziplinegames/moai/MoaiMoviePlayer" ); if ( movie == NULL ) { ZLLog::LogF ( ZLLog::CONSOLE, "MOAIMoviePlayerAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiMoviePlayer" ); } else { jmethodID init = env->GetStaticMethodID ( movie, "init", "(Ljava/lang/String;)V" ); if ( init == NULL ) { ZLLog::LogF ( ZLLog::CONSOLE, "MOAIMoviePlayerAndroid: Unable to find static java method %s", "init" ); } else { env->CallStaticVoidMethod ( movie, init, jurl ); } } return 0; }
/** @name graphRequest @text Performs a requset on the Facebook Graph API @in string path @out string token */ int MOAIFacebookAndroid::_graphRequest ( lua_State* L ) { MOAILuaState state ( L ); cc8* path = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( path, jpath ) jclass facebook = env->FindClass ( "com/ziplinegames/moai/MoaiFacebook" ); if ( facebook == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiFacebook" ); } else { jmethodID graphRequest = env->GetStaticMethodID ( facebook, "graphRequest", "(Ljava/lang/String;)Ljava/lang/String;" ); if ( graphRequest == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find static java method %s", "graphRequest" ); } else { jstring jresult = ( jstring )env->CallStaticObjectMethod ( facebook, graphRequest, jpath ); JNI_GET_CSTRING ( jresult, result ); lua_pushstring ( state, result ); JNI_RELEASE_CSTRING ( jresult, result ); return 1; } } lua_pushnil ( state ); return 1; }
/** @name postToFeed @text Post a message to the logged in users' news feed. @in string link The URL that the post links to. See Facebook documentation. @in string picture The URL of an image to include in the post. See Facebook documentation. @in string name The name of the link. See Facebook documentation. @in string caption The caption of the link. See Facebook documentation. @in string description The description of the link. See Facebook documentation. @in string message The message for the post. See Facebook documentation. @out nil */ int MOAIFacebookAndroid::_postToFeed ( lua_State* L ) { MOAILuaState state ( L ); cc8* link = lua_tostring ( state, 1 ); cc8* picture = lua_tostring ( state, 2 ); cc8* name = lua_tostring ( state, 3 ); cc8* caption = lua_tostring ( state, 4 ); cc8* description = lua_tostring ( state, 5 ); cc8* message = lua_tostring ( state, 6 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( link, jlink ); JNI_GET_JSTRING ( picture, jpicture ); JNI_GET_JSTRING ( name, jname ); JNI_GET_JSTRING ( caption, jcaption ); JNI_GET_JSTRING ( description, jdescription ); JNI_GET_JSTRING ( message, jmessage ); jclass facebook = env->FindClass ( "com/ziplinegames/moai/MoaiFacebook" ); if ( facebook == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiFacebook" ); } else { jmethodID postToFeed = env->GetStaticMethodID ( facebook, "postToFeed", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V" ); if ( postToFeed == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find static java method %s", "postToFeed" ); } else { env->CallStaticVoidMethod ( facebook, postToFeed, jlink, jpicture, jname, jcaption, jdescription, jmessage ); } } return 0; }
/** @name init @text Initialize AdColony. @in string appId Available in AdColony dashboard settings. @in table zones A list of zones to configure. Available in AdColony dashboard settings. @out nil */ int MOAIAdColonyAndroid::_init ( lua_State* L ) { MOAILuaState state ( L ); cc8* identifier = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( identifier, jidentifier ); jobjectArray jzones = NULL; if ( state.IsType ( 2, LUA_TTABLE )) { int numEntries = 0; for ( int key = 1; ; ++key ) { state.GetField ( 2, key ); cc8* value = _luaParseTable ( state, -1 ); lua_pop ( state, 1 ); if ( !value ) { numEntries = key - 1; break; } } jzones = env->NewObjectArray ( numEntries, env->FindClass( "java/lang/String" ), 0 ); for ( int key = 1; ; ++key ) { state.GetField ( 2, key ); cc8* value = _luaParseTable ( state, -1 ); lua_pop ( state, 1 ); if ( value ) { JNI_GET_JSTRING ( value, jvalue ); env->SetObjectArrayElement ( jzones, key - 1, jvalue ); } else { break; } } } if ( jzones == NULL ) { jzones = env->NewObjectArray ( 0, env->FindClass( "java/lang/String" ), 0 ); } jclass adcolony = env->FindClass ( "com/ziplinegames/moai/MoaiAdColony" ); if ( adcolony == NULL ) { ZLLog::Print ( "MOAIAdColonyAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiAdColony" ); } else { jmethodID init = env->GetStaticMethodID ( adcolony, "init", "(Ljava/lang/String;[Ljava/lang/String;)V" ); if ( init == NULL ) { ZLLog::Print ( "MOAIAdColonyAndroid: Unable to find static java method %s", "init" ); } else { env->CallStaticVoidMethod ( adcolony, init, jidentifier, jzones ); } } return 0; }
/** @name login @text Prompt the user to login to Facebook. @opt table permissions Optional set of required permissions. See Facebook documentation for a full list. Default is nil. @out nil */ int MOAIFacebookAndroid::_login ( lua_State *L ) { MOAILuaState state ( L ); JNI_GET_ENV ( jvm, env ); jobjectArray jpermissions = NULL; if ( state.IsType ( 1, LUA_TTABLE )) { int numEntries = 0; for ( int key = 1; ; ++key ) { state.GetField ( 1, key ); cc8* value = _luaParseTable ( state, -1 ); lua_pop ( state, 1 ); if ( !value ) { numEntries = key - 1; break; } } jpermissions = env->NewObjectArray ( numEntries, env->FindClass( "java/lang/String" ), 0 ); for ( int key = 1; ; ++key ) { state.GetField ( 1, key ); cc8* value = _luaParseTable ( state, -1 ); lua_pop ( state, 1 ); if ( value ) { JNI_GET_JSTRING ( value, jvalue ); env->SetObjectArrayElement ( jpermissions, key - 1, jvalue ); } else { break; } } } if ( jpermissions == NULL ) { jpermissions = env->NewObjectArray ( 0, env->FindClass( "java/lang/String" ), 0 ); } jclass facebook = env->FindClass ( "com/ziplinegames/moai/MoaiFacebook" ); if ( facebook == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiFacebook" ); } else { jmethodID login = env->GetStaticMethodID ( facebook, "login", "([Ljava/lang/String;)V" ); if ( login == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find static java method %s", "login" ); } else { env->CallStaticVoidMethod ( facebook, login, jpermissions ); } } return 0; }