import java.util.*;
import java.io.*;
-import org.altusmetrum.altoslib_7.*;
+import org.altusmetrum.altoslib_10.*;
import android.app.Activity;
import android.graphics.*;
}
}
-public class AltosMapOffline extends View implements ScaleGestureDetector.OnScaleGestureListener, AltosMapInterface, AltosDroidMapInterface {
+public class AltosMapOffline extends View implements ScaleGestureDetector.OnScaleGestureListener, AltosMapInterface, AltosDroidMapInterface, AltosMapTypeListener {
ScaleGestureDetector scale_detector;
boolean scaling;
AltosMap map;
AltosDroid altos_droid;
AltosLatLon here;
+ AltosLatLon there;
AltosLatLon pad;
Canvas canvas;
public void select_object(AltosLatLon latlon) {
if (map.transform == null)
return;
+ ArrayList<Integer> near = new ArrayList<Integer>();
+
for (Rocket rocket : sorted_rockets()) {
if (rocket.position == null) {
debug("rocket %d has no position\n", rocket.serial);
debug("check select %d distance %g width %d\n", rocket.serial, distance, rocket_bitmap.getWidth());
if (distance < rocket_bitmap.getWidth() * 2.0) {
debug("selecting %d\n", rocket.serial);
- altos_droid.select_tracker(rocket.serial);
- break;
+ near.add(rocket.serial);
}
}
+ if (near.size() != 0)
+ altos_droid.touch_trackers(near.toArray(new Integer[0]));
}
class Line {
}
private void draw_positions() {
- line.set_a(map.last_position);
+ line.set_a(there);
line.set_b(here);
line.paint();
draw_bitmap(pad, pad_bitmap, pad_off_x, pad_off_y);
@Override
protected void onDraw(Canvas view_canvas) {
- debug("onDraw");
if (map == null) {
debug("MapView draw without map\n");
return;
double mapAccuracy;
public void center(double lat, double lon, double accuracy) {
- if (mapAccuracy < 0 || accuracy < mapAccuracy/10) {
+ if (mapAccuracy <= 0 || accuracy < mapAccuracy/10 || (map != null && !map.has_centre())) {
if (map != null)
map.maybe_centre(lat, lon);
mapAccuracy = accuracy;
}
public void show(TelemetryState telem_state, AltosState state, AltosGreatCircle from_receiver, Location receiver) {
+ boolean changed = false;
+
if (state != null) {
map.show(state, null);
if (state.pad_lat != AltosLib.MISSING && pad == null)
rocket = new Rocket(serial, this);
rockets.put(serial, rocket);
}
- if (t_state.gps != null)
- rocket.set_position(new AltosLatLon(t_state.gps.lat, t_state.gps.lon), t_state.received_time);
+ if (t_state.gps != null) {
+ AltosLatLon latlon = new AltosLatLon(t_state.gps.lat, t_state.gps.lon);
+ rocket.set_position(latlon, t_state.received_time);
+ if (state.serial == serial)
+ there = latlon;
+ }
if (state != null)
rocket.set_active(state.serial == serial);
}
}
if (receiver != null) {
- here = new AltosLatLon(receiver.getLatitude(), receiver.getLongitude());
+ AltosLatLon new_here = new AltosLatLon(receiver.getLatitude(), receiver.getLongitude());
+ if (!new_here.equals(here)) {
+ here = new_here;
+ AltosDebug.debug("Location changed, redraw");
+ repaint();
+ }
}
}
public void onCreateView(AltosDroid altos_droid) {
this.altos_droid = altos_droid;
map = new AltosMap(this);
- map.set_maptype(altos_droid.map_type);
+ AltosPreferences.register_map_type_listener(this);
+ map.set_maptype(AltosPreferences.map_type());
pad_bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pad);
/* arrow at the bottom of the launchpad image */
here_off_y = here_bitmap.getHeight() / 2;
}
- public void set_map_type(int map_type) {
+ public void onDestroyView() {
+ AltosPreferences.unregister_map_type_listener(this);
+ }
+
+ public void map_type_changed(int map_type) {
if (map != null)
map.set_maptype(map_type);
}