請(qǐng)問(wèn)一下老師這些代碼是什么意思呢
private OnOrientationListener mOnOrientationListener;
public void setOnOrientationListener(OnOrientationListener mOnOrientationListener) {
this.mOnOrientationListener = mOnOrientationListener;
}
public interface OnOrientationListener {
void onOrientationChanged(float x);//float x = event.values[SensorManager.DATA_X];
}
public void onSensorChanged(SensorEvent event) {//方向發(fā)生變化
// TODO Auto-generated method stub
if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) {//事件返回類(lèi)型是方向傳感器
// 這里我們可以得到數(shù)據(jù),然后根據(jù)需要來(lái)處理 ?
float x = event.values[SensorManager.DATA_X];
if ((Math.abs(x - lastX)) > 1.0) {
if (mOnOrientationListener != null) {
//不為空進(jìn)行回調(diào)
mOnOrientationListener.onOrientationChanged(x);
}
}
lastX = x;
}
}
2016-07-21
提供了一個(gè)接口,當(dāng)坐標(biāo)發(fā)生改變相差大于1的時(shí)候,坐標(biāo)數(shù)據(jù)才發(fā)生變化