From 99ff0afeab720a21a70ef9750b8461ced9009ece Mon Sep 17 00:00:00 2001 From: player-03 Date: Sun, 7 Jul 2024 13:20:06 -0400 Subject: [PATCH] Reduce duplicate logic. I'd rather duplicate the SDK version check, not the math. --- .../main/java/org/haxe/lime/GameActivity.java | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/templates/android/template/app/src/main/java/org/haxe/lime/GameActivity.java b/templates/android/template/app/src/main/java/org/haxe/lime/GameActivity.java index 02dabb4f6..b5b0c78f8 100644 --- a/templates/android/template/app/src/main/java/org/haxe/lime/GameActivity.java +++ b/templates/android/template/app/src/main/java/org/haxe/lime/GameActivity.java @@ -386,46 +386,36 @@ public class GameActivity extends SDLActivity { } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (period == 0) { - if (period == 0) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { vibrator.vibrate (VibrationEffect.createOneShot (duration, VibrationEffect.DEFAULT_AMPLITUDE)); } else { - int periodMS = Math.max (1, (int)Math.ceil (period / 2.0)); - int count = Math.max (1, (int)Math.ceil ((duration / (double) period) * 2)); - long[] pattern = new long[count]; - - for (int i = 0; i < count; i++) { - - pattern[i] = periodMS; - - } - - vibrator.vibrate (VibrationEffect.createWaveform (pattern, -1)); + vibrator.vibrate (duration); } } else { - if (period == 0) { + int periodMS = Math.max (1, (int)Math.ceil (period / 2.0)); + int count = Math.max (1, (int)Math.ceil ((duration / (double) period) * 2)); + long[] pattern = new long[count]; - vibrator.vibrate (duration); + for (int i = 0; i < count; i++) { + + pattern[i] = periodMS; + + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + + vibrator.vibrate (VibrationEffect.createWaveform (pattern, -1)); } else { - int periodMS = (int)Math.ceil (period / 2); - int count = (int)Math.ceil ((duration / period) * 2); - long[] pattern = new long[count]; - - for (int i = 0; i < count; i++) { - - pattern[i] = periodMS; - - } - vibrator.vibrate (pattern, -1); }