altosdroid: Update UI even if no telem has been received. Center map.
authorKeith Packard <keithp@keithp.com>
Sat, 13 Apr 2013 19:13:18 +0000 (12:13 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 13 Apr 2013 19:13:18 +0000 (12:13 -0700)
This allows the receiver location to be displayed even when telemetry
is not.

Center the map on the first valid location, either receiver or
rocket. Update center if a significantly more precise location is received.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosdroid/res/layout/tab_landed.xml
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java
altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java
altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java
altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java
altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java

index 9008700f65ce8dbac6c4133f7b55e59c7f2ee726..f27baa9e7b87477b2ec6235757b28a2de61bbd84 100644 (file)
                android:paddingTop="5dp" >
 
                <TextView
-                       android:id="@+id/lat_label"
+                       android:id="@+id/target_lat_label"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
-                       android:text="@string/latitude_label" />
+                       android:text="@string/target_latitude_label" />
 
                <TextView
-                       android:id="@+id/lat_value"
+                       android:id="@+id/target_lat_value"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
-                       android:layout_below="@id/lat_label"
+                       android:layout_below="@id/target_lat_label"
                        android:text=""
                        android:textAppearance="?android:attr/textAppearanceSmall" />
        </RelativeLayout>
                android:paddingTop="5dp" >
 
                <TextView
-                       android:id="@+id/lon_label"
+                       android:id="@+id/target_lon_label"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
-                       android:text="@string/longitude_label" />
+                       android:text="@string/target_longitude_label" />
 
                <TextView
-                       android:id="@+id/lon_value"
+                       android:id="@+id/target_lon_value"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
-                       android:layout_below="@id/lon_label"
+                       android:layout_below="@id/target_lon_label"
+                       android:text=""
+                       android:textAppearance="?android:attr/textAppearanceSmall" />
+       </RelativeLayout>
+
+       <RelativeLayout
+               android:layout_width="wrap_content"
+               android:layout_height="wrap_content"
+               android:paddingTop="5dp" >
+
+               <TextView
+                       android:id="@+id/receiver_lat_label"
+                       android:layout_width="wrap_content"
+                       android:layout_height="wrap_content"
+                       android:text="@string/receiver_latitude_label" />
+
+               <TextView
+                       android:id="@+id/receiver_lat_value"
+                       android:layout_width="wrap_content"
+                       android:layout_height="wrap_content"
+                       android:layout_alignParentRight="true"
+                       android:layout_below="@id/receiver_lat_label"
+                       android:text=""
+                       android:textAppearance="?android:attr/textAppearanceSmall" />
+       </RelativeLayout>
+
+       <RelativeLayout
+               android:layout_width="wrap_content"
+               android:layout_height="wrap_content"
+               android:paddingTop="5dp" >
+
+               <TextView
+                       android:id="@+id/receiver_lon_label"
+                       android:layout_width="wrap_content"
+                       android:layout_height="wrap_content"
+                       android:text="@string/receiver_longitude_label" />
+
+               <TextView
+                       android:id="@+id/receiver_lon_value"
+                       android:layout_width="wrap_content"
+                       android:layout_height="wrap_content"
+                       android:layout_alignParentRight="true"
+                       android:layout_below="@id/receiver_lon_label"
                        android:text=""
                        android:textAppearance="?android:attr/textAppearanceSmall" />
        </RelativeLayout>
index 93af2fdcd6ac69d0e56530d2ef6ac877bd728cca..5ce6f81069eae5bb7222f9d4c447ce211d8b28e1 100644 (file)
@@ -205,13 +205,11 @@ public class AltosDroid extends FragmentActivity {
 
        void set_location(Location location) {
                saved_location = location;
-               if (saved_state != null) {
-                       update_ui(saved_state);
-               }
+               update_ui(saved_state);
        }
 
        void update_ui(AltosState state) {
-               if (saved_state != null) {
+               if (state != null && saved_state != null) {
                        if (saved_state.state != state.state) {
                                String currentTab = mTabHost.getCurrentTabTag();
                                switch (state.state) {
@@ -231,7 +229,7 @@ public class AltosDroid extends FragmentActivity {
 
                AltosGreatCircle from_receiver = null;
 
-               if (saved_location != null && state.gps != null && state.gps.locked) {
+               if (state != null && saved_location != null && state.gps != null && state.gps.locked) {
                        double altitude = 0;
                        if (saved_location.hasAltitude())
                                altitude = saved_location.getAltitude();
@@ -243,16 +241,19 @@ public class AltosDroid extends FragmentActivity {
                                                             state.gps.alt);
                }
 
-               mCallsignView.setText(state.data.callsign);
-               mSerialView.setText(String.format("%d", state.data.serial));
-               mFlightView.setText(String.format("%d", state.data.flight));
-               mStateView.setText(state.data.state());
-               mRSSIView.setText(String.format("%d", state.data.rssi));
+               if (state != null) {
+                       mCallsignView.setText(state.data.callsign);
+                       mSerialView.setText(String.format("%d", state.data.serial));
+                       mFlightView.setText(String.format("%d", state.data.flight));
+                       mStateView.setText(state.data.state());
+                       mRSSIView.setText(String.format("%d", state.data.rssi));
+               }
 
                for (AltosDroidTab mTab : mTabs)
                        mTab.update_ui(state, from_receiver, saved_location);
 
-               mAltosVoice.tell(state);
+               if (state != null)
+                       mAltosVoice.tell(state);
        }
 
        private void onTimerTick() {
index de3bc3d29f5cefd8e5e16e2e643eff1017be410e..23d2e97cead2eb9d48e8000316183999a0d7f8b4 100644 (file)
@@ -86,22 +86,24 @@ public class TabAscent extends Fragment implements AltosDroidTab {
        }
 
        public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
-               mHeightView.setText(String.format("%6.0f m", state.height));
-               mMaxHeightView.setText(String.format("%6.0f m", state.max_height));
-               mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
-               mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed()));
-               mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
-               mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration));
-
-               if (state.gps != null) {
-                       mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
-                       mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
+               if (state != null) {
+                       mHeightView.setText(String.format("%6.0f m", state.height));
+                       mMaxHeightView.setText(String.format("%6.0f m", state.max_height));
+                       mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
+                       mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed()));
+                       mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
+                       mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration));
+
+                       if (state.gps != null) {
+                               mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
+                               mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
+                       }
+
+                       mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
+                       mApogeeLights.set(state.drogue_sense > 3.2);
+
+                       mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
+                       mMainLights.set(state.main_sense > 3.2);
                }
-
-               mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
-               mApogeeLights.set(state.drogue_sense > 3.2);
-
-               mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
-               mMainLights.set(state.main_sense > 3.2);
        }
 }
