altosdroid: Split setup functions to separate dialog
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / TabMap.java
index 0ee202a46da696b35529e8dddfe9b4424697e6e4..19ce86c9f75c5e80448486e8ab11174c95a94c69 100644 (file)
@@ -20,7 +20,7 @@ package org.altusmetrum.AltosDroid;
 import java.util.*;
 import java.io.*;
 
-import org.altusmetrum.altoslib_7.*;
+import org.altusmetrum.altoslib_10.*;
 
 import android.app.Activity;
 import android.graphics.*;
@@ -32,11 +32,12 @@ import android.widget.*;
 import android.location.Location;
 import android.content.*;
 
-public class TabMap extends AltosDroidTab {
+public class TabMap extends AltosDroidTab implements AltosDroidMapSourceListener {
 
        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);
@@ -72,7 +74,8 @@ public class TabMap extends AltosDroidTab {
                map_offline.onCreateView(altos_droid);
                map_online = new AltosMapOnline(view.getContext());
                map_online.onCreateView(altos_droid);
-               set_map_source(AltosDroidPreferences.map_source());
+               map_source_changed(AltosDroidPreferences.map_source());
+               AltosDroidPreferences.register_map_source_listener(this);
                return view;
        }
 
@@ -86,6 +89,9 @@ public class TabMap extends AltosDroidTab {
        @Override
        public void onDestroyView() {
                super.onDestroyView();
+               map_offline.onDestroyView();
+               map_online.onDestroyView();
+               AltosDroidPreferences.unregister_map_source_listener(this);
        }
 
        public String tab_name() { return AltosDroid.tab_map_name; }
@@ -99,8 +105,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) {
@@ -131,16 +148,7 @@ public class TabMap extends AltosDroidTab {
                }
        }
 
-       @Override
-       public void set_map_type(int map_type) {
-               if (map_offline != null)
-                       map_offline.set_map_type(map_type);
-               if (map_online != null)
-                       map_online.set_map_type(map_type);
-       }
-
-       @Override
-       public void set_map_source(int map_source) {
+       public void map_source_changed(int map_source) {
                this.map_source = map_source;
                if (map_source == AltosDroidPreferences.MAP_SOURCE_OFFLINE) {
                        if (map_online != null)