import android.os.Messenger;
import android.os.RemoteException;
import android.support.v4.app.FragmentActivity;
-import android.support.v4.view.ViewPager;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.app.AlertDialog;
import android.location.Location;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_5.*;
public class AltosDroid extends FragmentActivity {
// Debugging
private TextView mVersion;
// Tabs
- TabHost mTabHost;
- AltosViewPager mViewPager;
- TabsAdapter mTabsAdapter;
+ TabHost mTabHost;
+ AltosViewPager mViewPager;
+ TabsAdapter mTabsAdapter;
ArrayList<AltosDroidTab> mTabs = new ArrayList<AltosDroidTab>();
+ int tabHeight;
// Timer and Saved flight state for Age calculation
private Timer timer = new Timer();
case MSG_CRC_ERROR:
case MSG_UPDATE_AGE:
if (ad.saved_state != null) {
- ad.mAgeView.setText(String.format("%d", (System.currentTimeMillis() - ad.saved_state.report_time + 500) / 1000));
+ ad.mAgeView.setText(String.format("%d", (System.currentTimeMillis() - ad.saved_state.received_time + 500) / 1000));
}
break;
}
}
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));
+ mCallsignView.setText(state.callsign);
+ mSerialView.setText(String.format("%d", state.serial));
+ mFlightView.setText(String.format("%d", state.flight));
+ mStateView.setText(state.state_name());
+ mRSSIView.setText(String.format("%d", state.rssi));
}
for (AltosDroidTab mTab : mTabs)
static String pos(double p, String pos, String neg) {
String h = pos;
- if (p == AltosRecord.MISSING)
+ if (p == AltosLib.MISSING)
return "";
if (p < 0) {
h = neg;
}
static String number(String format, double value) {
- if (value == AltosRecord.MISSING)
+ if (value == AltosLib.MISSING)
+ return "";
+ return String.format(format, value);
+ }
+
+ static String integer(String format, int value) {
+ if (value == AltosLib.MISSING)
return "";
return String.format(format, value);
}
setContentView(R.layout.altosdroid);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
+ // Create the Tabs and ViewPager
mTabHost = (TabHost)findViewById(android.R.id.tabhost);
mTabHost.setup();
mTabsAdapter.addTab(mTabHost.newTabSpec("landed").setIndicator("Landed"), TabLanded.class, null);
mTabsAdapter.addTab(mTabHost.newTabSpec("map").setIndicator("Map"), TabMap.class, null);
+
+ // Scale the size of the Tab bar for different screen densities
+ // This probably won't be needed when we start supporting ICS+ tabs.
+ DisplayMetrics metrics = new DisplayMetrics();
+ getWindowManager().getDefaultDisplay().getMetrics(metrics);
+ int density = metrics.densityDpi;
+
+ if (density==DisplayMetrics.DENSITY_XHIGH)
+ tabHeight = 65;
+ else if (density==DisplayMetrics.DENSITY_HIGH)
+ tabHeight = 45;
+ else if (density==DisplayMetrics.DENSITY_MEDIUM)
+ tabHeight = 35;
+ else if (density==DisplayMetrics.DENSITY_LOW)
+ tabHeight = 25;
+ else
+ tabHeight = 65;
+
for (int i = 0; i < 5; i++)
- mTabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 45;
+ mTabHost.getTabWidget().getChildAt(i).getLayoutParams().height = tabHeight;
+
// Set up the custom title
mTitle = (TextView) findViewById(R.id.title_left_text);
super.onDestroy();
if(D) Log.e(TAG, "--- ON DESTROY ---");
- mAltosVoice.stop();
+ if (mAltosVoice != null) mAltosVoice.stop();
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}
+ void setBaud(int baud) {
+ try {
+ mService.send(Message.obtain(null, TelemetryService.MSG_SETBAUD, baud));
+ } catch (RemoteException e) {
+ }
+ }
+
+ void setBaud(String baud) {
+ try {
+ int value = Integer.parseInt(baud);
+ int rate = AltosLib.ao_telemetry_rate_38400;
+ switch (value) {
+ case 2400:
+ rate = AltosLib.ao_telemetry_rate_2400;
+ break;
+ case 9600:
+ rate = AltosLib.ao_telemetry_rate_9600;
+ break;
+ case 38400:
+ rate = AltosLib.ao_telemetry_rate_38400;
+ break;
+ }
+ setBaud(rate);
+ } catch (NumberFormatException e) {
+ }
+ }
+
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent serverIntent = null;
"Channel 9 (435.450MHz)"
};
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle("Pick a frequency");
- builder.setItems(frequencies,
+ AlertDialog.Builder builder_freq = new AlertDialog.Builder(this);
+ builder_freq.setTitle("Pick a frequency");
+ builder_freq.setItems(frequencies,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
setFrequency(frequencies[item]);
}
});
- AlertDialog alert = builder.create();
- alert.show();
+ AlertDialog alert_freq = builder_freq.create();
+ alert_freq.show();
+ return true;
+ case R.id.select_rate:
+ // Set the TBT baud rate
+
+ final String[] rates = {
+ "38400",
+ "9600",
+ "2400",
+ };
+
+ AlertDialog.Builder builder_rate = new AlertDialog.Builder(this);
+ builder_rate.setTitle("Pick a baud rate");
+ builder_rate.setItems(rates,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int item) {
+ setBaud(rates[item]);
+ }
+ });
+ AlertDialog alert_rate = builder_rate.create();
+ alert_rate.show();
return true;
}
return false;