altosdroid: Show direction to target in recover tab
authorKeith Packard <keithp@keithp.com>
Wed, 24 Jun 2015 04:35:43 +0000 (21:35 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 24 Jun 2015 04:42:35 +0000 (21:42 -0700)
This takes the bearing to target and current direction of motion (from
the Android API) and computes a turn amount and displays that so you
don't have to know which way is north when walking towards the rocket.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosdroid/res/layout/tab_recover.xml
altosdroid/res/values/strings.xml
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
altosdroid/src/org/altusmetrum/AltosDroid/TabRecover.java

index f27baa9e7b87477b2ec6235757b28a2de61bbd84..c2806629e5b8fbe06c2c0caa44ec5db11733398b 100644 (file)
                        android:textAppearance="?android:attr/textAppearanceSmall" />
        </RelativeLayout>
 
+       <RelativeLayout
+               android:layout_width="wrap_content"
+               android:layout_height="wrap_content" >
+
+               <TextView
+                       android:id="@+id/direction_label"
+                       android:layout_width="wrap_content"
+                       android:layout_height="wrap_content"
+                       android:text="@string/direction_label" />
+
+               <TextView
+                       android:id="@+id/direction_value"
+                       android:layout_width="wrap_content"
+                       android:layout_height="wrap_content"
+                       android:layout_alignParentRight="true"
+                       android:layout_below="@+id/direction_label"
+                       android:text=""
+                       android:textAppearance="?android:attr/textAppearanceSmall" />
+       </RelativeLayout>
+
        <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall" />
        </RelativeLayout>
 
-</LinearLayout>
\ No newline at end of file
+</LinearLayout>
index 5a9d96299d74a6df2f095d34716748b35d4d02d5..8c299a35e98bc37ac7ee9f5cc272ad22cc6f27cf 100644 (file)
@@ -69,6 +69,7 @@
        <string name="speed_label">Speed</string>
        <string name="accel_label">Acceleration</string>
        <string name="bearing_label">Bearing</string>
+       <string name="direction_label">Direction</string>
        <string name="elevation_label">Elevation</string>
        <string name="range_label">Range</string>
        <string name="distance_label">Distance</string>
index 6cd9463afbc056f39e7cde3561134a943bd75933..f1da27d8a8ab6908fb61b0a15d93729e5702e823 100644 (file)
@@ -990,4 +990,29 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                }
                return false;
        }
+
+       static String direction(AltosGreatCircle from_receiver,
+                            Location receiver) {
+               if (!receiver.hasBearing())
+                       return null;
+
+               float   bearing = receiver.getBearing();
+               float   heading = (float) from_receiver.bearing - bearing;
+
+               while (heading <= -180.0f)
+                       heading += 360.0f;
+               while (heading > 180.0f)
+                       heading -= 360.0f;
+
+               int iheading = (int) (heading + 0.5f);
+
+               if (-1 < iheading && iheading < 1)
+                       return "ahead";
+               else if (iheading < -179 || 179 < iheading)
+                       return "backwards";
+               else if (iheading < 0)
+                       return String.format("left %d", -iheading);
+               else
+                       return String.format("right %d", iheading);
+       }
 }
index 0ab20f5f6c8f9890f3e09fe65cde17cf5a502522..cb394dbe904ec08f57631783391fadcc21efa337 100644 (file)
@@ -30,6 +30,7 @@ import android.location.Location;
 
 public class TabRecover extends AltosDroidTab {
        private TextView mBearingView;
+       private TextView mDirectionView;
        private TextView mDistanceView;
        private TextView mTargetLatitudeView;
        private TextView mTargetLongitudeView;
@@ -44,6 +45,7 @@ public class TabRecover extends AltosDroidTab {
                View v = inflater.inflate(R.layout.tab_recover, container, false);
 
                mBearingView   = (TextView) v.findViewById(R.id.bearing_value);
+               mDirectionView = (TextView) v.findViewById(R.id.direction_value);
                mDistanceView  = (TextView) v.findViewById(R.id.distance_value);
                mTargetLatitudeView  = (TextView) v.findViewById(R.id.target_lat_value);
                mTargetLongitudeView = (TextView) v.findViewById(R.id.target_lon_value);
@@ -62,6 +64,11 @@ public class TabRecover extends AltosDroidTab {
                if (from_receiver != null) {
                        mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
                        set_value(mDistanceView, AltosConvert.distance, 6, from_receiver.distance);
+                       String direction = AltosDroid.direction(from_receiver, receiver);
+                       if (direction == null)
+                               mDirectionView.setText("");
+                       else
+                               mDirectionView.setText(direction);
                }
                if (state != null && state.gps != null) {
                        mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));