diff options
Diffstat (limited to 'platform/android')
-rw-r--r-- | platform/android/java/lib/src/org/godotengine/godot/Godot.kt | 21 | ||||
-rw-r--r-- | platform/android/java_godot_wrapper.cpp | 13 | ||||
-rw-r--r-- | platform/android/java_godot_wrapper.h | 2 | ||||
-rw-r--r-- | platform/android/os_android.cpp | 4 | ||||
-rw-r--r-- | platform/android/os_android.h | 2 |
5 files changed, 29 insertions, 13 deletions
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt index ce53aeebcb..fbdf07e6c2 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt @@ -894,16 +894,25 @@ class Godot(private val context: Context) : SensorEventListener { */ @SuppressLint("MissingPermission") @Keep - private fun vibrate(durationMs: Int) { + private fun vibrate(durationMs: Int, amplitude: Int) { if (durationMs > 0 && requestPermission("VIBRATE")) { val vibratorService = getActivity()?.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator? ?: return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - vibratorService.vibrate( - VibrationEffect.createOneShot( - durationMs.toLong(), - VibrationEffect.DEFAULT_AMPLITUDE + if (amplitude <= -1) { + vibratorService.vibrate( + VibrationEffect.createOneShot( + durationMs.toLong(), + VibrationEffect.DEFAULT_AMPLITUDE + ) ) - ) + } else { + vibratorService.vibrate( + VibrationEffect.createOneShot( + durationMs.toLong(), + amplitude + ) + ) + } } else { // deprecated in API 26 vibratorService.vibrate(durationMs.toLong()) diff --git a/platform/android/java_godot_wrapper.cpp b/platform/android/java_godot_wrapper.cpp index 61be6fc5db..0e766e7d56 100644 --- a/platform/android/java_godot_wrapper.cpp +++ b/platform/android/java_godot_wrapper.cpp @@ -72,7 +72,7 @@ GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_ _get_granted_permissions = p_env->GetMethodID(godot_class, "getGrantedPermissions", "()[Ljava/lang/String;"); _get_ca_certificates = p_env->GetMethodID(godot_class, "getCACertificates", "()Ljava/lang/String;"); _init_input_devices = p_env->GetMethodID(godot_class, "initInputDevices", "()V"); - _vibrate = p_env->GetMethodID(godot_class, "vibrate", "(I)V"); + _vibrate = p_env->GetMethodID(godot_class, "vibrate", "(II)V"); _get_input_fallback_mapping = p_env->GetMethodID(godot_class, "getInputFallbackMapping", "()Ljava/lang/String;"); _on_godot_setup_completed = p_env->GetMethodID(godot_class, "onGodotSetupCompleted", "()V"); _on_godot_main_loop_started = p_env->GetMethodID(godot_class, "onGodotMainLoopStarted", "()V"); @@ -331,11 +331,18 @@ void GodotJavaWrapper::init_input_devices() { } } -void GodotJavaWrapper::vibrate(int p_duration_ms) { +void GodotJavaWrapper::vibrate(int p_duration_ms, float p_amplitude) { if (_vibrate) { JNIEnv *env = get_jni_env(); ERR_FAIL_NULL(env); - env->CallVoidMethod(godot_instance, _vibrate, p_duration_ms); + + int j_amplitude = -1.0; + + if (p_amplitude != -1.0) { + j_amplitude = CLAMP(int(p_amplitude * 255), 1, 255); + } + + env->CallVoidMethod(godot_instance, _vibrate, p_duration_ms, j_amplitude); } } diff --git a/platform/android/java_godot_wrapper.h b/platform/android/java_godot_wrapper.h index 93998021a9..e86391d4e3 100644 --- a/platform/android/java_godot_wrapper.h +++ b/platform/android/java_godot_wrapper.h @@ -102,7 +102,7 @@ public: Vector<String> get_granted_permissions() const; String get_ca_certificates() const; void init_input_devices(); - void vibrate(int p_duration_ms); + void vibrate(int p_duration_ms, float p_amplitude = -1.0); String get_input_fallback_mapping(); int create_new_godot_instance(const List<String> &args); void begin_benchmark_measure(const String &p_context, const String &p_label); diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 463a307854..c60125c34e 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -746,8 +746,8 @@ ANativeWindow *OS_Android::get_native_window() const { #endif } -void OS_Android::vibrate_handheld(int p_duration_ms) { - godot_java->vibrate(p_duration_ms); +void OS_Android::vibrate_handheld(int p_duration_ms, float p_amplitude) { + godot_java->vibrate(p_duration_ms, p_amplitude); } String OS_Android::get_config_path() const { diff --git a/platform/android/os_android.h b/platform/android/os_android.h index 7bdbeef77a..b150ef4f61 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -153,7 +153,7 @@ public: virtual Error move_to_trash(const String &p_path) override; - void vibrate_handheld(int p_duration_ms) override; + void vibrate_handheld(int p_duration_ms, float p_amplitude = -1.0) override; virtual String get_config_path() const override; |