altosdroid: Start a hacked-up frequency dialog
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / AltosDroid.java
index 20904d2b0845f6de6723144bfb6bf2dca3ac23b9..2776016216beb9f4f3687ad6f2c80318aa44d27b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2012 Mike Beattie <mike@ethernal.org>
+ * Copyright Â© 2012 Mike Beattie <mike@ethernal.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@ import android.content.Intent;
 import android.content.Context;
 import android.content.ComponentName;
 import android.content.ServiceConnection;
+import android.content.DialogInterface;
 import android.os.IBinder;
 import android.os.Bundle;
 import android.os.Handler;
@@ -40,6 +41,7 @@ import android.view.MenuItem;
 import android.view.Window;
 import android.widget.TextView;
 import android.widget.Toast;
+import android.app.AlertDialog;
 
 import org.altusmetrum.AltosLib.*;
 
@@ -188,12 +190,12 @@ public class AltosDroid extends Activity {
                if (!state.ascent)
                        speed = state.baro_speed;
                mSpeedView.setText(String.format("%6.0f m/s", speed));
-               mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
+               mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
                mRangeView.setText(String.format("%6.0f m", state.range));
                mHeightView.setText(String.format("%6.0f m", state.height));
-               mElevationView.setText(String.format("%3.0f°", state.elevation));
+               mElevationView.setText(String.format("%3.0f°", state.elevation));
                if (state.from_pad != null)
-                       mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
+                       mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
                mLatitudeView.setText(pos(state.gps.lat, "N", "S"));
                mLongitudeView.setText(pos(state.gps.lon, "W", "E"));
 
@@ -208,7 +210,7 @@ public class AltosDroid extends Activity {
                }
                int deg = (int) Math.floor(p);
                double min = (p - Math.floor(p)) * 60.0;
-               return String.format("%d° %9.6f\" %s", deg, min, h);
+               return String.format("%d° %9.6f\" %s", deg, min, h);
        }
 
        @Override
@@ -352,6 +354,17 @@ public class AltosDroid extends Activity {
                return true;
        }
 
+       void setFrequency(double freq) {
+               
+       }
+
+       void setFrequency(String freq) {
+               try {
+                       setFrequency (Double.parseDouble(freq));
+               } catch (NumberFormatException e) {
+               }
+       }
+
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
                Intent serverIntent = null;
@@ -361,6 +374,32 @@ public class AltosDroid extends Activity {
                        serverIntent = new Intent(this, DeviceListActivity.class);
                        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
                        return true;
+               case R.id.select_freq:
+                       // Set the TBT radio frequency
+
+                       final String[] frequencies = {
+                               "434.550",
+                               "434.650",
+                               "434.750",
+                               "434.850",
+                               "434.950",
+                               "435.050",
+                               "435.150",
+                               "435.250",
+                               "435.350",
+                               "435.450"
+                       };
+
+                       AlertDialog.Builder builder = new AlertDialog.Builder(this);
+                       builder.setTitle("Pick a frequency");
+                       builder.setItems(frequencies,
+                                        new DialogInterface.OnClickListener() {
+                                                public void onClick(DialogInterface dialog, int item) {
+                                                        setFrequency(frequencies[item]);
+                                                }
+                                        });
+                       AlertDialog alert = builder.create();
+                       return true;
                }
                return false;
        }