1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view;
18
19import android.content.Context;
20import android.hardware.SensorListener;
21
22/**
23 * Helper class for receiving notifications from the SensorManager when
24 * the orientation of the device has changed.
25 *  @deprecated use {@link android.view.OrientationEventListener} instead.
26 *  This class internally uses the OrientationEventListener.
27 */
28@Deprecated
29public abstract class OrientationListener implements SensorListener {
30    private OrientationEventListener mOrientationEventLis;
31
32    /**
33     * Returned from onOrientationChanged when the device orientation cannot be determined
34     * (typically when the device is in a close to flat position).
35     *
36     *  @see #onOrientationChanged
37     */
38    public static final int ORIENTATION_UNKNOWN = OrientationEventListener.ORIENTATION_UNKNOWN;
39
40    /**
41     * Creates a new OrientationListener.
42     *
43     * @param context for the OrientationListener.
44     */
45    public OrientationListener(Context context) {
46        mOrientationEventLis = new OrientationEventListenerInternal(context);
47    }
48
49    /**
50     * Creates a new OrientationListener.
51     *
52     * @param context for the OrientationListener.
53     * @param rate at which sensor events are processed (see also
54     * {@link android.hardware.SensorManager SensorManager}). Use the default
55     * value of {@link android.hardware.SensorManager#SENSOR_DELAY_NORMAL
56     * SENSOR_DELAY_NORMAL} for simple screen orientation change detection.
57     */
58    public OrientationListener(Context context, int rate) {
59        mOrientationEventLis = new OrientationEventListenerInternal(context, rate);
60    }
61
62    class OrientationEventListenerInternal extends OrientationEventListener {
63        OrientationEventListenerInternal(Context context) {
64            super(context);
65        }
66
67        OrientationEventListenerInternal(Context context, int rate) {
68            super(context, rate);
69            // register so that onSensorChanged gets invoked
70            registerListener(OrientationListener.this);
71        }
72
73        public void onOrientationChanged(int orientation) {
74            OrientationListener.this.onOrientationChanged(orientation);
75        }
76    }
77
78    /**
79     * Enables the OrientationListener so it will monitor the sensor and call
80     * {@link #onOrientationChanged} when the device orientation changes.
81     */
82    public void enable() {
83        mOrientationEventLis.enable();
84    }
85
86    /**
87     * Disables the OrientationListener.
88     */
89    public void disable() {
90        mOrientationEventLis.disable();
91    }
92
93    public void onAccuracyChanged(int sensor, int accuracy) {
94    }
95
96    public void onSensorChanged(int sensor, float[] values) {
97        // just ignore the call here onOrientationChanged is invoked anyway
98    }
99
100
101    /**
102     * Look at {@link android.view.OrientationEventListener#onOrientationChanged}
103     * for method description and usage
104     * @param orientation The new orientation of the device.
105     *
106     *  @see #ORIENTATION_UNKNOWN
107     */
108    abstract public void onOrientationChanged(int orientation);
109
110}
111