Class VibrationApi
The Vibration API allows triggering device vibration patterns. It's commonly used for haptic feedback in response to user actions.
Note: Vibration may be disabled on some devices or blocked by user settings. There is no way to detect if vibration actually occurred.
Usage:
public class MyPage extends HtmlPage {
@Override
protected void createBody(Body body) {
Button btn = new Button("Vibrate");
btn.registerListener(this, MouseClickedEvent.class);
body.addElement(btn);
}
@Override
public void onEvent(MouseClickedEvent event) {
// Short vibration for button feedback
VibrationApi.vibrate(50);
}
}
- Author:
- Marvin P. Warble Jr.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcancel()Cancels any ongoing vibration using the current page context.static voidCancels any ongoing vibration.static voidChecks if the Vibration API is supported by the browser using the current page context.static voidcheckSupport(HtmlPage page) Checks if the Vibration API is supported by the browser.static voidDouble tap vibration pattern using the current page context.static voidDouble tap vibration pattern.static voiderror()Error notification vibration pattern using the current page context.static voidError notification vibration pattern.static voidsuccess()Success notification vibration pattern using the current page context.static voidSuccess notification vibration pattern.static voidtap()Short vibration for button/tap feedback using the current page context.static voidShort vibration for button/tap feedback.static voidvibrate(int duration) Vibrates the device for the specified duration using the current page context.static voidvibrate(int... pattern) Vibrates the device with a pattern using the current page context.static voidVibrates the device for the specified duration.static voidVibrates the device with a pattern.static voidwarning()Warning notification vibration pattern using the current page context.static voidWarning notification vibration pattern.
-
Constructor Details
-
VibrationApi
public VibrationApi()
-
-
Method Details
-
vibrate
public static void vibrate(int duration) Vibrates the device for the specified duration using the current page context.- Parameters:
duration- Duration in milliseconds.
-
vibrate
Vibrates the device for the specified duration.- Parameters:
page- The page context.duration- Duration in milliseconds.
-
vibrate
public static void vibrate(int... pattern) Vibrates the device with a pattern using the current page context.The pattern alternates between vibration and pause durations. For example, [100, 50, 100] vibrates for 100ms, pauses 50ms, vibrates 100ms.
- Parameters:
pattern- Array of durations in milliseconds.
-
vibrate
Vibrates the device with a pattern.The pattern alternates between vibration and pause durations. For example, [100, 50, 100] vibrates for 100ms, pauses 50ms, vibrates 100ms.
- Parameters:
page- The page context.pattern- Array of durations in milliseconds.
-
cancel
public static void cancel()Cancels any ongoing vibration using the current page context. -
cancel
Cancels any ongoing vibration.- Parameters:
page- The page context.
-
tap
public static void tap()Short vibration for button/tap feedback using the current page context.Vibrates for 10ms.
-
tap
Short vibration for button/tap feedback.Vibrates for 10ms.
- Parameters:
page- The page context.
-
doubleTap
public static void doubleTap()Double tap vibration pattern using the current page context.Vibrates for 10ms, pauses 50ms, vibrates 10ms.
-
doubleTap
Double tap vibration pattern.Vibrates for 10ms, pauses 50ms, vibrates 10ms.
- Parameters:
page- The page context.
-
success
public static void success()Success notification vibration pattern using the current page context.Two short vibrations.
-
success
Success notification vibration pattern.Two short vibrations.
- Parameters:
page- The page context.
-
error
public static void error()Error notification vibration pattern using the current page context.Three short vibrations.
-
error
Error notification vibration pattern.Three short vibrations.
- Parameters:
page- The page context.
-
warning
public static void warning()Warning notification vibration pattern using the current page context.One long vibration.
-
warning
Warning notification vibration pattern.One long vibration.
- Parameters:
page- The page context.
-
checkSupport
public static void checkSupport()Checks if the Vibration API is supported by the browser using the current page context.Note: This executes JavaScript that logs to console.
-
checkSupport
Checks if the Vibration API is supported by the browser.Note: This executes JavaScript that logs to console.
- Parameters:
page- The page context.
-