Class VibrationApi

java.lang.Object
com.oorian.html.js.JavaScriptApi
com.oorian.html.js.vibration.VibrationApi

public class VibrationApi extends JavaScriptApi
Provides access to the Vibration API from server-side Java code.

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Cancels any ongoing vibration using the current page context.
    static void
    Cancels any ongoing vibration.
    static void
    Checks if the Vibration API is supported by the browser using the current page context.
    static void
    Checks if the Vibration API is supported by the browser.
    static void
    Double tap vibration pattern using the current page context.
    static void
    Double tap vibration pattern.
    static void
    Error notification vibration pattern using the current page context.
    static void
    Error notification vibration pattern.
    static void
    Success notification vibration pattern using the current page context.
    static void
    Success notification vibration pattern.
    static void
    tap()
    Short vibration for button/tap feedback using the current page context.
    static void
    tap(HtmlPage page)
    Short vibration for button/tap feedback.
    static void
    vibrate(int duration)
    Vibrates the device for the specified duration using the current page context.
    static void
    vibrate(int... pattern)
    Vibrates the device with a pattern using the current page context.
    static void
    vibrate(HtmlPage page, int duration)
    Vibrates the device for the specified duration.
    static void
    vibrate(HtmlPage page, int... pattern)
    Vibrates the device with a pattern.
    static void
    Warning notification vibration pattern using the current page context.
    static void
    Warning notification vibration pattern.

    Methods inherited from class com.oorian.html.js.JavaScriptApi

    executeJs, executeJs, executeJs, executeJs, getPage

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static void vibrate(HtmlPage page, int duration)
      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

      public static void vibrate(HtmlPage page, int... pattern)
      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

      public static void cancel(HtmlPage page)
      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

      public static void tap(HtmlPage page)
      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

      public static void doubleTap(HtmlPage page)
      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

      public static void success(HtmlPage page)
      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

      public static void error(HtmlPage page)
      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

      public static void warning(HtmlPage page)
      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

      public static void checkSupport(HtmlPage page)
      Checks if the Vibration API is supported by the browser.

      Note: This executes JavaScript that logs to console.

      Parameters:
      page - The page context.