/** Shows the "connecting" dialog if it's not already showing. */
  @UiThread
  private void showConnectingDialog() {
    if (connectingDialog == null || !connectingDialog.isShowing()) {
      Preferences preferences = new Preferences(mActivity);
      Preferences.ServerAddress serverAddress = preferences.getServerAddress();

      connectingDialog =
          ProgressDialog.show(
              mActivity,
              getText(R.string.connecting_text),
              getString(R.string.connecting_to_text, preferences.getServerName(serverAddress)),
              true,
              false);
    }
  }
  public void startVisibleConnection() {
    Log.v(TAG, "startVisibleConnection");
    if (mService == null) {
      return;
    }

    Preferences preferences = new Preferences(mActivity);

    // If we are configured to automatically connect on Wi-Fi availability
    // we will also give the user the opportunity to enable Wi-Fi
    if (preferences.isAutoConnect()) {
      WifiManager wifiManager = (WifiManager) mActivity.getSystemService(Context.WIFI_SERVICE);
      if (!wifiManager.isWifiEnabled()) {
        FragmentManager fragmentManager = getFragmentManager();
        if (fragmentManager != null) {
          EnableWifiDialog.show(getFragmentManager());
        } else {
          Log.i(getTag(), "fragment manager is null so we can't show EnableWifiDialog");
        }
        return;
        // When a Wi-Fi connection is made this method will be called again by the
        // broadcastReceiver
      }
    }

    Preferences.ServerAddress serverAddress = preferences.getServerAddress();
    String ipPort = serverAddress.address;
    if (ipPort == null) {
      // Set up a server connection, if it is not present
      DisconnectedActivity.show(mActivity);
      return;
    }

    if (isConnectInProgress()) {
      Log.v(TAG, "Connection is already in progress, connecting aborted");
      return;
    }
    Log.v(TAG, "startConnect, ipPort: " + ipPort);
    mService.startConnect(
        ipPort,
        preferences.getUserName(serverAddress, "test"),
        preferences.getPassword(serverAddress, "test1"));
  }