Beispiel #1
0
  @Override
  public Time get(ContentSet values) {
    Long timestamp = values.getAsLong(mTimestampField);
    if (timestamp == null) {
      // if the time stamp is null we return null
      return null;
    }
    // create a new Time for the given time zone, falling back to UTC if none is given
    String timezone = mTzField == null ? Time.TIMEZONE_UTC : values.getAsString(mTzField);
    Time value = new Time(timezone == null ? Time.TIMEZONE_UTC : timezone);
    // set the time stamp
    value.set(timestamp);

    // cache mAlldayField locally
    String allDayField = mAllDayField;

    // set the allday flag appropriately
    Integer allDayInt = allDayField == null ? null : values.getAsInteger(allDayField);

    if ((allDayInt != null && allDayInt != 0) || (allDayField == null && mAllDayDefault)) {
      value.set(value.monthDay, value.month, value.year);
      value.timezone = Time.TIMEZONE_UTC;
    }

    return value;
  }
Beispiel #2
0
 @Override
 public void unregisterListener(ContentSet values, OnContentChangeListener listener) {
   values.removeOnChangeListener(listener, mTimestampField);
   if (mTzField != null) {
     values.removeOnChangeListener(listener, mTzField);
   }
   if (mAllDayField != null) {
     values.removeOnChangeListener(listener, mAllDayField);
   }
 }
Beispiel #3
0
 @Override
 public void registerListener(
     ContentSet values, OnContentChangeListener listener, boolean initalNotification) {
   values.addOnChangeListener(listener, mTimestampField, initalNotification);
   if (mTzField != null) {
     values.addOnChangeListener(listener, mTzField, initalNotification);
   }
   if (mAllDayField != null) {
     values.addOnChangeListener(listener, mAllDayField, initalNotification);
   }
 }
Beispiel #4
0
  /**
   * Method to check if allday flag in values is set. If a <code>null</code> allday field name has
   * been passed to the constructor then return default {@link TimeFieldAdapter#mAllDayDefault}
   *
   * @param values The {@link ContentSet} to get the value of
   * @return <code>true</code> if allday flag is set, <code>false</code> otherwise
   */
  public boolean isAllDay(ContentSet values) {
    // cache mAlldayField locally
    String allDayField = mAllDayField;

    if (allDayField == null) {
      return mAllDayDefault;
    }

    Integer allDayInt = values.getAsInteger(allDayField);

    return (allDayInt != null && allDayInt != 0);
  }
Beispiel #5
0
  @Override
  public Time getDefault(ContentSet values) {
    // create a new Time for the given time zone, falling back to the default time zone if none is
    // given
    String timezone = mTzField == null ? Time.TIMEZONE_UTC : values.getAsString(mTzField);
    Time value = new Time(timezone == null ? TimeZone.getDefault().getID() : timezone);

    value.setToNow();

    Integer allDayInt = mAllDayField == null ? null : values.getAsInteger(mAllDayField);
    if ((allDayInt != null && allDayInt != 0) || (mAllDayField == null && mAllDayDefault)) {
      // make it an allday value
      value.set(value.monthDay, value.month, value.year);
    } else {
      value.second = 0;
      // round up to next quarter-hour
      value.minute = ((value.minute + 14) / 15) * 15;
      value.normalize(false);
    }

    return value;
  }
Beispiel #6
0
  @Override
  public void set(ContentSet values, Time value) {
    values.startBulkUpdate();
    try {
      if (value != null) {
        // just store all three parts separately
        values.put(mTimestampField, value.toMillis(false));

        if (mTzField != null) {
          values.put(mTzField, value.allDay ? null : value.timezone);
        }
        if (mAllDayField != null) {
          values.put(mAllDayField, value.allDay ? 1 : 0);
        }
      } else {
        // write timestamp only, other fields may still use allday and timezone
        values.put(mTimestampField, (Long) null);
      }
    } finally {
      values.finishBulkUpdate();
    }
  }