Skip to content

Commit

Permalink
Added MOAIApp.vibrate(ms) for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
mandrav committed Jan 31, 2013
1 parent 58a2101 commit a86fc87
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ant/host-source/source/project/AndroidManifest.xml
Expand Up @@ -48,6 +48,7 @@
<!-- Moai -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />

<!-- EXTERNAL PERMISSIONS: Placeholder (DO NOT MOVE OR REMOVE) -->

Expand All @@ -62,4 +63,4 @@

<uses-feature android:name="android.hardware.screen.landscape" android:required="true" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="true" />
</manifest>
</manifest>
8 changes: 8 additions & 0 deletions ant/host-source/source/project/src/moai/Moai.java
Expand Up @@ -15,6 +15,7 @@
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Vibrator;
import android.provider.Settings.Secure;
import android.util.DisplayMetrics;

Expand Down Expand Up @@ -632,6 +633,13 @@ public static void share ( String prompt, String subject, String text ) {
sActivity.startActivity ( Intent.createChooser ( intent, prompt ));
}

//----------------------------------------------------------------//
public static void vibrate ( int milliseconds ) {

Vibrator v = (Vibrator) sActivity.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(milliseconds);
}

//----------------------------------------------------------------//
public static void showDialog ( String title, String message, String positiveButton, String neutralButton, String negativeButton, boolean cancelable ) {

Expand Down
37 changes: 36 additions & 1 deletion src/moaiext-android/MOAIAppAndroid.cpp
Expand Up @@ -176,6 +176,40 @@ int MOAIAppAndroid::_share ( lua_State* L ) {
return 0;
}

//----------------------------------------------------------------//
/** @name vibrate
@text Vibrate for the given amount of milliseconds.
@in number milliseconds The time-span to vibrate for.
@out nil
*/
int MOAIAppAndroid::_vibrate ( lua_State* L ) {

MOAILuaState state ( L );

int ms = lua_tonumber ( state, 1 );

JNI_GET_ENV ( jvm, env );

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 vibrate = env->GetStaticMethodID ( moai, "vibrate", "(I)V" );
if ( vibrate == NULL ) {

USLog::Print ( "MOAIAppAndroid: Unable to find static java method %s", "vibrate" );
} else {

env->CallStaticVoidMethod ( moai, vibrate, ms );
}
}

return 0;
}

//================================================================//
// MOAIAppAndroid
//================================================================//
Expand Down Expand Up @@ -204,6 +238,7 @@ void MOAIAppAndroid::RegisterLuaClass ( MOAILuaState& state ) {
{ "openURL", _openURL },
{ "setListener", _setListener },
{ "share", _share },
{ "vibrate", _vibrate },
{ NULL, NULL }
};

Expand Down Expand Up @@ -276,4 +311,4 @@ extern "C" void Java_com_ziplinegames_moai_Moai_AKUAppDidStartSession ( JNIEnv*
extern "C" void Java_com_ziplinegames_moai_Moai_AKUAppWillEndSession ( JNIEnv* env, jclass obj ) {

MOAIAppAndroid::Get ().NotifyWillEndSession ();
}
}
3 changes: 2 additions & 1 deletion src/moaiext-android/MOAIAppAndroid.h
Expand Up @@ -36,6 +36,7 @@ class MOAIAppAndroid :
static int _openURL ( lua_State* L );
static int _setListener ( lua_State* L );
static int _share ( lua_State* L );
static int _vibrate ( lua_State* L );

public:

Expand All @@ -49,4 +50,4 @@ class MOAIAppAndroid :
void RegisterLuaClass ( MOAILuaState& state );
};

#endif
#endif

0 comments on commit a86fc87

Please sign in to comment.