Vibration fix

This commit is contained in:
2025-11-23 18:47:38 +01:00
parent 35e2a1158d
commit 4282c53372

View File

@@ -959,33 +959,58 @@ public class Actions
public static void vibrate(boolean parameter1, String parameter2) public static void vibrate(boolean parameter1, String parameter2)
{ {
String vibrateDurations[] = parameter2.split(Action.vibrateSeparator); String[] vibrateDurations = parameter2.split(Action.vibrateSeparator);
int counter = 1; int counter = 1;
for (String vibrate : vibrateDurations)
{
if (counter % 2 != 0)
{
Vibrator vibrator = (Vibrator) Miscellaneous.getAnyContext().getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
vibrator.vibrate(VibrationEffect.createOneShot(Long.parseLong(vibrate), VibrationEffect.DEFAULT_AMPLITUDE));
else
vibrator.vibrate(Long.parseLong(vibrate));
}
else
{
try
{
Thread.sleep(Long.parseLong(vibrate));
}
catch (Exception e)
{
Miscellaneous.logEvent("e", "VibrateSleep", Log.getStackTraceString(e), 5);
}
}
counter++; Vibrator vibrator = (Vibrator) Miscellaneous.getAnyContext().getSystemService(Context.VIBRATOR_SERVICE);
if(ActivityPermissions.havePermission(Manifest.permission.VIBRATE, Miscellaneous.getAnyContext()))
Miscellaneous.logEvent("i", "Vibrate", "Have permission.", 3);
if(vibrator != null && vibrator.hasVibrator())
{
for (String vibrateDuration : vibrateDurations)
{
vibrator.cancel();
if (counter % 2 != 0)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
VibrationEffect ve = VibrationEffect.createOneShot(Long.parseLong(vibrateDuration), VibrationEffect.DEFAULT_AMPLITUDE);
vibrator.vibrate(ve);
// For newer versions it seems we have to wait for the vibration to complete.
try
{
Thread.sleep(Long.parseLong(vibrateDuration));
}
catch (Exception e)
{
Miscellaneous.logEvent("e", "VibrateSleep", Log.getStackTraceString(e), 5);
}
}
else
vibrator.vibrate(Long.parseLong(vibrateDuration));
}
else
{
try
{
Thread.sleep(Long.parseLong(vibrateDuration));
}
catch (Exception e)
{
Miscellaneous.logEvent("e", "VibrateSleep", Log.getStackTraceString(e), 5);
}
}
counter++;
}
} }
else
Miscellaneous.logEvent("w", "Vibrate", "Device doesn't have vibrator.", 3);
} }
public void useDownloadedWebpage(String result) public void useDownloadedWebpage(String result)