Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/os/VibrationEffect.Composition#constants) \| [Methods](https://developer.android.com/reference/android/os/VibrationEffect.Composition#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/os/VibrationEffect.Composition#inhmethods)

# VibrationEffect.Composition

*** ** * ** ***


`
public
static
final

class
VibrationEffect.Composition
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.os.VibrationEffect.Composition |

<br />

*** ** * ** ***

A composition of haptic elements that are combined to be playable as a single
`https://developer.android.com/reference/android/os/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 `https://developer.android.com/reference/android/os/Vibrator#arePrimitivesSupported(int[])`.
**See also:**

- `https://developer.android.com/reference/android/os/VibrationEffect#startComposition()`

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect.Composition#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. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect.Composition#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. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_CLICK` This effect should produce a sharp, crisp click sensation. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_LOW_TICK` This very short low frequency effect should produce a light crisp sensation intended to be used repetitively for dynamic feedback. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_FALL` A haptic effect that simulates quick downwards movement with gravity. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_RISE` A haptic effect that simulates quick upward movement against gravity. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SLOW_RISE` A haptic effect that simulates slow upward movement against gravity. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SPIN` A haptic effect that simulates spinning momentum. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_THUD` A haptic effect that simulates downwards movement with gravity. |
| `int` | `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_TICK` This very short effect should produce a light crisp sensation intended to be used repetitively for dynamic feedback. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/os/VibrationEffect.Composition` | ` https://developer.android.com/reference/android/os/VibrationEffect.Composition#addPrimitive(int)(int primitiveId) ` Add a haptic primitive to the end of the current composition. |
| ` https://developer.android.com/reference/android/os/VibrationEffect.Composition` | ` https://developer.android.com/reference/android/os/VibrationEffect.Composition#addPrimitive(int,%20float,%20int)(int primitiveId, float scale, int delay) ` Add a haptic primitive to the end of the current composition. |
| ` https://developer.android.com/reference/android/os/VibrationEffect.Composition` | ` https://developer.android.com/reference/android/os/VibrationEffect.Composition#addPrimitive(int,%20float,%20int,%20int)(int primitiveId, float scale, int delay, int delayType) ` Add a haptic primitive to the end of the current composition. |
| ` https://developer.android.com/reference/android/os/VibrationEffect.Composition` | ` https://developer.android.com/reference/android/os/VibrationEffect.Composition#addPrimitive(int,%20float)(int primitiveId, float scale) ` Add a haptic primitive to the end of the current composition. |
| ` https://developer.android.com/reference/android/os/VibrationEffect` | ` https://developer.android.com/reference/android/os/VibrationEffect.Composition#compose()() ` Compose all of the added primitives together into a single `https://developer.android.com/reference/android/os/VibrationEffect`. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### DELAY_TYPE_PAUSE

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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()
```

<br />

<br />

Constant Value:

0
(0x00000000)


### DELAY_TYPE_RELATIVE_START_OFFSET

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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()
```
Will be performed on the device as follows:

```
 0ms               20ms                     100ms
 PRIMITIVE_CLICK---PRIMITIVE_TICK---PRIMITIVE_THUD
```

A primitive will be dropped from the composition if it overlaps with previous ones.

<br />

Constant Value:

1
(0x00000001)


### PRIMITIVE_CLICK

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PRIMITIVE_CLICK
```

This effect should produce a sharp, crisp click sensation.

<br />

Constant Value:

1
(0x00000001)


### PRIMITIVE_LOW_TICK

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

Constant Value:

8
(0x00000008)


### PRIMITIVE_QUICK_FALL

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PRIMITIVE_QUICK_FALL
```

A haptic effect that simulates quick downwards movement with gravity.

<br />

Constant Value:

6
(0x00000006)


### PRIMITIVE_QUICK_RISE

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PRIMITIVE_QUICK_RISE
```

A haptic effect that simulates quick upward movement against gravity.

<br />

Constant Value:

4
(0x00000004)


### PRIMITIVE_SLOW_RISE

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PRIMITIVE_SLOW_RISE
```

A haptic effect that simulates slow upward movement against gravity.

<br />

Constant Value:

5
(0x00000005)


### PRIMITIVE_SPIN

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PRIMITIVE_SPIN
```

A haptic effect that simulates spinning momentum.

<br />

Constant Value:

3
(0x00000003)


### PRIMITIVE_THUD

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

Constant Value:

2
(0x00000002)


### PRIMITIVE_TICK

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int PRIMITIVE_TICK
```

This very short effect should produce a light crisp sensation intended
to be used repetitively for dynamic feedback.

