# Print output for @column tags ?>
public
abstract
class
VibrationEffect
extends Object
implements
Parcelable
java.lang.Object | |
↳ | 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.
Nested classes | |
---|---|
class |
VibrationEffect.Composition
A composition of haptic primitives that, when combined, create a single haptic effect. |
Constants | |
---|---|
int |
DEFAULT_AMPLITUDE
The default vibration strength of the device. |
int |
EFFECT_CLICK
A click effect. |
int |
EFFECT_DOUBLE_CLICK
A double click effect. |
int |
EFFECT_HEAVY_CLICK
A heavy click effect. |
int |
EFFECT_TICK
A tick effect. |
Inherited constants |
---|
Fields | |
---|---|
public
static
final
Creator<VibrationEffect> |
CREATOR
|
Public methods | |
---|---|
static
VibrationEffect
|
createOneShot(long milliseconds, int amplitude)
Create a one shot vibration. |
static
VibrationEffect
|
createPredefined(int effectId)
Create a predefined vibration effect. |
static
VibrationEffect
|
createWaveform(long[] timings, int[] amplitudes, int repeat)
Create a waveform vibration. |
static
VibrationEffect
|
createWaveform(long[] timings, int repeat)
Create a waveform vibration. |
int
|
describeContents()
Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
static
VibrationEffect.Composition
|
startComposition()
Start composing a haptic effect. |
Inherited methods | |
---|---|
public static final int DEFAULT_AMPLITUDE
The default vibration strength of the device.
Constant Value: -1 (0xffffffff)
public static final int EFFECT_CLICK
A click effect. Use this effect as a baseline, as it's the most common type of click effect.
Constant Value: 0 (0x00000000)
public static final int EFFECT_DOUBLE_CLICK
A double click effect.
Constant Value: 1 (0x00000001)
public static final int EFFECT_HEAVY_CLICK
A heavy click effect. This effect is stronger than EFFECT_CLICK
.
Constant Value: 5 (0x00000005)
public static final int EFFECT_TICK
A tick effect. This effect is less strong compared to EFFECT_CLICK
.
Constant Value: 2 (0x00000002)
public static VibrationEffect createOneShot (long milliseconds, int amplitude)
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 . |
Returns | |
---|---|
VibrationEffect |
The desired effect. |
public static VibrationEffect createPredefined (int effectId)
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 EFFECT_TICK , EFFECT_CLICK , EFFECT_HEAVY_CLICK , or EFFECT_DOUBLE_CLICK |
Returns | |
---|---|
VibrationEffect |
The desired effect.
This value cannot be null . |
public static VibrationEffect createWaveform (long[] timings, int[] amplitudes, int repeat)
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, in milliseconds. Amplitude values must be between 0 and 255, and an amplitude of 0 implies no vibration (i.e. off). 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 |
long : The timing values, in milliseconds, of the timing / amplitude pairs. Timing
values of 0 will cause the pair to be ignored. |
amplitudes |
int : 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. |
Returns | |
---|---|
VibrationEffect |
The desired effect. |
public static VibrationEffect createWaveform (long[] timings, int repeat)
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 |
long : 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. |
Returns | |
---|---|
VibrationEffect |
The desired effect. |
public int describeContents ()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation. For example, if the object will
include a file descriptor in the output of writeToParcel(android.os.Parcel, int)
,
the return value of this method must include the
CONTENTS_FILE_DESCRIPTOR
bit.
Returns | |
---|---|
int |
a bitmask indicating the set of special object types marshaled
by this Parcelable object instance.
Value is either 0 or CONTENTS_FILE_DESCRIPTOR |
public static VibrationEffect.Composition startComposition ()
Start composing a haptic effect.
Returns | |
---|---|
VibrationEffect.Composition |
This value cannot be null . |
See also: