VibrationEffect.Composition
  public
  static
  final
  
  class
  VibrationEffect.Composition
  
    extends Object
  
  
  
  
  
  
| java.lang.Object | |
| ↳ | android.os.VibrationEffect.Composition | 
A composition of haptic elements that are combined to be playable as a single
 VibrationEffect.
 
The haptic primitives are available as Composition.PRIMITIVE_* constants and
 can be added to a composition to create a custom vibration effect. Here is an example of an
 effect that grows in intensity and then dies off, with a longer rising portion for emphasis
 and an extra tick 100ms after:
 
 VibrationEffect effect = VibrationEffect.startComposition()
     .addPrimitive(VibrationEffect.Composition.PRIMITIVE_SLOW_RISE, 0.5f)
     .addPrimitive(VibrationEffect.Composition.PRIMITIVE_QUICK_FALL, 0.5f)
     .addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, 1.0f, 100)
     .compose();When choosing to play a composed effect, you should check that individual components are
 supported by the device by using Vibrator.arePrimitivesSupported.
See also:
Summary
| Constants | |
|---|---|
| int | DELAY_TYPE_PAUSEThe delay represents a pause in the composition between the end of the previous primitive and the beginning of the next one. | 
| int | DELAY_TYPE_RELATIVE_START_OFFSETThe delay represents an offset before starting this primitive, relative to the start time of the previous primitive in the composition. | 
| int | PRIMITIVE_CLICKThis effect should produce a sharp, crisp click sensation. | 
| int | PRIMITIVE_LOW_TICKThis very short low frequency effect should produce a light crisp sensation intended to be used repetitively for dynamic feedback. | 
| int | PRIMITIVE_QUICK_FALLA haptic effect that simulates quick downwards movement with gravity. | 
| int | PRIMITIVE_QUICK_RISEA haptic effect that simulates quick upward movement against gravity. | 
| int | PRIMITIVE_SLOW_RISEA haptic effect that simulates slow upward movement against gravity. | 
| int | PRIMITIVE_SPINA haptic effect that simulates spinning momentum. | 
| int | PRIMITIVE_THUDA haptic effect that simulates downwards movement with gravity. | 
| int | PRIMITIVE_TICKThis very short effect should produce a light crisp sensation intended to be used repetitively for dynamic feedback. | 
| Public methods | |
|---|---|
| 
        
        
        
        
        
        VibrationEffect.Composition | 
      addPrimitive(int primitiveId)
      Add a haptic primitive to the end of the current composition. | 
| 
        
        
        
        
        
        VibrationEffect.Composition | 
      addPrimitive(int primitiveId, float scale, int delay)
      Add a haptic primitive to the end of the current composition. | 
| 
        
        
        
        
        
        VibrationEffect.Composition | 
      addPrimitive(int primitiveId, float scale, int delay, int delayType)
      Add a haptic primitive to the end of the current composition. | 
| 
        
        
        
        
        
        VibrationEffect.Composition | 
      addPrimitive(int primitiveId, float scale)
      Add a haptic primitive to the end of the current composition. | 
| 
        
        
        
        
        
        VibrationEffect | 
      compose()
      Compose all of the added primitives together into a single  | 
| Inherited methods | |
|---|---|
Constants
DELAY_TYPE_PAUSE
public static final int DELAY_TYPE_PAUSE
The delay represents a pause in the composition between the end of the previous primitive and the beginning of the next one.
The primitive will start after the requested pause after the last primitive ended. The actual time the primitive will be played depends on the previous primitive's actual duration on the device hardware. This enables the combination of primitives to create more complex effects based on how close to each other they'll play. Here is an example:
     VibrationEffect popEffect = VibrationEffect.startComposition()
         .addPrimitive(PRIMITIVE_QUICK_RISE)
         .addPrimitive(PRIMITIVE_CLICK, 0.7, 50, DELAY_TYPE_PAUSE)
         .compose()
 Constant Value: 0 (0x00000000)
DELAY_TYPE_RELATIVE_START_OFFSET
public static final int DELAY_TYPE_RELATIVE_START_OFFSET
The delay represents an offset before starting this primitive, relative to the start time of the previous primitive in the composition.
The primitive will start at the requested fixed time after the last primitive started, independently of that primitive's actual duration on the device hardware. This enables precise timings of primitives within a composition, ensuring they'll be played at the desired intervals. Here is an example:
     VibrationEffect.startComposition()
         .addPrimitive(PRIMITIVE_CLICK, 1.0)
         .addPrimitive(PRIMITIVE_TICK, 1.0, 20, DELAY_TYPE_RELATIVE_START_OFFSET)
         .addPrimitive(PRIMITIVE_THUD, 1.0, 80, DELAY_TYPE_RELATIVE_START_OFFSET)
         .compose()
 0ms 20ms 100ms PRIMITIVE_CLICK---PRIMITIVE_TICK-----------PRIMITIVE_THUD
