It is a possibly dumb question, probability my Java is just rudimentary :-( but I do not understand why this works (it is actually Android code, but I think this as a general Java question).
I do not understand how is it possible that the object mySensorEventListener
is actually created???
- I do not understand what does this code below actually do.
- How does this code get called???
- When is it called???
THIS IS THE PART I DO NOT UNDERSTAND
public SensorListener mySensorEventListener = new SensorListener() {
@Override
public void onSensorChanged(int sensor, float[] values) {
synchronized (this) {
}
}
@Override
public void onAccuracyChanged(int sensor, int accuracy) {
}
};
And this is the android Activity it belongs to:
public class RouteMapActivity extends Activity implements IRegisterReceiver {
private SensorManager mSensorManager;
private MapView mapView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapView = new MapView(this, provider.getTileSource()
.getTileSizePixels(), resProxy, provider);
mSensorManager=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
mSensorManager.registerListener(mySensorEventListener,
SensorManager.SENSOR_ORIENTATION,
SensorManager.SENSOR_DELAY_FASTEST);
setContentView(mapView);
}
public SensorListener mySensorEventListener = new SensorListener() {
@Override
public void onSensorChanged(int sensor, float[] values) {
synchronized (this) {
float mHeading = values[0];
mapView.setMapOrientation(-mHeading);
}
}
@Override
public void onAccuracyChanged(int sensor, int accuracy) {
}
};