+ String text;
+ if (age < 60)
+ text = String.format("%ds", age);
+ else if (age < 60 * 60)
+ text = String.format("%dm", age / 60);
+ else if (age < 60 * 60 * 24)
+ text = String.format("%dh", age / (60 * 60));
+ else
+ text = String.format("%dd", age / (24 * 60 * 60));
+ mAgeView.setText(text);
+ }
+ }
+
+ void update_ui(TelemetryState telem_state, AltosState state, boolean quiet) {
+
+ this.state = state;
+
+ int prev_state = AltosLib.ao_flight_invalid;
+
+ AltosGreatCircle from_receiver = null;
+
+ if (saved_state != null)
+ prev_state = saved_state.state;
+
+ if (state != null) {
+ set_screen_on(state_age(state.received_time));
+
+ if (state.state() == AltosLib.ao_flight_stateless) {
+ boolean prev_locked = false;
+ boolean locked = false;
+
+ if(state.gps != null)
+ locked = state.gps.locked;
+ if (saved_state != null)
+ prev_locked = saved_state.locked;
+ if (prev_locked != locked) {
+ String currentTab = mTabHost.getCurrentTabTag();
+ if (locked) {
+ if (currentTab.equals(tab_pad_name)) mTabHost.setCurrentTabByTag(tab_flight_name);
+ } else {
+ if (currentTab.equals(tab_flight_name)) mTabHost.setCurrentTabByTag(tab_pad_name);
+ }
+ }
+ } else {
+ if (prev_state != state.state()) {
+ String currentTab = mTabHost.getCurrentTabTag();
+ switch (state.state()) {
+ case AltosLib.ao_flight_boost:
+ if (currentTab.equals(tab_pad_name)) mTabHost.setCurrentTabByTag(tab_flight_name);
+ break;
+ case AltosLib.ao_flight_landed:
+ if (currentTab.equals(tab_flight_name)) mTabHost.setCurrentTabByTag(tab_recover_name);
+ break;
+ case AltosLib.ao_flight_stateless:
+ if (currentTab.equals(tab_pad_name)) mTabHost.setCurrentTabByTag(tab_flight_name);
+ break;
+ }
+ }
+ }
+
+ if (location != null && state.gps != null && state.gps.locked) {
+ double altitude = 0;
+ if (location.hasAltitude())
+ altitude = location.getAltitude();
+ from_receiver = new AltosGreatCircle(location.getLatitude(),
+ location.getLongitude(),
+ altitude,
+ state.gps.lat,
+ state.gps.lon,
+ state.gps.alt);
+ }
+
+ if (saved_state == null || !same_string(saved_state.callsign, state.cal_data.callsign)) {
+ mCallsignView.setText(state.cal_data.callsign);
+ }
+ if (saved_state == null || state.cal_data.serial != saved_state.serial) {
+ if (state.cal_data.serial == AltosLib.MISSING)
+ mSerialView.setText("");
+ else
+ mSerialView.setText(String.format("%d", state.cal_data.serial));
+ }
+ if (saved_state == null || state.cal_data.flight != saved_state.flight) {
+ if (state.cal_data.flight == AltosLib.MISSING)
+ mFlightView.setText("");
+ else
+ mFlightView.setText(String.format("%d", state.cal_data.flight));
+ }
+ if (saved_state == null || state.state() != saved_state.state) {
+ if (state.state() == AltosLib.ao_flight_stateless) {
+ mStateLayout.setVisibility(View.GONE);
+ } else {
+ mStateView.setText(state.state_name());
+ mStateLayout.setVisibility(View.VISIBLE);
+ }
+ }
+ if (saved_state == null || state.rssi != saved_state.rssi) {
+ if (state.rssi == AltosLib.MISSING)
+ mRSSIView.setText("");
+ else
+ mRSSIView.setText(String.format("%d", state.rssi));
+ }
+ saved_state = new SavedState(state);
+ }