+ private TextToSpeech tts;
+ private boolean tts_enabled = false;
+
+ // The Handler that gets information back from the Telemetry Service
+ static class IncomingHandler extends Handler {
+ private final WeakReference<AltosDroid> mAltosDroid;
+ IncomingHandler(AltosDroid ad) { mAltosDroid = new WeakReference<AltosDroid>(ad); }
+
+ @Override
+ public void handleMessage(Message msg) {
+ AltosDroid ad = mAltosDroid.get();
+ switch (msg.what) {
+ case MSG_STATE_CHANGE:
+ if(D) Log.i(TAG, "MSG_STATE_CHANGE: " + msg.arg1);
+ switch (msg.arg1) {
+ case TelemetryService.STATE_CONNECTED:
+ ad.mTitle.setText(R.string.title_connected_to);
+ ad.mTitle.append(ad.mConnectedDeviceName);
+ ad.mSerialView.setText("");
+ break;
+ case TelemetryService.STATE_CONNECTING:
+ ad.mTitle.setText(R.string.title_connecting);
+ break;
+ case TelemetryService.STATE_READY:
+ case TelemetryService.STATE_NONE:
+ ad.mTitle.setText(R.string.title_not_connected);
+ break;
+ }
+ break;
+ case MSG_INCOMING_TELEM:
+ byte[] buf = (byte[]) msg.obj;
+ // construct a string from the buffer
+ String telem = new String(buf);
+ ad.mSerialView.append(telem);
+ break;
+ case MSG_DEVNAME:
+ // save the connected device's name
+ ad.mConnectedDeviceName = (String) msg.obj;
+ if (ad.mConnectedDeviceName != null)
+ Toast.makeText(ad.getApplicationContext(), "Connected to "
+ + ad.mConnectedDeviceName, Toast.LENGTH_SHORT).show();
+ break;
+ case MSG_TOAST:
+ Toast.makeText(
+ ad.getApplicationContext(),
+ (String) msg.obj,
+ Toast.LENGTH_SHORT).show();
+ break;
+ }
+ }
+ };
+
+
+ private ServiceConnection mConnection = new ServiceConnection() {
+ public void onServiceConnected(ComponentName className, IBinder service) {
+ mService = new Messenger(service);
+ try {
+ Message msg = Message.obtain(null, TelemetryService.MSG_REGISTER_CLIENT);
+ msg.replyTo = mMessenger;
+ mService.send(msg);
+ } catch (RemoteException e) {
+ // In this case the service has crashed before we could even do anything with it
+ }
+ }
+
+ public void onServiceDisconnected(ComponentName className) {
+ // This is called when the connection with the service has been unexpectedly disconnected - process crashed.
+ mService = null;
+ }
+ };
+
+