index 698e89fc83474c26caf62492be0f89ba0f5a79f7..49774a3030b87eb810970f908388662a25e862a1 100644 (file)
@@ -90,31 +90,33 @@ public class TabDescent extends Fragment implements AltosDroidTab {
        }
 
        public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
-               mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
-               mHeightView.setText(String.format("%6.0f m", state.height));
-               if (from_receiver != null) {
-                       mElevationView.setText(String.format("%3.0f°", from_receiver.elevation));
-                       mRangeView.setText(String.format("%6.0f m", from_receiver.range));
-                       mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
-                       mCompassView.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG));
-                       mDistanceView.setText(String.format("%6.0f m", from_receiver.distance));
-               } else { 
-                       mElevationView.setText("<unknown>");
-                       mRangeView.setText("<unknown>");
-                       mBearingView.setText("<unknown>");
-                       mCompassView.setText("<unknown>");
-                       mDistanceView.setText("<unknown>");
+               if (state != null) {
+                       mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
+                       mHeightView.setText(String.format("%6.0f m", state.height));
+                       if (from_receiver != null) {
+                               mElevationView.setText(String.format("%3.0f°", from_receiver.elevation));
+                               mRangeView.setText(String.format("%6.0f m", from_receiver.range));
+                               mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
+                               mCompassView.setText(from_receiver.bearing_words(AltosGreatCircle.BEARING_LONG));
+                               mDistanceView.setText(String.format("%6.0f m", from_receiver.distance));
+                       } else { 
+                               mElevationView.setText("<unknown>");
+                               mRangeView.setText("<unknown>");
+                               mBearingView.setText("<unknown>");
+                               mCompassView.setText("<unknown>");
+                               mDistanceView.setText("<unknown>");
+                       }
+                       if (state.gps != null) {
+                               mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
+                               mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
+                       }
+
+                       mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
+                       mApogeeLights.set(state.drogue_sense > 3.2);
+
+                       mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
+                       mMainLights.set(state.main_sense > 3.2);
                }
-               if (state.gps != null) {
-                       mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
-                       mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
-               }
-
-               mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
-               mApogeeLights.set(state.drogue_sense > 3.2);
-
-               mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
-               mMainLights.set(state.main_sense > 3.2);
        }
 
 }
