FileDocCategorySizeDatePackage
WindowOrientationListener.javaAPI DocAndroid 1.5 API9541Wed May 06 22:41:56 BST 2009android.view

WindowOrientationListener

public 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.
hide

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.

param
context for the WindowOrientationListener.


                   
       
        this(context, SensorManager.SENSOR_DELAY_NORMAL);
    
public WindowOrientationListener(android.content.Context context, int rate)
Creates a new WindowOrientationListener.

param
context for the WindowOrientationListener.
param
rate at which sensor events are processed (see also {@link android.hardware.SensorManager SensorManager}). Use the default value of {@link android.hardware.SensorManager#SENSOR_DELAY_NORMAL SENSOR_DELAY_NORMAL} for simple screen orientation change detection.

        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 booleancanDetectOrientation()

        return mSensor != null;
    
public voiddisable()
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 voidenable()
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 intgetCurrentRotation()

        return mSensorRotation;
    
public abstract voidonOrientationChanged(int rotation)
Called when the rotation view of the device has changed. Can be either Surface.ROTATION_90 or Surface.ROTATION_0.

param
rotation The new orientation of the device.
see
#ORIENTATION_UNKNOWN