Most visited

Recently visited

Added in API level 1
Deprecated since API level 3

OrientationListener

public abstract class OrientationListener
extends Object implements SensorListener

java.lang.Object
    android.view.OrientationListener


此类在API级别3中已弃用。
改为使用OrientationEventListener 。 这个类在内部使用OrientationEventListener。

Helper类用于在设备的方向发生更改时从SensorManager接收通知。

摘要(Summary)

常量(Constants)

int ORIENTATION_UNKNOWN

从onOrientation返回当设备方向无法确定时(通常设备处于接近平坦位置时)更改。

Public constructors

OrientationListener(Context context)

创建一个新的OrientationListener。

OrientationListener(Context context, int rate)

创建一个新的OrientationListener。

公共方法(Public methods)

void disable()

禁用OrientationListener。

void enable()

启用OrientationListener,以便监视传感器,并在设备方向更改时调用 onOrientationChanged(int) 。

void onAccuracyChanged(int sensor, int accuracy)

当传感器的准确度发生变化时调用。

abstract void onOrientationChanged(int orientation)

请查看 onOrientationChanged(int)了解方法描述和用法

void onSensorChanged(int sensor, float[] values)

传感器值发生变化时调用。

继承方法(Inherited methods)

From class java.lang.Object
From interface android.hardware.SensorListener

常量(Constants)

ORIENTATION_UNKNOWN

Added in API level 1
int ORIENTATION_UNKNOWN

从onOrientation返回当设备方向无法确定时(通常设备处于接近平坦位置时)更改。

也可以看看:

常量值:-1(0xffffffff)

Public constructors

OrientationListener

Added in API level 1
OrientationListener (Context context)

创建一个新的OrientationListener。

参数(Parameters)
context Context: for the OrientationListener.

OrientationListener

Added in API level 3
OrientationListener (Context context, 
                int rate)

创建一个新的OrientationListener。

参数(Parameters)
context Context: for the OrientationListener.
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)

disable

Added in API level 1
void disable ()

禁用OrientationListener。

enable

Added in API level 1
void enable ()

启用OrientationListener,以便监视传感器,并在设备方向更改时调用 onOrientationChanged(int) 。

onAccuracyChanged

Added in API level 1
void onAccuracyChanged (int sensor, 
                int accuracy)

当传感器的准确度发生变化时调用。 详情请参阅SensorManager 。

参数(Parameters)
sensor int: The ID of the sensor being monitored
accuracy int: The new accuracy of this sensor.

onOrientationChanged

Added in API level 1
void onOrientationChanged (int orientation)

查看方法描述和用法,查看 onOrientationChanged(int)

参数(Parameters)
orientation int: The new orientation of the device.

也可以看看:

onSensorChanged

Added in API level 1
void onSensorChanged (int sensor, 
                float[] values)

传感器值发生变化时调用。 值数组的长度和内容因所监视的传感器而异。 有关可能的传感器类型的详细信息,请参阅SensorManager 。

下面使用的坐标系的定义。

X轴指屏幕的水平轴(纵向模式下的小边,横向模式下的长边)并指向右侧。

Y轴指的是屏幕的垂直轴,并指向屏幕的顶部(原点位于左下角)。

当设备躺在桌子上时,Z轴指向天空。

重要提示:当设备的屏幕方向改变时,该轴被交换 。 要访问未打开的值,请在值[]中使用索引3,4和5。

SENSOR_ORIENTATION , SENSOR_ORIENTATION_RAW :

所有值都是以度为单位的角度。

值[0]:方位角,绕Z轴旋转(0 <=方位角<360)。 0 =北,90 =东,180 =南,270 =西

值[1]:俯仰,围绕X轴的旋转(-180 <= pitch <= 180),当z轴朝向y轴移动时为正值。

值[2]:滚动,围绕Y轴旋转(-90 <=滚动<= 90),当z轴向x轴移动时为正值。

请注意,偏航,俯仰和滚转的定义与X轴沿飞机长边(尾部到鼻部)的航空中使用的传统定义不同。

SENSOR_ACCELEROMETER :

所有数值均以SI单位(m / s ^ 2)表示并测量接触力。

值[0]:设备在x轴上施加的力

值[1]:设备在y轴上施加的力

值[2]:设备在z轴上施加的力

例子 :

  • When the device is pushed on its left side toward the right, the x acceleration value is negative (the device applies a reaction force to the push toward the left)
  • When the device lies flat on a table, the acceleration value is -STANDARD_GRAVITY, which correspond to the force the device applies on the table in reaction to gravity.
  • SENSOR_MAGNETIC_FIELD :

    所有数值均以微特斯拉(uT)为单位,并测量X,Y和-Z轴的环境磁场。

    注意:磁场的Z轴是倒置的。

    参数(Parameters)
    sensor int: The ID of the sensor being monitored
    values float: The new values for the sensor.

    Hooray!