public void onDateSet(DatePicker view, int year, int month, int monthDay) {
      // Cache the member variables locally to avoid inner class overhead.
      Time startTime = mStartTime;
      Time dueTime = mDueTime;

      // Cache the start and due millis so that we limit the number
      // of calls to normalize() and toMillis(), which are fairly
      // expensive.
      long startMillis;
      long dueMillis;
      if (mView == mStartDateButton) {
        // The start date was changed.
        int yearDuration = dueTime.year - startTime.year;
        int monthDuration = dueTime.month - startTime.month;
        int monthDayDuration = dueTime.monthDay - startTime.monthDay;

        startTime.year = year;
        startTime.month = month;
        startTime.monthDay = monthDay;
        startMillis = startTime.normalize(true);
        mShowStart = true;

        // Also update the end date to keep the duration constant.
        dueTime.year = year + yearDuration;
        dueTime.month = month + monthDuration;
        dueTime.monthDay = monthDay + monthDayDuration;
        dueMillis = dueTime.normalize(true);
        mShowDue = true;
      } else {
        // The end date was changed.
        startMillis = startTime.toMillis(true);
        dueTime.year = year;
        dueTime.month = month;
        dueTime.monthDay = monthDay;
        dueMillis = dueTime.normalize(true);
        mShowDue = true;

        if (mShowStart) {
          // Do not allow an event to have an end time before the start time.
          if (dueTime.before(startTime)) {
            dueTime.set(startTime);
            dueMillis = startMillis;
          }
        } else {
          // if start time is not shown, default it to be the same as due time
          startTime.set(dueTime);
          mShowStart = true;
        }
      }

      // update all 4 buttons in case visibility has changed
      setDate(mStartDateButton, startMillis, mShowStart);
      setTime(mStartTimeButton, startMillis, mShowStart);
      setDate(mDueDateButton, dueMillis, mShowDue);
      setTime(mDueTimeButton, dueMillis, mShowDue);
      updateCalendarPanel();
    }
    /** Parses an SC timestamp and returns a currentTimeMillis()-style timestamp */
    long getSCTimestampMillis() {
      // TP-Service-Centre-Time-Stamp
      int year = IccUtils.gsmBcdByteToInt(mPdu[mCur++]);
      int month = IccUtils.gsmBcdByteToInt(mPdu[mCur++]);
      int day = IccUtils.gsmBcdByteToInt(mPdu[mCur++]);
      int hour = IccUtils.gsmBcdByteToInt(mPdu[mCur++]);
      int minute = IccUtils.gsmBcdByteToInt(mPdu[mCur++]);
      int second = IccUtils.gsmBcdByteToInt(mPdu[mCur++]);

      // For the timezone, the most significant bit of the
      // least significant nibble is the sign byte
      // (meaning the max range of this field is 79 quarter-hours,
      // which is more than enough)

      byte tzByte = mPdu[mCur++];

      // Mask out sign bit.
      int timezoneOffset = IccUtils.gsmBcdByteToInt((byte) (tzByte & (~0x08)));

      timezoneOffset = ((tzByte & 0x08) == 0) ? timezoneOffset : -timezoneOffset;

      Time time = new Time(Time.TIMEZONE_UTC);

      // It's 2006.  Should I really support years < 2000?
      time.year = year >= 90 ? year + 1900 : year + 2000;
      time.month = month - 1;
      time.monthDay = day;
      time.hour = hour;
      time.minute = minute;
      time.second = second;

      // Timezone offset is in quarter hours.
      return time.toMillis(true) - (timezoneOffset * 15 * 60 * 1000);
    }
Exemple #3
0
  /** Return the time the workout was completed for a given workout id. */
  private Time getTimeForWorkout(int workoutId) {
    Cursor cursor = null;
    try {
      cursor =
          mDatabase.query(
              DATABASE_TABLE_WENDLER_WORKOUT,
              new String[] {KEY_WORKOUT_YEAR, KEY_WORKOUT_MONTH, KEY_WORKOUT_DAY},
              KEY_WORKOUT_ID + "=?",
              new String[] {String.valueOf(workoutId)},
              null,
              null,
              null);

      Time time = new Time();
      time.setToNow();
      if (cursor != null && cursor.moveToFirst()) {
        time.year = Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_WORKOUT_YEAR)));
        time.month = Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_WORKOUT_MONTH)));
        time.monthDay = Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_WORKOUT_DAY)));
      }
      return time;
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
  }
Exemple #4
0
  private void setupDates() {
    sdate = new android.text.format.Time();
    sdate.year = 1979;
    sdate.month = 11;
    sdate.monthDay = 31;

    edate = new android.text.format.Time(sdate);
    today = new android.text.format.Time(sdate);

    sdate.monthDay += readShort(0x28);
    edate.monthDay += readShort(0x2a);
    today.monthDay += readShort(0x2c);

    sdate.normalize(false);
    edate.normalize(false);
    today.normalize(false);
  }
  /** Refresh month title text view when user swipe */
  protected void refreshMonthTitleTextView() {
    // Refresh title view
    firstMonthTime.year = year;
    firstMonthTime.month = month - 2;
    firstMonthTime.monthDay = 1;
    long millis = firstMonthTime.toMillis(true);

    // This is the method used by the platform Calendar app to get a
    // correctly localized month name for display on a wall calendar
    monthYearStringBuilder.setLength(0);
    String monthTitle =
        DateUtils.formatDateRange(
                getActivity(), monthYearFormatter, millis, millis, MONTH_YEAR_FLAG)
            .toString();

    monthTitleTextView.setText(monthTitle);
  }