VibrationEffect
abstract class VibrationEffect : Parcelable
| kotlin.Any | |
| ↳ | android.os.VibrationEffect |
A VibrationEffect describes a haptic effect to be performed by a Vibrator. These effects may be any number of things, from single shot vibrations to complex waveforms.
Summary
Nested classes |
|
|---|---|
|
A composition of haptic primitives that, when combined, create a single haptic effect. |
|
Constants |
|
|---|---|
| static Int |
The default vibration strength of the device. |
| static Int |
A click effect. |
| static Int |
A double click effect. |
| static Int |
A heavy click effect. |
| static Int |
A tick effect. |
Inherited constants |
|
|---|---|
Public methods |
|
|---|---|
| open static VibrationEffect! |
createOneShot(milliseconds: Long, amplitude: Int)Create a one shot vibration. |
| open static VibrationEffect |
createPredefined(effectId: Int)Create a predefined vibration effect. |
| open static VibrationEffect! |
createWaveform(timings: LongArray!, repeat: Int)Create a waveform vibration. |
| open static VibrationEffect! |
createWaveform(timings: LongArray!, amplitudes: IntArray!, repeat: Int)Create a waveform vibration. |
| open Int | |
| open static VibrationEffect.Composition |
Start composing a haptic effect. |
Inherited functions |
|
|---|---|
Properties |
|
|---|---|
| static Parcelable.Creator<VibrationEffect!> | |
Constants
DEFAULT_AMPLITUDE
static val DEFAULT_AMPLITUDE: Int
The default vibration strength of the device.
Value: -1
EFFECT_CLICK
static val EFFECT_CLICK: Int
A click effect. Use this effect as a baseline, as it's the most common type of click effect.
Value: 0
See Also
#get(int)
EFFECT_DOUBLE_CLICK
static val EFFECT_DOUBLE_CLICK: Int
A double click effect.
Value: 1
See Also
#get(int)
EFFECT_HEAVY_CLICK
static val EFFECT_HEAVY_CLICK: Int
A heavy click effect. This effect is stronger than EFFECT_CLICK.
Value: 5
See Also
#get(int)
EFFECT_TICK
static val EFFECT_TICK: Int
A tick effect. This effect is less strong compared to EFFECT_CLICK.
Value: 2
See Also
#get(int)
Public methods
createOneShot
open static fun createOneShot(
milliseconds: Long,
amplitude: Int
): VibrationEffect!
Create a one shot vibration. One shot vibrations will vibrate constantly for the specified period of time at the specified amplitude, and then stop.
| Parameters | |
|---|---|
milliseconds |
Long: The number of milliseconds to vibrate. This must be a positive number. |
amplitude |
Int: The strength of the vibration. This must be a value between 1 and 255, or DEFAULT_AMPLITUDE. |
| Return | |
|---|---|
VibrationEffect! |
The desired effect. |
createPredefined
open static fun createPredefined(effectId: Int): VibrationEffect
Create a predefined vibration effect. Predefined effects are a set of common vibration effects that should be identical, regardless of the app they come from, in order to provide a cohesive experience for users across the entire device. They also may be custom tailored to the device hardware in order to provide a better experience than you could otherwise build using the generic building blocks. This will fallback to a generic pattern if one exists and there does not exist a hardware-specific implementation of the effect.
| Parameters | |
|---|---|
effectId |
Int: The ID of the effect to perform: EFFECT_CLICK, EFFECT_DOUBLE_CLICK, EFFECT_TICK Value is android.os.VibrationEffect#EFFECT_TICK, android.os.VibrationEffect#EFFECT_CLICK, android.os.VibrationEffect#EFFECT_HEAVY_CLICK, or android.os.VibrationEffect#EFFECT_DOUBLE_CLICK |
| Return | |
|---|---|
VibrationEffect |
The desired effect. This value cannot be null. |
createWaveform
open static fun createWaveform(
timings: LongArray!,
repeat: Int
): VibrationEffect!
Create a waveform vibration. Waveform vibrations are a potentially repeating series of timing and amplitude pairs. For each pair, the value in the amplitude array determines the strength of the vibration and the value in the timing array determines how long it vibrates for. An amplitude of 0 implies no vibration (i.e. off), and any pairs with a timing value of 0 will be ignored.
The amplitude array of the generated waveform will be the same size as the given timing array with alternating values of 0 (i.e. off) and DEFAULT_AMPLITUDE, starting with 0. Therefore the first timing value will be the period to wait before turning the vibrator on, the second value will be how long to vibrate at DEFAULT_AMPLITUDE strength, etc.
To cause the pattern to repeat, pass the index into the timings array at which to start the repetition, or -1 to disable repeating.
| Parameters | |
|---|---|
timings |
LongArray!: The pattern of alternating on-off timings, starting with off. Timing values of 0 will cause the timing / amplitude pair to be ignored. |
repeat |
Int: The index into the timings array at which to repeat, or -1 if you you don't want to repeat. |
| Return | |
|---|---|
VibrationEffect! |
The desired effect. |
createWaveform
open static fun createWaveform(
timings: LongArray!,
amplitudes: IntArray!,
repeat: Int
): VibrationEffect!
Create a waveform vibration. Waveform vibrations are a potentially repeating series of timing and amplitude pairs. For each pair, the value in the amplitude array determines the strength of the vibration and the value in the timing array determines how long it vibrates for. An amplitude of 0 implies no vibration (i.e. off), and any pairs with a timing value of 0 will be ignored.
To cause the pattern to repeat, pass the index into the timings array at which to start the repetition, or -1 to disable repeating.
| Parameters | |
|---|---|
timings |
LongArray!: The timing values of the timing / amplitude pairs. Timing values of 0 will cause the pair to be ignored. |
amplitudes |
IntArray!: The amplitude values of the timing / amplitude pairs. Amplitude values must be between 0 and 255, or equal to DEFAULT_AMPLITUDE. An amplitude value of 0 implies the motor is off. |
repeat |
Int: The index into the timings array at which to repeat, or -1 if you you don't want to repeat. |
| Return | |
|---|---|
VibrationEffect! |
The desired effect. |
describeContents
open fun describeContents(): Int
| Return | |
|---|---|
Int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR |
startComposition
open static fun startComposition(): VibrationEffect.Composition
Start composing a haptic effect.
| Return | |
|---|---|
VibrationEffect.Composition |
This value cannot be null. |