X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FAltosDroid.java;h=fb669c5dcbfd3d72b408ebca9a0c17ec6e7e92a2;hp=942ebbd5f06d1b4b50441b0677fb948ad23ec54c;hb=ee656c9d41238ab2c56859a03fe6b8ce8ff2df4e;hpb=c813c2c8f71017a686128e06b5178fc99ece251c diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index 942ebbd5..fb669c5d 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -248,9 +248,14 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { } } - boolean registered_units_listener; - int current_serial; + long switch_time; + + void set_switch_time() { + switch_time = System.currentTimeMillis(); + } + + boolean registered_units_listener; void update_state(TelemetryState new_telemetry_state) { @@ -269,11 +274,35 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { update_title(telemetry_state); - AltosDebug.debug("update state current serial %d\n", current_serial); - AltosState state = null; - if (telemetry_state.states.containsKey(current_serial)) + boolean aged = true; + + if (telemetry_state.states.containsKey(current_serial)) { state = telemetry_state.states.get(current_serial); + int age = state_age(state); + if (age < 20) + aged = false; + if (switch_time != 0 && (switch_time - state.received_time) > 0) + aged = true; + } + + if (aged) { + AltosState newest_state = null; + int newest_age = 0; + + for (int serial : telemetry_state.states.keySet()) { + AltosState existing = telemetry_state.states.get(serial); + int existing_age = state_age(existing); + + if (newest_state == null || existing_age < newest_age) { + newest_state = existing; + newest_age = existing_age; + } + } + + if (newest_state != null) + state = newest_state; + } update_ui(telemetry_state, state, telemetry_state.location); @@ -474,12 +503,18 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { return tab_view; } + public void set_map_source() { + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AltosDebug.init(this); AltosDebug.debug("+++ ON CREATE +++"); + // Initialise preferences + AltosDroidPreferences.init(this); + fm = getSupportFragmentManager(); // Set up the window layout @@ -750,6 +785,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { void setFrequency(double freq) { try { mService.send(Message.obtain(null, TelemetryService.MSG_SETFREQUENCY, freq)); + set_switch_time(); } catch (RemoteException e) { } } @@ -764,6 +800,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { void setBaud(int baud) { try { mService.send(Message.obtain(null, TelemetryService.MSG_SETBAUD, baud)); + set_switch_time(); } catch (RemoteException e) { } } @@ -796,7 +833,6 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { if (i == serials.length) return; - AltosDebug.debug("Switching to serial %d\n", serial); current_serial = serial; update_state(null); } @@ -888,6 +924,12 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { serverIntent = new Intent(this, MapTypeActivity.class); startActivityForResult(serverIntent, REQUEST_MAP_TYPE); return true; + case R.id.map_source: + int source = AltosDroidPreferences.map_source(); + int new_source = source == AltosDroidPreferences.MAP_SOURCE_ONLINE ? AltosDroidPreferences.MAP_SOURCE_OFFLINE : AltosDroidPreferences.MAP_SOURCE_ONLINE; + AltosDroidPreferences.set_map_source(new_source); + set_map_source(); + return true; case R.id.select_tracker: if (serials != null) { String[] trackers = new String[serials.length];