Ejemplo n.º 1
0
 /**
  * Creates a new note.
  *
  * @param octave The octave where the note is in. Has to be 0 - 2.
  * @param note The tone within the octave. If the octave is 2 the note has to be F#.
  * @param sharped Set it the tone is sharped (e.g. for F#).
  */
 public Note(byte octave, Tone note, boolean sharped) {
   if (sharped && !note.isSharpable()) {
     throw new IllegalArgumentException("This tone could not be sharped.");
   }
   if (octave < 0 || octave > 2 || (octave == 2 && !(note == Tone.F && sharped))) {
     throw new IllegalArgumentException("Tone and octave have to be between F#0 and F#2");
   }
   this.note = (byte) (octave * Tone.TONES_COUNT + note.getId(sharped));
 }
  /**
   * Processes PLAY_TONE proactive command from the SIM card.
   *
   * @param cmdDet Command Details container object.
   * @param ctlvs List of ComprehensionTlv objects following Command Details object and Device
   *     Identities object within the proactive command
   * @return true if the command is processing is pending and additional asynchronous processing is
   *     required.t
   * @throws ResultException
   */
  private boolean processPlayTone(CommandDetails cmdDet, List<ComprehensionTlv> ctlvs)
      throws ResultException {

    CatLog.d(this, "process PlayTone");

    Tone tone = null;
    TextMessage textMsg = new TextMessage();
    Duration duration = null;
    IconId iconId = null;

    ComprehensionTlv ctlv = searchForTag(ComprehensionTlvTag.TONE, ctlvs);
    if (ctlv != null) {
      // Nothing to do for null objects.
      if (ctlv.getLength() > 0) {
        try {
          byte[] rawValue = ctlv.getRawValue();
          int valueIndex = ctlv.getValueIndex();
          int toneVal = rawValue[valueIndex];
          tone = Tone.fromInt(toneVal);
        } catch (IndexOutOfBoundsException e) {
          throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD);
        }
      }
    }
    // parse alpha identifier
    ctlv = searchForTag(ComprehensionTlvTag.ALPHA_ID, ctlvs);
    if (ctlv != null) {
      textMsg.text = ValueParser.retrieveAlphaId(ctlv);
    }
    // parse tone duration
    ctlv = searchForTag(ComprehensionTlvTag.DURATION, ctlvs);
    if (ctlv != null) {
      duration = ValueParser.retrieveDuration(ctlv);
    }
    // parse icon identifier
    ctlv = searchForTag(ComprehensionTlvTag.ICON_ID, ctlvs);
    if (ctlv != null) {
      iconId = ValueParser.retrieveIconId(ctlv);
      textMsg.iconSelfExplanatory = iconId.selfExplanatory;
    }

    boolean vibrate = (cmdDet.commandQualifier & 0x01) != 0x00;

    textMsg.responseNeeded = false;
    mCmdParams = new PlayToneParams(cmdDet, textMsg, tone, duration, vibrate);

    if (iconId != null) {
      mIconLoadState = LOAD_SINGLE_ICON;
      mIconLoader.loadIcon(iconId.recordNumber, this.obtainMessage(MSG_ID_LOAD_ICON_DONE));
      return true;
    }
    return false;
  }
Ejemplo n.º 3
0
    static {
      byte lowest = F.id;
      byte highest = F.id;
      for (Tone tone : Tone.values()) {
        byte id = tone.id;
        tones.put(id, tone);
        if (id < lowest) {
          lowest = id;
        }
        if (tone.isSharpable()) {
          id++;
          tones.put(id, tone);
        }
        if (id > highest) {
          highest = id;
        }
      }

      TONES_COUNT = (byte) (highest - lowest + 1);
      tones.put((byte) (TONES_COUNT - 1), F);
    }
Ejemplo n.º 4
0
 /**
  * Returns if this note is sharped.
  *
  * @return if this note is sharped.
  */
 public boolean isSharped() {
   byte note = getToneByte();
   return Tone.getToneById(note).isSharped(note);
 }
Ejemplo n.º 5
0
 /**
  * Returns the tone of this note.
  *
  * @return the tone of this note.
  */
 public Tone getTone() {
   return Tone.getToneById(getToneByte());
 }