index c346dc991763cdfec4e69a45ea1f0e9146ead798..f42b46b55520d7fbf8551e676ddda47dfebafe41 100644 (file)
@@ -33,8 +33,10 @@ public class TabLanded extends Fragment implements AltosDroidTab {
 
        private TextView mBearingView;
        private TextView mDistanceView;
-       private TextView mLatitudeView;
-       private TextView mLongitudeView;
+       private TextView mTargetLatitudeView;
+       private TextView mTargetLongitudeView;
+       private TextView mReceiverLatitudeView;
+       private TextView mReceiverLongitudeView;
        private TextView mMaxHeightView;
        private TextView mMaxSpeedView;
        private TextView mMaxAccelView;
@@ -53,8 +55,10 @@ public class TabLanded extends Fragment implements AltosDroidTab {
 
                mBearingView   = (TextView) v.findViewById(R.id.bearing_value);
                mDistanceView  = (TextView) v.findViewById(R.id.distance_value);
-               mLatitudeView  = (TextView) v.findViewById(R.id.lat_value);
-               mLongitudeView = (TextView) v.findViewById(R.id.lon_value);
+               mTargetLatitudeView  = (TextView) v.findViewById(R.id.target_lat_value);
+               mTargetLongitudeView = (TextView) v.findViewById(R.id.target_lon_value);
+               mReceiverLatitudeView  = (TextView) v.findViewById(R.id.receiver_lat_value);
+               mReceiverLongitudeView = (TextView) v.findViewById(R.id.receiver_lon_value);
                mMaxHeightView = (TextView) v.findViewById(R.id.max_height_value);
                mMaxSpeedView  = (TextView) v.findViewById(R.id.max_speed_value);
                mMaxAccelView  = (TextView) v.findViewById(R.id.max_accel_value);
@@ -74,13 +78,21 @@ public class TabLanded extends Fragment implements AltosDroidTab {
                        mBearingView.setText(String.format("%3.0f°", from_receiver.bearing));
                        mDistanceView.setText(String.format("%6.0f m", from_receiver.distance));
                }
-               if (state.gps != null) {
-                       mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
-                       mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
+               if (state != null && state.gps != null) {
+                       mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
+                       mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
+               }
+
+               if (receiver != null) {
+                       mReceiverLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S"));
+                       mReceiverLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "W", "E"));
+               }
+              
+               if (state != null) {
+                       mMaxHeightView.setText(String.format("%6.0f m", state.max_height));
+                       mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration));
+                       mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed()));
                }
-               mMaxHeightView.setText(String.format("%6.0f m", state.max_height));
-               mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration));
-               mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed()));
        }
 
 }
index 29696dbf3dcd636675534044e48000f200ddb4c1..66669ad04208c15787775b209292e346324743c1 100644 (file)
@@ -60,6 +60,8 @@ public class TabMap extends Fragment implements AltosDroidTab {
        private TextView mReceiverLatitudeView;
        private TextView mReceiverLongitudeView;
 
+       private double mapAccuracy = -1;
+
        @Override
        public void onAttach(Activity activity) {
                super.onAttach(activity);
@@ -118,7 +120,6 @@ public class TabMap extends Fragment implements AltosDroidTab {
                        mMap.setMyLocationEnabled(true);
                        mMap.getUiSettings().setTiltGesturesEnabled(false);
                        mMap.getUiSettings().setZoomControlsEnabled(false);
-                       mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40.8,-104.7),8));
 
                        mRocketMarker = mMap.addMarker(
                                        // From: http://mapicons.nicolasmollet.com/markers/industry/military/missile-2/
@@ -144,35 +145,52 @@ public class TabMap extends Fragment implements AltosDroidTab {
                }
        }
 
-       public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
-               if (state.from_pad != null) {
-                       mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance));
-                       mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
+       private void center(double lat, double lon, double accuracy) {
+               if (mapAccuracy < 0 || accuracy < mapAccuracy/10) {
+                       mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lon),14));
+                       mapAccuracy = accuracy;
                }
