コード例 #1
0
  public void nextStates() {

    switch (state) {
      case IDLE:
        if (currentCmd != null) state = BUSY;
        break;

      case BUSY:
        if (Constants.CMD_CLOSE.equalsIgnoreCase(currentCmd)
            || Constants.CMD_CALL.equalsIgnoreCase(currentCmd)) {

          state = CONFIRM;
          contact = nlu.getContact();

          confirm(currentCmd);

        } else if (Constants.CMD_SMS.equalsIgnoreCase(currentCmd)) {

          state = OPTION;
          option = 0;
          String msg = "";
          int j = 0;
          contact = nlu.getContact();

          for (int i = 0; i < sms_options.length; i++) {
            j = i + 1;
            msg += j + ", " + sms_options[i] + ".\n";
          }
          toSay = "Please choose an option." + "\n" + (msg);
          // toSay = "Please choose an option";
        } else {
          state = RUN;
        }
        break;

      case CONFIRM:
        // System.out.println("Confirm branch: \nState " + state + "\nAnswer " + answer);
        if ("yes".equalsIgnoreCase(answer)) {
          state = RUN;
          runCmd(currentCmd);
        } else if ("no".equalsIgnoreCase(answer)) {
          cancelCmd();
        }
        break;

      case OPTION:
        if (option != 0) {
          state = CONFIRM;
          contact = nlu.getContact();
          message = sms_options[option - 1];
          confirm(currentCmd);
        }
        break;
      case RUN:
        runCmd(currentCmd);
        break;
    }
    // System.out.println("Current state :" + state);
  }
コード例 #2
0
  private void confirm(String currentCmd) {
    // TODO Auto-generated method stub

    if (Constants.CMD_CALL.equalsIgnoreCase(currentCmd)) {
      if (contact != null) {
        toSay = "Do you want to call " + contact + ". Say Yes or No";
      } else {
        toSay = "Please provide the contact to be called";
        // start the command incomplete timer
      }

    } else if (Constants.CMD_CLOSE.equalsIgnoreCase(currentCmd)) {
      toSay = "Do you want to close the application. Say Yes or No";

    } else if (Constants.CMD_SMS.equalsIgnoreCase(currentCmd)) {
      String sms = "Do you want to send the message";
      sms += " " + message + " to " + contact;
      sms += ". Say Yes or No";
      toSay = sms;
    }
  }