altosdroid: Display direction in map view
authorKeith Packard <keithp@keithp.com>
Wed, 24 Jun 2015 19:02:22 +0000 (12:02 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 24 Jun 2015 19:02:22 +0000 (12:02 -0700)
Use direction in map view when available, otherwise use bearing

Signed-off-by: Keith Packard <keithp@keithp.com>
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java

index db7815f..b87b51b 100644 (file)
@@ -998,6 +998,12 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
 
        static String direction(AltosGreatCircle from_receiver,
                             Location receiver) {
+               if (from_receiver == null)
+                       return null;
+
+               if (receiver == null)
+                       return null;
+
                if (!receiver.hasBearing())
                        return null;
 
@@ -1016,8 +1022,8 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                else if (iheading < -179 || 179 < iheading)
                        return "backwards";
                else if (iheading < 0)
-                       return String.format("left %d", -iheading);
+                       return String.format("left %d°", -iheading);
                else
-                       return String.format("right %d", iheading);
+                       return String.format("right %d°", iheading);
        }
 }
index 0ee202a..81b6fe5 100644 (file)
@@ -37,6 +37,7 @@ public class TabMap extends AltosDroidTab {
        AltosLatLon     here;
 
        private TextView mDistanceView;
+       private TextView mBearingLabel;
        private TextView mBearingView;
        private TextView mTargetLatitudeView;
        private TextView mTargetLongitudeView;
@@ -63,6 +64,7 @@ public class TabMap extends AltosDroidTab {
                int map_source = AltosDroidPreferences.map_source();
 
                mDistanceView  = (TextView)view.findViewById(R.id.distance_value);
+               mBearingLabel  = (TextView)view.findViewById(R.id.bearing_label);
                mBearingView   = (TextView)view.findViewById(R.id.bearing_value);
                mTargetLatitudeView  = (TextView)view.findViewById(R.id.target_lat_value);
                mTargetLongitudeView = (TextView)view.findViewById(R.id.target_lon_value);
@@ -99,8 +101,19 @@ public class TabMap extends AltosDroidTab {
 
        public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
                if (from_receiver != null) {
-                       mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
+                       String  direction = AltosDroid.direction(from_receiver, receiver);
+                       if (direction != null) {
+                               mBearingLabel.setText("Direction");
+                               mBearingView.setText(direction);
+                       } else {
+                               mBearingLabel.setText("Bearing");
+                               mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
+                       }
                        set_value(mDistanceView, AltosConvert.distance, 6, from_receiver.distance);
+               } else {
+                       mBearingLabel.setText("Bearing");
+                       mBearingView.setText("");
+                       set_value(mDistanceView, AltosConvert.distance, 6, AltosLib.MISSING);
                }
 
                if (state != null) {