summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/java/src/org/godotengine/godot/Godot.java22
-rw-r--r--platform/android/java_godot_wrapper.cpp8
-rw-r--r--platform/android/java_godot_wrapper.h2
-rw-r--r--platform/android/os_android.cpp4
-rw-r--r--platform/android/os_android.h1
5 files changed, 37 insertions, 0 deletions
diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java
index 6e1841fa8b..f493b5f33f 100644
--- a/platform/android/java/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/src/org/godotengine/godot/Godot.java
@@ -56,6 +56,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Messenger;
+import android.os.Vibrator;
import android.provider.Settings.Secure;
import android.support.v4.content.ContextCompat;
import android.view.Display;
@@ -98,6 +99,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
static final int MAX_SINGLETONS = 64;
static final int REQUEST_RECORD_AUDIO_PERMISSION = 1;
static final int REQUEST_CAMERA_PERMISSION = 2;
+ static final int REQUEST_VIBRATE_PERMISSION = 3;
private IStub mDownloaderClientStub;
private IDownloaderService mRemoteService;
private TextView mStatusText;
@@ -324,6 +326,15 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
});
}
+ public void vibrate(int p_duration_ms) {
+ if (requestPermission("VIBRATE")) {
+ Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
+ if (v != null) {
+ v.vibrate(p_duration_ms);
+ }
+ }
+ }
+
public void restart() {
// HACK:
//
@@ -625,6 +636,10 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
GodotLib.ondestroy(this);
super.onDestroy();
+
+ // TODO: This is a temp solution. The proper fix will involve tracking down and properly shutting down each
+ // native Godot components that is started in Godot#onVideoInit.
+ forceQuit();
}
@Override
@@ -985,6 +1000,13 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
return false;
}
}
+
+ if (p_name.equals("VIBRATE")) {
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED) {
+ requestPermissions(new String[] { Manifest.permission.VIBRATE }, REQUEST_VIBRATE_PERMISSION);
+ return false;
+ }
+ }
return true;
}
diff --git a/platform/android/java_godot_wrapper.cpp b/platform/android/java_godot_wrapper.cpp
index 339b14974c..c7dc1d124c 100644
--- a/platform/android/java_godot_wrapper.cpp
+++ b/platform/android/java_godot_wrapper.cpp
@@ -62,6 +62,7 @@ GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_godot_instance) {
_init_input_devices = p_env->GetMethodID(cls, "initInputDevices", "()V");
_get_surface = p_env->GetMethodID(cls, "getSurface", "()Landroid/view/Surface;");
_is_activity_resumed = p_env->GetMethodID(cls, "isActivityResumed", "()Z");
+ _vibrate = p_env->GetMethodID(cls, "vibrate", "(I)V");
}
GodotJavaWrapper::~GodotJavaWrapper() {
@@ -211,3 +212,10 @@ bool GodotJavaWrapper::is_activity_resumed() {
return false;
}
}
+
+void GodotJavaWrapper::vibrate(int p_duration_ms) {
+ if (_vibrate) {
+ JNIEnv *env = ThreadAndroid::get_env();
+ env->CallVoidMethod(godot_instance, _vibrate, p_duration_ms);
+ }
+}
diff --git a/platform/android/java_godot_wrapper.h b/platform/android/java_godot_wrapper.h
index 82c2a5d122..3e0e950180 100644
--- a/platform/android/java_godot_wrapper.h
+++ b/platform/android/java_godot_wrapper.h
@@ -57,6 +57,7 @@ private:
jmethodID _init_input_devices = 0;
jmethodID _get_surface = 0;
jmethodID _is_activity_resumed = 0;
+ jmethodID _vibrate = 0;
public:
GodotJavaWrapper(JNIEnv *p_env, jobject p_godot_instance);
@@ -82,6 +83,7 @@ public:
void init_input_devices();
jobject get_surface();
bool is_activity_resumed();
+ void vibrate(int p_duration_ms);
};
#endif /* !JAVA_GODOT_WRAPPER_H */
diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp
index 701a351203..9b2df50f6c 100644
--- a/platform/android/os_android.cpp
+++ b/platform/android/os_android.cpp
@@ -700,6 +700,10 @@ String OS_Android::get_joy_guid(int p_device) const {
return input->get_joy_guid_remapped(p_device);
}
+void OS_Android::vibrate_handheld(int p_duration_ms) {
+ godot_java->vibrate(p_duration_ms);
+}
+
bool OS_Android::_check_internal_feature_support(const String &p_feature) {
if (p_feature == "mobile") {
//TODO support etc2 only if GLES3 driver is selected
diff --git a/platform/android/os_android.h b/platform/android/os_android.h
index e74d4cfd43..a17941f7c0 100644
--- a/platform/android/os_android.h
+++ b/platform/android/os_android.h
@@ -198,6 +198,7 @@ public:
virtual bool is_joy_known(int p_device);
virtual String get_joy_guid(int p_device) const;
void joy_connection_changed(int p_device, bool p_connected, String p_name);
+ void vibrate_handheld(int p_duration_ms);
virtual bool _check_internal_feature_support(const String &p_feature);
OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_godot_io_java, bool p_use_apk_expansion);