@Override
  protected void onPause() {
    super.onPause();
    if (Log.DEBUG) Log.v("SMSPopupActivity: onPause()");

    // Hide the soft keyboard in case it was shown via quick reply
    hideSoftKeyboard();

    // Shutdown eyes-free TTS
    if (eyesFreeTts != null) {
      eyesFreeTts.shutdown();
    }

    // Shutdown Android TTS
    if (androidTextToSpeechAvailable) {
      if (androidTts != null) {
        androidTts.shutdown();
      }
    }

    // Dismiss loading dialog
    if (mProgressDialog != null) {
      mProgressDialog.dismiss();
    }

    if (wasVisible) {
      // Cancel the receiver that will clear our locks
      ClearAllReceiver.removeCancel(getApplicationContext());
      ClearAllReceiver.clearAll(!exitingKeyguardSecurely);
    }

    mDbAdapter.close();
  }
  /*
   * Speak the message out loud using text-to-speech (either via Android text-to-speech or
   * via the free eyes-free text-to-speech library)
   */
  private void speakMessage() {
    // TODO: we should really require the keyguard be unlocked here if we are in privacy mode

    // If not previously initialized...
    if (!ttsInitialized) {

      // Show a loading dialog
      showDialog(DIALOG_LOADING);

      // User interacted so remove all locks and cancel reminders
      ClearAllReceiver.removeCancel(getApplicationContext());
      ClearAllReceiver.clearAll(false);
      ReminderReceiver.cancelReminder(getApplicationContext());

      // We'll use update notification to stop the sound playing
      ManageNotification.update(getApplicationContext(), message);

      if (androidTextToSpeechAvailable) {
        // Android text-to-speech available (normally found on Android 1.6+, aka Donut)
        androidTts = new TextToSpeechWrapper(SmsPopupActivity.this, androidTtsListener);
      } else { // Else use eyes-free text-to-speech library
        /*
         * This is an aweful fix for the loading dialog not disappearing
         * when the user decides to not install the TTS package but there didn't
         * seem like another way to hook into the current TTS library.
         *
         * This will all go away once we can purely use the system TTS engine and do away
         * with the eyes-free version from Market.
         */
        // Extend TTS alert dialog so we can dismiss the loading dialog correctly
        class mTtsVersionAlert extends TTSVersionAlert {
          // Leaving this as hardcoded just as from the TTS source
          private static final String QUIT = "Do not install the TTS";

          mTtsVersionAlert(Context context) {
            super(context, null, null, null);
            setNegativeButton(
                QUIT,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    if (mProgressDialog != null) {
                      mProgressDialog.dismiss();
                    }
                  }
                });
            setOnCancelListener(
                new OnCancelListener() {
                  public void onCancel(DialogInterface dialog) {
                    if (mProgressDialog != null) {
                      mProgressDialog.dismiss();
                    }
                  }
                });
          }
        }

        // Init the eyes-free text-to-speech library
        eyesFreeTts = new TTS(this, eyesFreeTtsListener, new mTtsVersionAlert(this));
      }

    } else {

      // Speak the message!
      if (androidTextToSpeechAvailable) {
        androidTts.speak(message.getMessageBody(), TextToSpeechWrapper.QUEUE_FLUSH, null);
      } else {
        eyesFreeTts.speak(message.getMessageBody(), 0 /* no queue mode */, null);
      }
    }
  }