# GestureUtils

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Methods](https://developer.android.com/reference/android/gesture/GestureUtils#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/gesture/GestureUtils#inhmethods)  

# GestureUtils

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/gesture/GestureUtils "View this page in Kotlin")\|Java

`
public

final

class
GestureUtils
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.gesture.GestureUtils |

<br />

*** ** * ** ***

Utility functions for gesture processing \& analysis, including methods for:

- feature extraction (e.g., samplers and those for calculating bounding boxes and gesture path lengths);
- geometric transformation (e.g., translation, rotation and scaling);
- gesture similarity comparison (e.g., calculating Euclidean or Cosine distances between two gestures).

<br />

## Summary

|                                                                                                                                                                                                                                                                   ### Public methods                                                                                                                                                                                                                                                                   ||
|--------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static `[OrientedBoundingBox](https://developer.android.com/reference/android/gesture/OrientedBoundingBox) | ` `[computeOrientedBoundingBox](https://developer.android.com/reference/android/gesture/GestureUtils#computeOrientedBoundingBox(java.util.ArrayList<android.gesture.GesturePoint>))`(`[ArrayList](https://developer.android.com/reference/java/util/ArrayList)`<`[GesturePoint](https://developer.android.com/reference/android/gesture/GesturePoint)`> originalPoints) ` Computes an oriented, minimum bounding box of a set of points. |
| ` static `[OrientedBoundingBox](https://developer.android.com/reference/android/gesture/OrientedBoundingBox) | ` `[computeOrientedBoundingBox](https://developer.android.com/reference/android/gesture/GestureUtils#computeOrientedBoundingBox(float[]))`(float[] originalPoints) ` Computes an oriented, minimum bounding box of a set of points.                                                                                                                                                                                                      |
| ` static float[]`                                                                                            | ` `[spatialSampling](https://developer.android.com/reference/android/gesture/GestureUtils#spatialSampling(android.gesture.Gesture,%20int))`(`[Gesture](https://developer.android.com/reference/android/gesture/Gesture)` gesture, int bitmapSize) ` Samples the gesture spatially by rendering the gesture into a 2D grayscale bitmap.                                                                                                   |
| ` static float[]`                                                                                            | ` `[spatialSampling](https://developer.android.com/reference/android/gesture/GestureUtils#spatialSampling(android.gesture.Gesture,%20int,%20boolean))`(`[Gesture](https://developer.android.com/reference/android/gesture/Gesture)` gesture, int bitmapSize, boolean keepAspectRatio) ` Samples the gesture spatially by rendering the gesture into a 2D grayscale bitmap.                                                               |
| ` static float[]`                                                                                            | ` `[temporalSampling](https://developer.android.com/reference/android/gesture/GestureUtils#temporalSampling(android.gesture.GestureStroke,%20int))`(`[GestureStroke](https://developer.android.com/reference/android/gesture/GestureStroke)` stroke, int numPoints) ` Samples a stroke temporally into a given number of evenly-distributed points.                                                                                      |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](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 `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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*.                                                                                             | ||

## Public methods

### computeOrientedBoundingBox

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

```
public static OrientedBoundingBox computeOrientedBoundingBox (ArrayList<GesturePoint> originalPoints)
```

Computes an oriented, minimum bounding box of a set of points.

<br />

|                                                               Returns                                                               ||
|----------------------------------------------------------------------------------------------------|---------------------------------|
| [OrientedBoundingBox](https://developer.android.com/reference/android/gesture/OrientedBoundingBox) | an oriented bounding box <br /> |

### computeOrientedBoundingBox

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

```
public static OrientedBoundingBox computeOrientedBoundingBox (float[] originalPoints)
```

Computes an oriented, minimum bounding box of a set of points.

<br />

|                                                               Returns                                                               ||
|----------------------------------------------------------------------------------------------------|---------------------------------|
| [OrientedBoundingBox](https://developer.android.com/reference/android/gesture/OrientedBoundingBox) | an oriented bounding box <br /> |

### spatialSampling

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

```
public static float[] spatialSampling (Gesture gesture, 
                int bitmapSize)
```

Samples the gesture spatially by rendering the gesture into a 2D grayscale bitmap. Scales the gesture to fit the size of the bitmap. The scaling does not necessarily keep the aspect ratio of the gesture.

<br />

|                        Parameters                         ||
|--------------|---------------------------------------------|
| `gesture`    | `Gesture`: the gesture to be sampled <br /> |
| `bitmapSize` | `int`: the size of the bitmap <br />        |

|                                                                                           Returns                                                                                           ||
|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `float[]` | a bitmapSize x bitmapSize grayscale bitmap that is represented as a 1D array. The float at index i represents the grayscale value at pixel \[i%bitmapSize, i/bitmapSize\] <br /> |

### spatialSampling

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

```
public static float[] spatialSampling (Gesture gesture, 
                int bitmapSize, 
                boolean keepAspectRatio)
```

Samples the gesture spatially by rendering the gesture into a 2D grayscale bitmap. Scales the gesture to fit the size of the bitmap.

<br />

|                                         Parameters                                         ||
|-------------------|-------------------------------------------------------------------------|
| `gesture`         | `Gesture`: the gesture to be sampled <br />                             |
| `bitmapSize`      | `int`: the size of the bitmap <br />                                    |
| `keepAspectRatio` | `boolean`: if the scaling should keep the gesture's aspect ratio <br /> |

|                                                                                           Returns                                                                                           ||
|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `float[]` | a bitmapSize x bitmapSize grayscale bitmap that is represented as a 1D array. The float at index i represents the grayscale value at pixel \[i%bitmapSize, i/bitmapSize\] <br /> |

### temporalSampling

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

```
public static float[] temporalSampling (GestureStroke stroke, 
                int numPoints)
```

Samples a stroke temporally into a given number of evenly-distributed points.

<br />

|                              Parameters                               ||
|-------------|----------------------------------------------------------|
| `stroke`    | `GestureStroke`: the gesture stroke to be sampled <br /> |
| `numPoints` | `int`: the number of points <br />                       |

|                                       Returns                                       ||
|-----------|--------------------------------------------------------------------------|
| `float[]` | the sampled points in the form of \[x1, y1, x2, y2, ..., xn, yn\] <br /> |