From 2ed859944ee9642d002de7623358a25a86ea5da8 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 1 Jul 2014 16:06:12 +0200 Subject: [PATCH] #commit --- AndroidManifest.xml | 5 ++-- res/menu/main.xml | 10 +++---- res/values/strings.xml | 5 +++- src/fr/projetcookie/boussole/DataManager.java | 27 ++++++++++--------- .../projetcookie/boussole/MainActivity.java | 20 +++++++++++++- 5 files changed, 45 insertions(+), 22 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b8949d1..baccd64 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -5,8 +5,8 @@ android:versionName="1.0" > + android:minSdkVersion="8" + android:targetSdkVersion="20" /> @@ -26,6 +26,7 @@ android:value="@integer/google_play_services_version" /> diff --git a/res/menu/main.xml b/res/menu/main.xml index 1cf12a7..ab28f20 100644 --- a/res/menu/main.xml +++ b/res/menu/main.xml @@ -1,14 +1,14 @@ - + - + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 25d31a5..e922ed5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,7 +1,7 @@ - Cookie - Boussole + Cookie Paramètres Localisation Open drawer @@ -16,6 +16,9 @@ Distance: Latitude: Longitude: + Précision: + Carte + Boussole \ No newline at end of file diff --git a/src/fr/projetcookie/boussole/DataManager.java b/src/fr/projetcookie/boussole/DataManager.java index 5938094..a95ed4d 100644 --- a/src/fr/projetcookie/boussole/DataManager.java +++ b/src/fr/projetcookie/boussole/DataManager.java @@ -37,6 +37,7 @@ public class DataManager implements SensorEventListener, LocationListener{ private double lat; private String serverUri; private double lon; + private GeomagneticField geoField; public DataManager(Context context, DirectionUpdateListener listener) { mContext = context; @@ -60,8 +61,8 @@ public void start() { Toast.makeText(mContext, "Getting data from settings", Toast.LENGTH_SHORT).show(); } mProvider.start(); - sensorManager.registerListener(this, gsensor, SensorManager.SENSOR_DELAY_GAME); - sensorManager.registerListener(this, msensor, SensorManager.SENSOR_DELAY_GAME); + sensorManager.registerListener(this, gsensor, SensorManager.SENSOR_DELAY_NORMAL); + sensorManager.registerListener(this, msensor, SensorManager.SENSOR_DELAY_NORMAL); } public void stop() { @@ -132,21 +133,21 @@ public void onSensorChanged(SensorEvent event) { public void onLocationChanged(Location location) { positionUpdated=true; mLastLocation=location; + + geoField = new GeomagneticField( + (float) mLastLocation.getLatitude(), + (float) mLastLocation.getLongitude(), + (float) mLastLocation.getAltitude(), + System.currentTimeMillis()); + updateDirection(); } - private void updateDirection() { - float azimuth = direction; - Location currentLoc = mLastLocation; - GeomagneticField geoField = new GeomagneticField( - (float) currentLoc.getLatitude(), - (float) currentLoc.getLongitude(), - (float) currentLoc.getAltitude(), - System.currentTimeMillis()); - azimuth += geoField.getDeclination(); - float bearing = currentLoc.bearingTo(mProvider.getLocation()); + private void updateDirection() { + direction += geoField.getDeclination(); + float bearing = mLastLocation.bearingTo(mProvider.getLocation()); - mListener.onDirectionUpdate(azimuth - bearing); + mListener.onDirectionUpdate(direction - bearing); } } diff --git a/src/fr/projetcookie/boussole/MainActivity.java b/src/fr/projetcookie/boussole/MainActivity.java index 2c827bf..9851171 100644 --- a/src/fr/projetcookie/boussole/MainActivity.java +++ b/src/fr/projetcookie/boussole/MainActivity.java @@ -86,6 +86,7 @@ public class MainActivity extends ActionBarActivity implements private String mDistanceText; private String mLatitudeText; private String mLongitudeText; + private String mPrecisionText; private ArrayAdapter dataAdapter; private ArrayList mDataString = new ArrayList(); @@ -116,11 +117,13 @@ protected void onCreate(Bundle savedInstanceState) { mDistanceText = mDataTitles[1] + " N/A"; mLatitudeText = mDataTitles[2] + " N/A"; mLongitudeText = mDataTitles[3] + " N/A"; + mPrecisionText = mDataTitles[4] + " N/A"; mDataString.add(mAltitudeText); mDataString.add(mDistanceText); mDataString.add(mLatitudeText); mDataString.add(mLongitudeText); + mDataString.add(mPrecisionText); dataAdapter = new ArrayAdapter(this, R.layout.drawer_list_item, mDataString); @@ -214,12 +217,17 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.action_enable_gps: startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); return true; + case R.id.action_boussole: + selectItem(1); + return true; + case R.id.action_map: + selectItem(2); + return true; default: return super.onOptionsItemSelected(item); } } - /* The click listner for ListView in the navigation drawer */ private class DrawerItemClickListener implements ListView.OnItemClickListener { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { @@ -493,6 +501,7 @@ public void onDirectionUpdate(float dir) { double distance = baloonLoc.distanceTo(mDataManager.mLastLocation); // 7 double lat = baloonLoc.getLatitude(); // 8 double lon = baloonLoc.getLongitude(); // 9 + double prec = baloonLoc.getAccuracy(); if(h > 800) mAltitudeText = mDataTitles[0] + " " + Math.round(h/10)/100f + " km"; @@ -506,6 +515,12 @@ public void onDirectionUpdate(float dir) { mLatitudeText = mDataTitles[2] + " " + Math.round(lat*1000)/1000f + "°"; mLongitudeText = mDataTitles[3] + " " + Math.round(lon*1000)/1000f + "°"; + + if(prec > 800) + mPrecisionText = mDataTitles[4] + " " + Math.round(prec/10)/100f + " km"; + else + mPrecisionText = mDataTitles[4] + " " + Math.round(prec) + " m"; + dataAdapter.clear(); dataAdapter.add(mAltitudeText); @@ -513,6 +528,9 @@ public void onDirectionUpdate(float dir) { dataAdapter.add(mLatitudeText); dataAdapter.add(mLongitudeText); + if(prec != 0) + dataAdapter.add(mPrecisionText); + dataAdapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();