WindowOrientationListenerpublic abstract class WindowOrientationListener extends Object A special helper class used by the WindowManager
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 android.hardware.SensorManager | mSensorManager | private boolean | mEnabled | private int | mRate | private android.hardware.Sensor | mSensor | private android.hardware.SensorEventListener | mSensorEventListener | private int | mSensorRotation |
Constructors Summary |
---|
public WindowOrientationListener(android.content.Context context)Creates a new WindowOrientationListener.
this(context, SensorManager.SENSOR_DELAY_NORMAL);
| public WindowOrientationListener(android.content.Context context, int rate)Creates a new WindowOrientationListener.
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 WindowOrientationListener.
if (mSensor == null) {
Log.w(TAG, "Cannot detect sensors. Invalid disable");
return;
}
if (mEnabled == true) {
if (localLOGV) Log.d(TAG, "WindowOrientationListener disabled");
mSensorRotation = -1;
mSensorManager.unregisterListener(mSensorEventListener);
mEnabled = false;
}
| public void | enable()Enables the WindowOrientationListener 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, "WindowOrientationListener enabled");
mSensorRotation = -1;
mSensorManager.registerListener(mSensorEventListener, mSensor, mRate);
mEnabled = true;
}
| public int | getCurrentRotation()
return mSensorRotation;
| public abstract void | onOrientationChanged(int rotation)Called when the rotation view of the device has changed.
Can be either Surface.ROTATION_90 or Surface.ROTATION_0.
|
|