Vibration fix
This commit is contained in:
@@ -959,24 +959,46 @@ 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)
|
|
||||||
|
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 (counter % 2 != 0)
|
||||||
{
|
{
|
||||||
Vibrator vibrator = (Vibrator) Miscellaneous.getAnyContext().getSystemService(Context.VIBRATOR_SERVICE);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||||
vibrator.vibrate(VibrationEffect.createOneShot(Long.parseLong(vibrate), VibrationEffect.DEFAULT_AMPLITUDE));
|
{
|
||||||
|
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
|
else
|
||||||
vibrator.vibrate(Long.parseLong(vibrate));
|
vibrator.vibrate(Long.parseLong(vibrateDuration));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.sleep(Long.parseLong(vibrate));
|
Thread.sleep(Long.parseLong(vibrateDuration));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -987,6 +1009,9 @@ public class Actions
|
|||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
Miscellaneous.logEvent("w", "Vibrate", "Device doesn't have vibrator.", 3);
|
||||||
|
}
|
||||||
|
|
||||||
public void useDownloadedWebpage(String result)
|
public void useDownloadedWebpage(String result)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user