Skip to content

Commit

Permalink
#commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLortex committed Jul 1, 2014
1 parent 62b5979 commit 2ed8599
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
5 changes: 3 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
Expand All @@ -26,6 +26,7 @@
android:value="@integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
10 changes: 5 additions & 5 deletions res/menu/main.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
<item android:id="@+id/action_boussole" android:title="@string/action_boussole" android:showAsAction="always"></item><item android:id="@+id/action_map" android:title="@string/action_map" android:showAsAction="always"></item><item android:id="@+id/action_settings" android:showAsAction="always" android:title="@string/action_settings" >
</item><item
android:id="@+id/action_enable_gps"
android:showAsAction="always"
android:icon="@drawable/ic_menu_mylocation"
android:title="@string/action_enable_gps"/>

<item
android:id="@+id/action_settings"
android:showAsAction="always"
android:title="@string/action_settings"/>




</menu>
5 changes: 4 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Cookie - Boussole</string>
<string name="app_name">Cookie</string>
<string name="action_settings">Paramètres</string>
<string name="action_enable_gps">Localisation</string>
<string name="drawer_open">Open drawer</string>
Expand All @@ -16,6 +16,9 @@
<item >Distance:</item>
<item >Latitude:</item>
<item >Longitude:</item>
<item >Précision: </item>
</string-array>
<string name="action_map">Carte</string>
<string name="action_boussole">Boussole</string>

</resources>
27 changes: 14 additions & 13 deletions src/fr/projetcookie/boussole/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
}
20 changes: 19 additions & 1 deletion src/fr/projetcookie/boussole/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class MainActivity extends ActionBarActivity implements
private String mDistanceText;
private String mLatitudeText;
private String mLongitudeText;
private String mPrecisionText;

private ArrayAdapter<String> dataAdapter;
private ArrayList<String> mDataString = new ArrayList<String>();
Expand Down Expand Up @@ -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<String>(this,
R.layout.drawer_list_item, mDataString);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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";
Expand All @@ -506,13 +515,22 @@ 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);
dataAdapter.add(mDistanceText);
dataAdapter.add(mLatitudeText);
dataAdapter.add(mLongitudeText);

if(prec != 0)
dataAdapter.add(mPrecisionText);

dataAdapter.notifyDataSetChanged();
adapter.notifyDataSetChanged();

Expand Down

0 comments on commit 2ed8599

Please sign in to comment.