Added in API level 3

OrientationEventListener


abstract class OrientationEventListener
kotlin.Any
   ↳ android.view.OrientationEventListener

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

Summary

Constants
static Int

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

Public constructors

Creates a new OrientationEventListener.

Creates a new OrientationEventListener.

Public methods
open Boolean

open Unit

Disables the OrientationEventListener.

open Unit

Enables the OrientationEventListener so it will monitor the sensor and call onOrientationChanged when the device orientation changes.

abstract Unit
onOrientationChanged(orientation: Int)

Called when the orientation of the device has changed.

Constants

ORIENTATION_UNKNOWN

Added in API level 3
static val ORIENTATION_UNKNOWN: Int

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

Value: -1

Public constructors

OrientationEventListener

Added in API level 3
OrientationEventListener(context: Context!)

Creates a new OrientationEventListener.

Parameters
context Context!: for the OrientationEventListener.

OrientationEventListener

Added in API level 3
OrientationEventListener(
    context: Context!,
    rate: Int)

Creates a new OrientationEventListener.

Parameters
context Context!: for the OrientationEventListener.
rate Int: at which sensor events are processed (see also SensorManager). Use the default value of SENSOR_DELAY_NORMAL for simple screen orientation change detection.

Public methods

canDetectOrientation

Added in API level 3
open fun canDetectOrientation(): Boolean

disable

Added in API level 3
open fun disable(): Unit

Disables the OrientationEventListener.

enable

Added in API level 3
open fun enable(): Unit

Enables the OrientationEventListener so it will monitor the sensor and call onOrientationChanged when the device orientation changes.

onOrientationChanged

Added in API level 3
abstract fun onOrientationChanged(orientation: Int): Unit

Called when the orientation of the device has changed. orientation parameter is in degrees, ranging from 0 to 359. orientation is 0 degrees when the device is oriented in its natural position, 90 degrees when its left side is at the top, 180 degrees when it is upside down, and 270 degrees when its right side is to the top. ORIENTATION_UNKNOWN is returned when the device is close to flat and the orientation cannot be determined.

Parameters
orientation Int: The new orientation of the device.