/** Put the vibrator in mode On */
  private void vibrateOn() {

    try {

      String vibratorService = Context.VIBRATOR_SERVICE;
      Vibrator vibrator = (Vibrator) ConfigAppValues.getContext().getSystemService(vibratorService);

      vibrator.vibrate(1000);

    } catch (Exception e) {
      if (QSLog.DEBUG_E)
        QSLog.e(CLASS_NAME, ExceptionUtils.exceptionTraceToString(e.toString(), e.getStackTrace()));
    }
  }
  /** Put the ddbb saved data in the activity widgets */
  private void initActivity() {

    try {
      ClientDDBB clientDDBB = new ClientDDBB();

      // Togglebutton (QuuiteSleep service) check
      Settings settings = clientDDBB.getSelects().selectSettings();
      if (settings != null) {
        serviceToggleButton.setChecked(settings.isQuiteSleepServiceState());
      } else serviceToggleButton.setChecked(false);

      // Mute or hangup radio buttons check
      if (ConfigAppValues.getMuteOrHangup() == null) {
        MuteOrHangUp muteOrHangup = clientDDBB.getSelects().selectMuteOrHangUp();
        if (muteOrHangup != null) {
          if (muteOrHangup.isMute()) muteRButton.setChecked(true);
          else if (muteOrHangup.isHangUp()) hangUpRButton.setChecked(true);
        }
        // If MuteOrHangUp object is not created. Should not occur
        else {
          muteOrHangup = new MuteOrHangUp();
          clientDDBB.getInserts().insertMuteOrHangUp(muteOrHangup);
          clientDDBB.commit();
        }

      } else {
        if (ConfigAppValues.getMuteOrHangup()) hangUpRButton.setChecked(true);
        else muteRButton.setChecked(true);
      }
      clientDDBB.close();

    } catch (Exception e) {
      if (QSLog.DEBUG_E)
        QSLog.e(CLASS_NAME, ExceptionUtils.exceptionTraceToString(e.toString(), e.getStackTrace()));
    }
  }
  /**
   * This function save the user option regarding both mute or hang up in the ddbb.
   *
   * @param optionValue
   */
  private void saveMuteOrHangUpOption(boolean optionValue) {

    try {

      ClientDDBB clientDDBB = new ClientDDBB();
      MuteOrHangUp muteOrHangup = clientDDBB.getSelects().selectMuteOrHangUp();
      if (muteOrHangup != null) {

        // If is true, then the hangup option is established
        if (optionValue) {
          muteOrHangup.setHangUp(true);
          ConfigAppValues.setMuteOrHangup(true);
        }
        // If is false, then the mute mode is set to true
        else {
          muteOrHangup.setMute(true);
          ConfigAppValues.setMuteOrHangup(false);
        }

        clientDDBB.getUpdates().insertMuteOrHangUp(muteOrHangup);
        clientDDBB.commit();
      }

      // If MuteOrHangUp object is not created.
      else {
        muteOrHangup = new MuteOrHangUp();
        clientDDBB.getInserts().insertMuteOrHangUp(muteOrHangup);
        clientDDBB.commit();
      }
      clientDDBB.close();

    } catch (Exception e) {
      if (QSLog.DEBUG_E)
        QSLog.e(CLASS_NAME, ExceptionUtils.exceptionTraceToString(e.toString(), e.getStackTrace()));
    }
  }
  /**
   * Put the mobile in normal mode (audio and vibrate), important: normal mode such the user defined
   * previously (before to put the mobile in silence)
   */
  private void putRingerModeNormal() {

    try {
      if (QSLog.DEBUG_D) QSLog.d(CLASS_NAME, "Poniendo el movil en modo normal");

      AudioManager audioManager =
          (AudioManager) ConfigAppValues.getContext().getSystemService(Context.AUDIO_SERVICE);
      audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

      ConfigAppValues.processIdleCall = false;

    } catch (Exception e) {
      if (QSLog.DEBUG_E)
        QSLog.e(CLASS_NAME, ExceptionUtils.exceptionTraceToString(e.toString(), e.getStackTrace()));
    }
  }