private void conditionallyEnableDisconnectButton() {
    View v = getDialog().findViewById(android.R.id.button2);
    if (v == null) return;

    if (ServiceMqtt.getState() == Defaults.State.ServiceMqtt.CONNECTING
        || ServiceMqtt.getState() == Defaults.State.ServiceMqtt.CONNECTED) {
      v.setEnabled(true);
    } else {
      v.setEnabled(false);
    }
  }
  @Override
  protected void onBindDialogView(View view) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    host.setText(prefs.getString(Defaults.SETTINGS_KEY_BROKER_HOST, Defaults.VALUE_BROKER_HOST));
    port.setText(prefs.getString(Defaults.SETTINGS_KEY_BROKER_PORT, Defaults.VALUE_BROKER_PORT));
    clientId.setHint(ServiceMqtt.getDefaultClientId());

    String cid = prefs.getString(Defaults.SETTINGS_KEY_BROKER_CLIENT_ID, "");
    if (!cid.equals("")) clientId.setText(cid);
    username.setText(prefs.getString(Defaults.SETTINGS_KEY_BROKER_USERNAME, ""));
    password.setText(prefs.getString(Defaults.SETTINGS_KEY_BROKER_PASSWORD, ""));
    brokerSecurity.setSelection(
        PreferenceManager.getDefaultSharedPreferences(context)
            .getInt(Defaults.SETTINGS_KEY_BROKER_SECURITY, Defaults.VALUE_BROKER_SECURITY_NONE));
    brokerSecuritySSLCaCrtPath.setText(
        prefs.getString(Defaults.SETTINGS_KEY_BROKER_SECURITY_SSL_CA_PATH, ""));
  }