-               if (state.gps != null) {
-                       mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
-                       mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
+       }
+       public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
+               if (state != null) {
+                       if (state.from_pad != null) {
+                               mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance));
+                               mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
+                       }
+                       if (mapLoaded) {
+                               if (state.gps != null) {
+                                       mRocketMarker.setPosition(new LatLng(state.gps.lat, state.gps.lon));
+                                       mRocketMarker.setVisible(true);
+
+                                       mPolyline.setPoints(Arrays.asList(new LatLng(state.pad_lat, state.pad_lon), new LatLng(state.gps.lat, state.gps.lon)));
+                                       mPolyline.setVisible(true);
+                               }
+
+                               if (state.state == AltosLib.ao_flight_pad) {
+                                       mPadMarker.setPosition(new LatLng(state.pad_lat, state.pad_lon));
+                                       mPadMarker.setVisible(true);
+                               }
+                       }
+                       if (state.gps != null) {
+                               mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
+                               mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
+                               if (state.gps.locked && state.gps.nsat >= 4)
+                                       center (state.gps.lat, state.gps.lon, 10);
+                       }
                }
 
                if (receiver != null) {
+                       double accuracy;
+
+                       if (receiver.hasAccuracy())
+                               accuracy = receiver.getAccuracy();
+                       else
+                               accuracy = 1000;
                        mReceiverLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S"));
                        mReceiverLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "W", "E"));
+                       center (receiver.getLatitude(), receiver.getLongitude(), accuracy);
                }
 
-               if (mapLoaded) {
-                       if (state.gps != null) {
-                               mRocketMarker.setPosition(new LatLng(state.gps.lat, state.gps.lon));
-                               mRocketMarker.setVisible(true);
-
-                               mPolyline.setPoints(Arrays.asList(new LatLng(state.pad_lat, state.pad_lon), new LatLng(state.gps.lat, state.gps.lon)));
-                               mPolyline.setVisible(true);
-                       }
-
-                       if (state.state == AltosLib.ao_flight_pad) {
-                               mPadMarker.setPosition(new LatLng(state.pad_lat, state.pad_lon));
-                               mPadMarker.setVisible(true);
-                       }
-               }
        }
 
 }
index 5070ec0bb0a33d765a33bc067a2f9f285bf2a105..3c168e37d4f69a4740f4a9567b37f6304d478fc7 100644 (file)
@@ -102,35 +102,37 @@ public class TabPad extends Fragment implements AltosDroidTab {
        }
 
        public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
-               mBatteryVoltageView.setText(String.format("%4.2f V", state.battery));
-               mBatteryLights.set(state.battery > 3.7);
-
-               mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
-               mApogeeLights.set(state.drogue_sense > 3.2);
-
-               mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
-               mMainLights.set(state.main_sense > 3.2);
-
-               if (state.data.flight != 0) {
-                       if (state.data.state <= AltosLib.ao_flight_pad)
-                               mDataLoggingView.setText("Ready to record");
-                       else if (state.data.state < AltosLib.ao_flight_landed)
-                               mDataLoggingView.setText("Recording data");
-                       else
-                               mDataLoggingView.setText("Recorded data");
-               } else {
-                       mDataLoggingView.setText("Storage full");
-               }
-               mDataLoggingLights.set(state.data.flight != 0);
-
-               if (state.gps != null) {
-                       mGPSLockedView.setText(String.format("%4d sats", state.gps.nsat));
-                       mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4);
-                       if (state.gps_ready)
-                               mGPSReadyView.setText("Ready");
-                       else
-                               mGPSReadyView.setText(String.format("Waiting %d", state.gps_waiting));
-                       mGPSReadyLights.set(state.gps_ready);
+               if (state != null) {
+                       mBatteryVoltageView.setText(String.format("%4.2f V", state.battery));
+                       mBatteryLights.set(state.battery > 3.7);
+
+                       mApogeeVoltageView.setText(String.format("%4.2f V", state.drogue_sense));
+                       mApogeeLights.set(state.drogue_sense > 3.2);
+
+                       mMainVoltageView.setText(String.format("%4.2f V", state.main_sense));
+                       mMainLights.set(state.main_sense > 3.2);
+
+                       if (state.data.flight != 0) {
+                               if (state.data.state <= AltosLib.ao_flight_pad)
+                                       mDataLoggingView.setText("Ready to record");
+                               else if (state.data.state < AltosLib.ao_flight_landed)
+                                       mDataLoggingView.setText("Recording data");
+                               else
+                                       mDataLoggingView.setText("Recorded data");
+                       } else {
+                               mDataLoggingView.setText("Storage full");
+                       }
+                       mDataLoggingLights.set(state.data.flight != 0);
+
+                       if (state.gps != null) {
+                               mGPSLockedView.setText(String.format("%4d sats", state.gps.nsat));
+                               mGPSLockedLights.set(state.gps.locked && state.gps.nsat >= 4);
+                               if (state.gps_ready)
+                                       mGPSReadyView.setText("Ready");
+                               else
+                                       mGPSReadyView.setText(String.format("Waiting %d", state.gps_waiting));
+                               mGPSReadyLights.set(state.gps_ready);
+                       }
                }
 
                if (receiver != null) {