mirror of
https://github.com/love2d/love-android.git
synced 2026-08-19 12:14:49 +02:00
implemented love.system.vibrate(seconds)
This commit is contained in:
@@ -91,6 +91,17 @@ bool openURL(const std::string &url)
|
||||
return true;
|
||||
}
|
||||
|
||||
void vibrate (double seconds)
|
||||
{
|
||||
JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
|
||||
jclass activity = env->FindClass("org/love2d/android/GameActivity");
|
||||
|
||||
jmethodID vibrate_method = env->GetStaticMethodID(activity, "vibrate", "(D)V");
|
||||
env->CallStaticVoidMethod(activity, vibrate_method, seconds);
|
||||
|
||||
env->DeleteLocalRef (activity);
|
||||
}
|
||||
|
||||
} // android
|
||||
} // love
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ const char* getSelectedGameFile();
|
||||
|
||||
bool openURL (const std::string &url);
|
||||
|
||||
void vibrate (double seconds);
|
||||
|
||||
} // android
|
||||
} // love
|
||||
|
||||
|
||||
@@ -118,6 +118,12 @@ bool System::openURL(const std::string &url) const
|
||||
#endif
|
||||
}
|
||||
|
||||
void System::vibrate(double seconds) const {
|
||||
#ifdef LOVE_ANDROID
|
||||
love::android::vibrate (seconds);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool System::getConstant(const char *in, System::PowerState &out)
|
||||
{
|
||||
return powerStates.find(in, out);
|
||||
|
||||
@@ -95,6 +95,14 @@ public:
|
||||
**/
|
||||
virtual bool openURL(const std::string &url) const;
|
||||
|
||||
/**
|
||||
* Vibrates for the specified amount of seconds.
|
||||
*
|
||||
* @param number of seconds to vibrate.
|
||||
*
|
||||
*/
|
||||
virtual void vibrate(double seconds) const;
|
||||
|
||||
static bool getConstant(const char *in, PowerState &out);
|
||||
static bool getConstant(PowerState in, const char *&out);
|
||||
|
||||
|
||||
@@ -86,6 +86,13 @@ int w_openURL(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_vibrate(lua_State *L)
|
||||
{
|
||||
double seconds = static_cast<double>(luaL_checknumber(L, 1));
|
||||
instance->vibrate(seconds);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getOS", w_getOS },
|
||||
@@ -94,6 +101,7 @@ static const luaL_Reg functions[] =
|
||||
{ "getClipboardText", w_getClipboardText },
|
||||
{ "getPowerInfo", w_getPowerInfo },
|
||||
{ "openURL", w_openURL },
|
||||
{ "vibrate", w_vibrate },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ int w_setClipboardText(lua_State *L);
|
||||
int w_getClipboardText(lua_State *L);
|
||||
int w_getPowerInfo(lua_State *L);
|
||||
int w_openURL(lua_State *L);
|
||||
int w_vibrate(lua_State *L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_system(lua_State *L);
|
||||
|
||||
} // system
|
||||
|
||||
Reference in New Issue
Block a user