======================
LOOK! LICENSING TERMS
======================
look! is licensed under the BSD 3-Clause (also known as "BSD New" or
"BSD Simplified"), as follows:
Copyright (c) 2010-2012, Look...
If you think the Android project Look listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/**
*-----------------------------------------------------------------------------
* Copyright (c) 2012, Look! Development Team
* All rights reserved.//www.java2s.com
*
* Distributed under the terms of the BSD Simplified License.
*
* The full license is in the LICENSE file, distributed with this software.
*-----------------------------------------------------------------------------
*/package es.ucm.look.locationProvider;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
/**
* Adapter of the INS to the Look! framework
*
* @author Jorge Creixell Rojo
* Based on Indoor Navigation System for Handheld Devices
* by Manh Hung V. Le, Dimitris Saragas, Nathan Webb
*
*/publicclass LocationProvider implements SensorEventListener, Runnable {
/**
* Application context.
*/privatestatic Context CONTEXT;
/**
* Android Sensor Manager.
*/private SensorManager mSensorManager;
/**
* Contructor. Initializes the INS and registers listeners.
*
* @param context
* Application context.
*/public LocationProvider(Context context) {
LocationProvider.CONTEXT = context;
Positioning.initialize();
mSensorManager = (SensorManager) CONTEXT
.getSystemService(Context.SENSOR_SERVICE);
Positioning.startPositioning();
Positioning.resetINS();
Sensor asensor = mSensorManager
.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
Sensor msensor = mSensorManager
.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
Sensor osensor = mSensorManager
.getDefaultSensor(Sensor.TYPE_ORIENTATION);
mSensorManager.registerListener(this, asensor,
SensorManager.SENSOR_DELAY_FASTEST);
mSensorManager.registerListener(this, msensor,
SensorManager.SENSOR_DELAY_FASTEST);
mSensorManager.registerListener(this, osensor,
SensorManager.SENSOR_DELAY_FASTEST);
}
/**
* Add new motion sample to the queue
*
* @return current context.
*/publicstatic Context getContext() {
return CONTEXT;
}
@Override
publicvoid onAccuracyChanged(Sensor arg0, int arg1) {
}
@Override
publicvoid onSensorChanged(SensorEvent event) {
int type = event.sensor.getType();
float[] data = Util.copyArray(event.values);
if (type == Sensor.TYPE_ACCELEROMETER) {
DeviceSensor.setDevA(data);
Positioning.updateINS();
} elseif (type == Sensor.TYPE_MAGNETIC_FIELD) {
DeviceSensor.setDevM(data);
DeviceSensor.toEarthCS();
} elseif (type == Sensor.TYPE_ORIENTATION) {
DeviceSensor.setDevO(data);
}
}
/**
* Recalculates distance moved
*/
@Override
publicvoid run() {
Positioning.process();
}
publicvoid resetINS() {
Positioning.resetINS();
}
/**
* Returns position in map coordinates.
*
* @return Position in map coordinates
*/publicstaticfloat[] getMapPosition() {
return Positioning.mapPosition();
}
/**
* Returns raw position
*
* @return Position in world coordinates
*/publicstaticfloat[] getPosition() {
return Positioning.position();
}
/**
* Returns relative displacement.
*
* @return relative displacement
*/publicstaticfloat[] getDisplacement() {
return Positioning.displacement();
}
/**
* Returns whether the device is moving or not.
*
* @return whether the device is moving or not
*/publicstaticboolean isMoving() {
return Positioning.isMoving();
}
}