J'ai un projet Jar simple référence par application android. Ensuite, j'ai Functions.java pour mes fonctions communes que je veux créer la classe de test unitaire.Android: Test unitaire: Comment créer un test unitaire avec SensorManager?
Voici les exemples de fonctions à l'intérieur du Functions.java:
public static double getAltitudeBySensor(float atmosphericPressure) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD
&& atmosphericPressure > 0d) {
return SensorManager.getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, atmosphericPressure);
}
return 0d;
}
public static double toPixelX(double imageSize, android.location.Location upperLeft, android.location.Location lowerRight, android.location.Location target) {
double hypotenuse = upperLeft.distanceTo(target);
double bearing = upperLeft.bearingTo(target);
double currentDistanceX = Math.sin(bearing * Math.PI/OneEightyDeg) * hypotenuse;
// "percentage to mark the position"
double totalHypotenuse = upperLeft.distanceTo(lowerRight);
double totalDistanceX = totalHypotenuse * Math.sin(upperLeft.bearingTo(lowerRight) * Math.PI/OneEightyDeg);
double currentPixelX = currentDistanceX/totalDistanceX * imageSize;
return currentPixelX;
}
Toute orientation sur la bonne direction est appréciée.