OrientationEventListenerpublic abstract class OrientationEventListener extends Object Helper class for receiving notifications from the SensorManager when
the orientation of the device has changed. |
Fields Summary |
---|
private static final String | TAG | private static final boolean | DEBUG | private static final boolean | localLOGV | private int | mOrientation | private android.hardware.SensorManager | mSensorManager | private boolean | mEnabled | private int | mRate | private android.hardware.Sensor | mSensor | private android.hardware.SensorEventListener | mSensorEventListener | private OrientationListener | mOldListener | public static final int | ORIENTATION_UNKNOWNReturned from onOrientationChanged when the device orientation cannot be determined
(typically when the device is in a close to flat position). |
Constructors Summary |
---|
public OrientationEventListener(android.content.Context context)Creates a new OrientationEventListener.
this(context, SensorManager.SENSOR_DELAY_NORMAL);
| public OrientationEventListener(android.content.Context context, int rate)Creates a new OrientationEventListener.
mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
mRate = rate;
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
if (mSensor != null) {
// Create listener only if sensors do exist
mSensorEventListener = new SensorEventListenerImpl();
}
|
Methods Summary |
---|
public boolean | canDetectOrientation()
return mSensor != null;
| public void | disable()Disables the OrientationEventListener.
if (mSensor == null) {
Log.w(TAG, "Cannot detect sensors. Invalid disable");
return;
}
if (mEnabled == true) {
if (localLOGV) Log.d(TAG, "OrientationEventListener disabled");
mSensorManager.unregisterListener(mSensorEventListener);
mEnabled = false;
}
| public void | enable()Enables the OrientationEventListener so it will monitor the sensor and call
{@link #onOrientationChanged} when the device orientation changes.
if (mSensor == null) {
Log.w(TAG, "Cannot detect sensors. Not enabled");
return;
}
if (mEnabled == false) {
if (localLOGV) Log.d(TAG, "OrientationEventListener enabled");
mSensorManager.registerListener(mSensorEventListener, mSensor, mRate);
mEnabled = true;
}
| public abstract void | onOrientationChanged(int orientation)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.
{@link #ORIENTATION_UNKNOWN} is returned when the device is close to flat
and the orientation cannot be determined.
| void | registerListener(OrientationListener lis)
mOldListener = lis;
|
|