Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/view/OrientationListener#constants) \| [Ctors](https://developer.android.com/reference/android/view/OrientationListener#pubctors) \| [Methods](https://developer.android.com/reference/android/view/OrientationListener#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/view/OrientationListener#inhmethods)

# OrientationListener

*** ** * ** ***

` public abstract class OrientationListener `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/hardware/SensorListener `

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

<br />

*** ** * ** ***

<br />

**This class was deprecated in API level 3.**   

use `https://developer.android.com/reference/android/view/OrientationEventListener` instead. This class internally uses the OrientationEventListener.

Helper class for receiving notifications from the SensorManager when the orientation of the device has changed.

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/view/OrientationListener#ORIENTATION_UNKNOWN` Returned from onOrientationChanged when the device orientation cannot be determined (typically when the device is in a close to flat position). |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/view/OrientationListener#OrientationListener(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` Creates a new OrientationListener. |
| ` https://developer.android.com/reference/android/view/OrientationListener#OrientationListener(android.content.Context,%20int)(https://developer.android.com/reference/android/content/Context context, int rate) ` Creates a new OrientationListener. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/view/OrientationListener#disable()() ` Disables the OrientationListener. |
| ` void` | ` https://developer.android.com/reference/android/view/OrientationListener#enable()() ` Enables the OrientationListener so it will monitor the sensor and call `https://developer.android.com/reference/android/view/OrientationListener#onOrientationChanged(int)` when the device orientation changes. |
| ` void` | ` https://developer.android.com/reference/android/view/OrientationListener#onAccuracyChanged(int,%20int)(int sensor, int accuracy) ` Called when the accuracy of a sensor has changed. |
| ` abstract void` | ` https://developer.android.com/reference/android/view/OrientationListener#onOrientationChanged(int)(int orientation) ` Look at `https://developer.android.com/reference/android/view/OrientationEventListener#onOrientationChanged(int)` for method description and usage |
| ` void` | ` https://developer.android.com/reference/android/view/OrientationListener#onSensorChanged(int,%20float[])(int sensor, float[] values) ` <br /> Called when sensor values have changed. |

### 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*.
From interface ` https://developer.android.com/reference/android/hardware/SensorListener ` ` abstract void` ` https://developer.android.com/reference/android/hardware/SensorListener#onAccuracyChanged(int,%20int)(int sensor, int accuracy) `

Called when the accuracy of a sensor has changed.
` abstract void` ` https://developer.android.com/reference/android/hardware/SensorListener#onSensorChanged(int,%20float[])(int sensor, float[] values) `

<br />

Called when sensor values have changed.

## Constants

### ORIENTATION_UNKNOWN

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

```
public static final int ORIENTATION_UNKNOWN
```

Returned from onOrientationChanged when the device orientation cannot be determined (typically when the device is in a close to flat position).

<br />

**See also:**

- `https://developer.android.com/reference/android/view/OrientationListener#onOrientationChanged(int)`

Constant Value: -1 (0xffffffff)

## Public constructors

### OrientationListener

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

```
public OrientationListener (Context context)
```

Creates a new OrientationListener.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: for the OrientationListener. <br /> |

### OrientationListener

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

```
public OrientationListener (Context context, 
                int rate)
```

Creates a new OrientationListener.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: for the OrientationListener. <br /> |
| `rate` | `int`: at which sensor events are processed (see also `https://developer.android.com/reference/android/hardware/SensorManager`). Use the default value of `https://developer.android.com/reference/android/hardware/SensorManager#SENSOR_DELAY_NORMAL` for simple screen orientation change detection. <br /> |

## Public methods

### disable

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

```
public void disable ()
```

Disables the OrientationListener.

<br />

### enable

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

```
public void enable ()
```

Enables the OrientationListener so it will monitor the sensor and call `https://developer.android.com/reference/android/view/OrientationListener#onOrientationChanged(int)` when the device orientation changes.

<br />

### onAccuracyChanged

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

```
public void onAccuracyChanged (int sensor, 
                int accuracy)
```

Called when the accuracy of a sensor has changed. See `https://developer.android.com/reference/android/hardware/SensorManager` for details.

<br />

| Parameters ||
|---|---|
| `sensor` | `int`: The ID of the sensor being monitored <br /> |
| `accuracy` | `int`: The new accuracy of this sensor. <br /> |

### onOrientationChanged

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

```
public abstract void onOrientationChanged (int orientation)
```

Look at `https://developer.android.com/reference/android/view/OrientationEventListener#onOrientationChanged(int)` for method description and usage

<br />

| Parameters ||
|---|---|
| `orientation` | `int`: The new orientation of the device. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/OrientationListener#ORIENTATION_UNKNOWN`

### onSensorChanged

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

```
public void onSensorChanged (int sensor, 
                float[] values)
```

<br />

Called when sensor values have changed. The length and contents of the values array vary depending on which sensor is being monitored. See `https://developer.android.com/reference/android/hardware/SensorManager` for details on possible sensor types.

Definition of the coordinate system used below.

<br />

The X axis refers to the screen's horizontal axis (the small edge in portrait mode, the long edge in landscape mode) and points to the right.

The Y axis refers to the screen's vertical axis and points towards the top of the screen (the origin is in the lower-left corner).

The Z axis points toward the sky when the device is lying on its back on a table.

**IMPORTANT NOTE:** The axis **are swapped** when the device's screen orientation changes. To access the unswapped values, use indices 3, 4 and 5 in values\[\].

`https://developer.android.com/reference/android/hardware/SensorManager#SENSOR_ORIENTATION`, `https://developer.android.com/reference/android/hardware/SensorManager#SENSOR_ORIENTATION_RAW`:

All values are angles in degrees.

values\[0\]: Azimuth, rotation around the Z axis (0\<=azimuth\<360). 0 = North, 90 = East, 180 = South, 270 = West

values\[1\]: Pitch, rotation around X axis (-180\<=pitch\<=180), with positive values when the z-axis moves toward the y-axis.

values\[2\]: Roll, rotation around Y axis (-90\<=roll\<=90), with positive values when the z-axis moves toward the x-axis.

Note that this definition of yaw, pitch and roll is different from the traditional definition used in aviation where the X axis is along the long side of the plane (tail to nose).

`https://developer.android.com/reference/android/hardware/SensorManager#SENSOR_ACCELEROMETER`:

All values are in SI units (m/s\^2) and measure contact forces.

values\[0\]: force applied by the device on the x-axis

values\[1\]: force applied by the device on the y-axis

values\[2\]: force applied by the device on the z-axis

Examples:
- When the device is pushed on its left side toward the right, the x acceleration value is negative (the device applies a reaction force to the push toward the left)
- When the device lies flat on a table, the acceleration value is `https://developer.android.com/reference/android/hardware/SensorManager#STANDARD_GRAVITY`, which correspond to the force the device applies on the table in reaction to gravity.
- `https://developer.android.com/reference/android/hardware/SensorManager#SENSOR_MAGNETIC_FIELD`:
- All values are in micro-Tesla (uT) and measure the ambient magnetic field in the X, Y and -Z axis.
- **Note:** the magnetic field's Z axis is inverted.

| Parameters ||
|---|---|
| `sensor` | `int`: The ID of the sensor being monitored <br /> |
| `values` | `float`: The new values for the sensor. <br /> |