mirror of
https://github.com/love2d/love-android.git
synced 2026-08-12 08:31:04 +02:00
implemented love.system.vibrate(seconds)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
android:versionName="0.9.1a"
|
||||
android:installLocation="auto" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<!-- Allow writing to external storage -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.os.ResultReceiver;
|
||||
import android.os.Vibrator;
|
||||
import android.util.Log;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.widget.Toast;
|
||||
@@ -32,12 +33,14 @@ public class GameActivity extends SDLActivity {
|
||||
private static DisplayMetrics metrics = new DisplayMetrics();
|
||||
private static String gamePath = "";
|
||||
private static Context context;
|
||||
|
||||
private static Vibrator vibrator;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Log.d("GameActivity", "started");
|
||||
|
||||
|
||||
context = this.getApplicationContext();
|
||||
vibrator = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
|
||||
Uri game = this.getIntent().getData();
|
||||
if (game != null) {
|
||||
@@ -62,6 +65,11 @@ public class GameActivity extends SDLActivity {
|
||||
return metrics;
|
||||
}
|
||||
|
||||
public static void vibrate (double seconds) {
|
||||
Log.d ("GameActivity", "vibrating for " + seconds + " seconds");
|
||||
vibrator.vibrate((long) (seconds * 1000.));
|
||||
}milli
|
||||
|
||||
public static void openURL (String url) {
|
||||
Log.d ("GameActivity", "opening url = " + url);
|
||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
|
||||
Reference in New Issue
Block a user