package com.johan.Vibrate;
import android.content.Context;
import android.os.Vibrator;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.BA;
@ShortName("B4Avibrate")
public class Vibrate
{
/**
*Vibrate with a given pattern.
*Pass in an array of Longs that are the durations for which to turn on or off the vibrator in milliseconds.
*The first value indicates the number of milliseconds to wait before turning the vibrator on. The next
*value indicates the number of milliseconds for which to keep the vibrator on before turning it off.
*Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.
*Parameters:
*pattern ---> an array of longs of times for which to turn the vibrator on or off.
*repeat ---> the index into pattern at which to repeat, or -1 if you don't want to repeat.
*
*You need to add the following to the manifest file of the B4A project:
*AddPermission("android.permission.VIBRATE")
*Example:<code>
*Dim mv As Vibrate
*Dim pattern() As Long
*pattern = Array As Long(0, 100, 1000, 300, 1000, 100, 1000, 200, 1000)
*Dim repeat as Int = 0
*mv.vibratePattern(pattern, repeat)</code>
*
*/
public void vibratePattern(final BA ba,long[] pattern, int repeat) {
Vibrator v = (Vibrator) ba.context.getSystemService(Context.VIBRATOR_SERVICE);
if (v.hasVibrator()) {
v.vibrate(pattern, repeat);
}
}
/**
*Cancel vibration (in case of method vibratePattern being active)
*You need to add the following to the manifest file of the B4A project:
*AddPermission("android.permission.VIBRATE")
*Example:<code>
*Dim mv As Vibrate
*mv.vibrateCancel</code>
*
*/
public void vibrateCancel(final BA ba) {
Vibrator v = (Vibrator) ba.context.getSystemService(Context.VIBRATOR_SERVICE);
if (v.hasVibrator()) {
v.cancel();
}
}
/**
*Vibrate continuously for the specified number of milliseconds
*You need to add the following to the manifest file of the B4A project:
*AddPermission("android.permission.VIBRATE")
*Example:<code>
*Dim mv As Vibrate
*Dim duration as Long = 2000
*mv.vibrateOnce(duration)</code>
*
*/
public void vibrateOnce(final BA ba, long duration) {
Vibrator v = (Vibrator) ba.context.getSystemService(Context.VIBRATOR_SERVICE);
if (v.hasVibrator()) {
v.vibrate(duration);
}
}
}