Package org.vaadin.firitin.devicemotion
Class DeviceSensorPermissions
java.lang.Object
org.vaadin.firitin.devicemotion.DeviceSensorPermissions
Helper class for handling device sensor permissions (motion and orientation).
On iOS 13+, these permissions must be requested from a user-initiated action (click event).
This class provides utilities to handle permissions seamlessly.
- Author:
- mstahv
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
configurePermissionRequest
(com.vaadin.flow.component.button.Button button, DeviceSensorPermissions.SensorType sensorType, Runnable onSuccess, Runnable onError) Configures an existing button to request permissions on click, then execute the action callback on the server side.static com.vaadin.flow.component.button.Button
createRequestPermissionButton
(String buttonText, DeviceSensorPermissions.SensorType sensorType, Runnable onSuccess, Runnable onError) Creates a button that requests the specified permissions on click, then executes the onSuccess callback if permissions are granted.static boolean
isPermissionRequired
(com.vaadin.flow.component.UI ui, DeviceSensorPermissions.SensorType sensorType) Checks if device sensor permissions are required on this platform.
-
Constructor Details
-
DeviceSensorPermissions
public DeviceSensorPermissions()
-
-
Method Details
-
createRequestPermissionButton
public static com.vaadin.flow.component.button.Button createRequestPermissionButton(String buttonText, DeviceSensorPermissions.SensorType sensorType, Runnable onSuccess, Runnable onError) Creates a button that requests the specified permissions on click, then executes the onSuccess callback if permissions are granted.- Parameters:
buttonText
- the text for the buttonsensorType
- which sensor permissions to requestonSuccess
- callback to execute after permissions are granted (on server side)onError
- callback to execute if permissions are denied (on server side)- Returns:
- a configured button
-
configurePermissionRequest
public static void configurePermissionRequest(com.vaadin.flow.component.button.Button button, DeviceSensorPermissions.SensorType sensorType, Runnable onSuccess, Runnable onError) Configures an existing button to request permissions on click, then execute the action callback on the server side. This allows seamless integration - clicking the button requests permissions if needed, then executes the intended action.- Parameters:
button
- the button to configuresensorType
- which sensor permissions to requestonSuccess
- callback to execute after permissions are granted (on server side)onError
- callback to execute if permissions are denied (on server side)
-
isPermissionRequired
public static boolean isPermissionRequired(com.vaadin.flow.component.UI ui, DeviceSensorPermissions.SensorType sensorType) Checks if device sensor permissions are required on this platform. Returns true on iOS 13+ Safari.- Parameters:
ui
- the UI contextsensorType
- which sensor to check- Returns:
- true if permission request is needed
-