A primitive will be dropped from the composition if it overlaps with previous ones.
Constant Value: 1 (0x00000001)
PRIMITIVE_CLICK
public static final int PRIMITIVE_CLICK
This effect should produce a sharp, crisp click sensation.
Constant Value: 1 (0x00000001)
PRIMITIVE_LOW_TICK
public static final int PRIMITIVE_LOW_TICK
This very short low frequency effect should produce a light crisp sensation intended to be used repetitively for dynamic feedback.
Constant Value: 8 (0x00000008)
PRIMITIVE_QUICK_FALL
public static final int PRIMITIVE_QUICK_FALL
A haptic effect that simulates quick downwards movement with gravity.
Constant Value: 6 (0x00000006)
PRIMITIVE_QUICK_RISE
public static final int PRIMITIVE_QUICK_RISE
A haptic effect that simulates quick upward movement against gravity.
Constant Value: 4 (0x00000004)
PRIMITIVE_SLOW_RISE
public static final int PRIMITIVE_SLOW_RISE
A haptic effect that simulates slow upward movement against gravity.
Constant Value: 5 (0x00000005)
PRIMITIVE_SPIN
public static final int PRIMITIVE_SPIN
A haptic effect that simulates spinning momentum.
Constant Value: 3 (0x00000003)
PRIMITIVE_THUD
public static final int PRIMITIVE_THUD
A haptic effect that simulates downwards movement with gravity. Often followed by extra energy of hitting and reverberation to augment physicality.
Constant Value: 2 (0x00000002)
PRIMITIVE_TICK
public static final int PRIMITIVE_TICK
This very short effect should produce a light crisp sensation intended to be used repetitively for dynamic feedback.
Constant Value: 7 (0x00000007)
Public methods
addPrimitive
public VibrationEffect.Composition addPrimitive (int primitiveId)
Add a haptic primitive to the end of the current composition.
Similar to addPrimitive(int, float, int), but with no delay and a
 default scale applied.
| Parameters | |
|---|---|
| primitiveId | int: The primitive to add
 Value isPRIMITIVE_CLICK,PRIMITIVE_THUD,PRIMITIVE_SPIN,PRIMITIVE_QUICK_RISE,PRIMITIVE_SLOW_RISE,PRIMITIVE_QUICK_FALL,PRIMITIVE_TICK, orPRIMITIVE_LOW_TICK | 
| Returns | |
|---|---|
| VibrationEffect.Composition | This Compositionobject to enable adding multiple elements in one chain.
 This value cannot benull. | 
addPrimitive
public VibrationEffect.Composition addPrimitive (int primitiveId, float scale, int delay)
Add a haptic primitive to the end of the current composition.
Similar to addPrimitive(int, float, int, int), but default
 delay type applied is DELAY_TYPE_PAUSE.
| Parameters | |
|---|---|
| primitiveId | int: The primitive to add
 Value isPRIMITIVE_CLICK,PRIMITIVE_THUD,PRIMITIVE_SPIN,PRIMITIVE_QUICK_RISE,PRIMITIVE_SLOW_RISE,PRIMITIVE_QUICK_FALL,PRIMITIVE_TICK, orPRIMITIVE_LOW_TICK | 
| scale | float: The scale to apply to the intensity of the primitive.
 Value is between 0.0f and 1.0f inclusive | 
| delay | int: The amount of time in milliseconds to wait between the end of the last
              primitive and the beginning of this one (i.e. a pause in the composition).
 Value is 0 or greater | 
| Returns | |
|---|---|
| VibrationEffect.Composition | This Compositionobject to enable adding multiple elements in one chain.
 This value cannot benull. | 
addPrimitive
public VibrationEffect.Composition addPrimitive (int primitiveId, float scale, int delay, int delayType)
Add a haptic primitive to the end of the current composition.
| Parameters | |
|---|---|
| primitiveId | int: The primitive to add
 Value isPRIMITIVE_CLICK,PRIMITIVE_THUD,PRIMITIVE_SPIN,PRIMITIVE_QUICK_RISE,PRIMITIVE_SLOW_RISE,PRIMITIVE_QUICK_FALL,PRIMITIVE_TICK, orPRIMITIVE_LOW_TICK | 
| scale | float: The scale to apply to the intensity of the primitive.
 Value is between 0.0f and 1.0f inclusive | 
| delay | int: The amount of time in milliseconds to wait before playing this primitive,
              as defined by the givendelayType.
 Value is 0 or greater | 
| delayType | int: The type of delay to be applied, e.g. a pause between last primitive and
                  this one or a start offset.
 Value isDELAY_TYPE_PAUSE, orDELAY_TYPE_RELATIVE_START_OFFSET | 
| Returns | |
|---|---|
| VibrationEffect.Composition | This Compositionobject to enable adding multiple elements in one chain.
 This value cannot benull. | 
addPrimitive
public VibrationEffect.Composition addPrimitive (int primitiveId, float scale)
Add a haptic primitive to the end of the current composition.
Similar to addPrimitive(int, float, int), but with no delay.
| Parameters | |
|---|---|
| primitiveId | int: The primitive to add
 Value isPRIMITIVE_CLICK,PRIMITIVE_THUD,PRIMITIVE_SPIN,PRIMITIVE_QUICK_RISE,PRIMITIVE_SLOW_RISE,PRIMITIVE_QUICK_FALL,PRIMITIVE_TICK, orPRIMITIVE_LOW_TICK | 
| scale | float: The scale to apply to the intensity of the primitive.
 Value is between 0.0f and 1.0f inclusive | 
| Returns | |
|---|---|
| VibrationEffect.Composition | This Compositionobject to enable adding multiple elements in one chain.
 This value cannot benull. | 
compose
public VibrationEffect compose ()
Compose all of the added primitives together into a single VibrationEffect.
 
The Composition object is still valid after this call, so you can continue
 adding more primitives to it and generating more VibrationEffects by calling this
 method again.
| Returns | |
|---|---|
| VibrationEffect | The VibrationEffectresulting from the composition of the primitives.
 This value cannot benull. | 
