/*
   * (non-Javadoc)
   *
   * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
   */
  @Override
  public void characters(char ch[], int start, int length) {
    String value = new String(ch, start, length);

    if (inMovie) {
      if (inReference) {
        mMovie.putOrConcat(Movie.KEY_REFERENCE, value);
      } else if (inTitle) {
        mMovie.putOrConcat(Movie.KEY_TITLE, value);
      } else if (inDescription) {
        mMovie.putOrConcat(Movie.KEY_DESCRIPTION, value);
      } else if (inDescriptionEx) {
        mMovie.putOrConcat(Movie.KEY_DESCRIPTION_EXTENDED, value);
      } else if (inName) {
        mMovie.putOrConcat(Movie.KEY_SERVICE_NAME, value.replaceAll("\\p{Cntrl}", "")); // remove
        // illegal
        // chars
      } else if (inTime) {
        mMovie.putOrConcat(Movie.KEY_TIME, value);
        mMovie.putOrConcat(Movie.KEY_TIME_READABLE, DateTime.getDateTimeString(value));
      } else if (inLength) {
        mMovie.putOrConcat(Movie.KEY_LENGTH, value);
      } else if (inTags) {
        mMovie.putOrConcat(Movie.KEY_TAGS, value);
      } else if (inFilename) {
        mMovie.putOrConcat(Movie.KEY_FILE_NAME, value);
      } else if (inFilesize) {
        mMovie.putOrConcat(Movie.KEY_FILE_SIZE, value);
        Long size = Long.valueOf(value);
        size /= (1024 * 1024);
        String size_readable = size + " MB";
        mMovie.putOrConcat(Movie.KEY_FILE_SIZE_READABLE, size_readable);
      }
    }
  }
 /** Apply the values of the TimePicker for the Timer-Begin to <code>mTimer</code> */
 private void updateBegin(Calendar cal) {
   mBegin = (int) (cal.getTimeInMillis() / 1000);
   String timestamp = Long.valueOf(mBegin).toString();
   mTimer.put(Timer.KEY_BEGIN, timestamp);
   mTimer.put(Timer.KEY_BEGIN_READEABLE, DateTime.getYearDateTimeString(timestamp));
 }
 /** Apply the values of the TimePicker for the Timer-End to <code>mTimer</code> */
 private void updateEnd(Calendar cal) {
   mEnd = (int) (cal.getTimeInMillis() / 1000);
   String timestamp = Long.valueOf(mEnd).toString();
   mTimer.put(Timer.KEY_END, timestamp);
   mTimer.put(Timer.KEY_END_READABLE, DateTime.getYearDateTimeString(timestamp));
 }
  /** Set the GUI-Content from <code>mTimer</code> */
  protected void reload() {
    // Name
    mName.setText(mTimer.getString(Timer.KEY_NAME));
    mName.setHint(R.string.title);

    // Description
    mDescription.setText(mTimer.getString(Timer.KEY_DESCRIPTION));
    mDescription.setHint(R.string.description);

    // Enabled
    int disabled = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_DISABLED));
    if (disabled == 0) {
      mEnabled.setChecked(true);
    } else {
      mEnabled.setChecked(false);
    }

    int zap = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_JUST_PLAY));
    if (zap == 1) {
      mZap.setChecked(true);
    } else {
      mZap.setChecked(false);
    }

    mService.setText(mTimer.getString(Timer.KEY_SERVICE_NAME));

    // Afterevents
    ArrayAdapter<CharSequence> aaAfterevent =
        ArrayAdapter.createFromResource(
            getAppCompatActivity(), R.array.afterevents, android.R.layout.simple_spinner_item);
    aaAfterevent.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mAfterevent.setAdapter(aaAfterevent);

    int aeValue = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_AFTER_EVENT));
    mAfterevent.setSelection(aeValue);

    // Locations
    ArrayAdapter<String> aaLocations =
        new ArrayAdapter<>(
            getAppCompatActivity(),
            android.R.layout.simple_spinner_item,
            DreamDroid.getLocations());
    aaLocations.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mLocation.setAdapter(aaLocations);

    String timerLoc = mTimer.getString(Timer.KEY_LOCATION);
    for (int i = 0; i < DreamDroid.getLocations().size(); i++) {
      String loc = DreamDroid.getLocations().get(i);

      if (timerLoc != null) {
        if (timerLoc.equals(loc)) {
          mLocation.setSelection(i);
        }
      }
    }

    // Start and Endtime
    mBegin = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_BEGIN));
    mEnd = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_END));
    Date dateBegin = new Date(((long) mBegin) * 1000);
    Date dateEnd = new Date(((long) mEnd) * 1000);

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");

    mStartDate.setText(dateFormat.format(dateBegin));
    mStartTime.setText(timeFormat.format(dateBegin));
    mEndDate.setText(dateFormat.format(dateEnd));
    mEndTime.setText(timeFormat.format(dateEnd));

    // Repeatings
    int repeatedValue = 0;
    try {
      repeatedValue = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_REPEATED));
    } catch (NumberFormatException ex) {
    }

    String repeatedText = getRepeated(repeatedValue);
    mRepeatings.setText(repeatedText);

    String text = mTimer.getString(Timer.KEY_TAGS);
    if (text == null) {
      text = "";
    }
    mTags.setText(text);
    String[] tags = text.split(" ");
    Collections.addAll(mSelectedTags, tags);
  }