<br />

Constant Value:

7
(0x00000007)


## Public methods

### addPrimitive

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public VibrationEffect.Composition addPrimitive (int primitiveId)
```

Add a haptic primitive to the end of the current composition.

Similar to `https://developer.android.com/reference/android/os/VibrationEffect.Composition#addPrimitive(int,%20float,%20int)`, but with no delay and a
default scale applied.

<br />

| Parameters ||
|---|---|
| `primitiveId` | `int`: The primitive to add. Value is one of the following: - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_CLICK` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_THUD` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SPIN` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_RISE` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SLOW_RISE` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_FALL` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_TICK` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_LOW_TICK` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect.Composition` | This `https://developer.android.com/reference/android/os/VibrationEffect.Composition` object to enable adding multiple elements in one chain. This value cannot be `null`. <br /> |

### addPrimitive

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public VibrationEffect.Composition addPrimitive (int primitiveId, 
                float scale, 
                int delay)
```

Add a haptic primitive to the end of the current composition.

Similar to `https://developer.android.com/reference/android/os/VibrationEffect.Composition#addPrimitive(int,%20float,%20int,%20int)`, but default
delay type applied is `https://developer.android.com/reference/android/os/VibrationEffect.Composition#DELAY_TYPE_PAUSE`.

<br />

| Parameters ||
|---|---|
| `primitiveId` | `int`: The primitive to add. Value is one of the following: - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_CLICK` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_THUD` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SPIN` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_RISE` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SLOW_RISE` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_FALL` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_TICK` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_LOW_TICK` |
| `scale` | `float`: The scale to apply to the intensity of the primitive. Value is between 0.0f and 1.0f inclusive <br /> |
| `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 <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect.Composition` | This `https://developer.android.com/reference/android/os/VibrationEffect.Composition` object to enable adding multiple elements in one chain. This value cannot be `null`. <br /> |

### addPrimitive

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public VibrationEffect.Composition addPrimitive (int primitiveId, 
                float scale, 
                int delay, 
                int delayType)
```

Add a haptic primitive to the end of the current composition.

<br />

| Parameters ||
|---|---|
| `primitiveId` | `int`: The primitive to add. Value is one of the following: - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_CLICK` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_THUD` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SPIN` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_RISE` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SLOW_RISE` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_FALL` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_TICK` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_LOW_TICK` |
| `scale` | `float`: The scale to apply to the intensity of the primitive. Value is between 0.0f and 1.0f inclusive <br /> |
| `delay` | `int`: The amount of time in milliseconds to wait before playing this primitive, as defined by the given `delayType`. Value is 0 or greater <br /> |
| `delayType` | `int`: The type of delay to be applied, e.g. a pause between last primitive and this one or a start offset. Value is one of the following: - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#DELAY_TYPE_PAUSE` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#DELAY_TYPE_RELATIVE_START_OFFSET` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect.Composition` | This `https://developer.android.com/reference/android/os/VibrationEffect.Composition` object to enable adding multiple elements in one chain. This value cannot be `null`. <br /> |

### addPrimitive

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public VibrationEffect.Composition addPrimitive (int primitiveId, 
                float scale)
```

Add a haptic primitive to the end of the current composition.

Similar to `https://developer.android.com/reference/android/os/VibrationEffect.Composition#addPrimitive(int,%20float,%20int)`, but with no delay.

<br />

| Parameters ||
|---|---|
| `primitiveId` | `int`: The primitive to add. Value is one of the following: - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_CLICK` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_THUD` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SPIN` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_RISE` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_SLOW_RISE` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_QUICK_FALL` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_TICK` - `https://developer.android.com/reference/android/os/VibrationEffect.Composition#PRIMITIVE_LOW_TICK` |
| `scale` | `float`: The scale to apply to the intensity of the primitive. Value is between 0.0f and 1.0f inclusive <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect.Composition` | This `https://developer.android.com/reference/android/os/VibrationEffect.Composition` object to enable adding multiple elements in one chain. This value cannot be `null`. <br /> |

### compose

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public VibrationEffect compose ()
```

Compose all of the added primitives together into a single `https://developer.android.com/reference/android/os/VibrationEffect`.

The `https://developer.android.com/reference/android/os/VibrationEffect.Composition` object is still valid after this call, so you can continue
adding more primitives to it and generating more `https://developer.android.com/reference/android/os/VibrationEffect`s by calling this
method again.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/VibrationEffect` | The `https://developer.android.com/reference/android/os/VibrationEffect` resulting from the composition of the primitives. This value cannot be `null`. <br /> |