コード例 #1
0
    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();
    }
コード例 #2
0
    /** 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);
    }
コード例 #3
0
ファイル: SqlHandler.java プロジェクト: mbeloded/oidarSample
  /** 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();
      }
    }
  }
コード例 #4
0
  // Do a "snap to start of month" fling
  private void doFling(float velocityY) {

    // Stop the list-view movement and take over
    MotionEvent cancelEvent =
        MotionEvent.obtain(
            mDownActionTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0, 0, 0);
    onTouchEvent(cancelEvent);

    // Below the threshold, fling one month. Above the threshold , fling
    // according to the speed of the fling.
    int monthsToJump;
    if (Math.abs(velocityY) < MULTIPLE_MONTH_VELOCITY_THRESHOLD) {
      if (velocityY < 0) {
        monthsToJump = 1;
      } else {
        // value here is zero and not -1 since by the time the fling is
        // detected the list moved back one month.
        monthsToJump = 0;
      }
    } else {
      if (velocityY < 0) {
        monthsToJump =
            1 - (int) ((velocityY + MULTIPLE_MONTH_VELOCITY_THRESHOLD) / FLING_VELOCITY_DIVIDER);
      } else {
        monthsToJump =
            -(int) ((velocityY - MULTIPLE_MONTH_VELOCITY_THRESHOLD) / FLING_VELOCITY_DIVIDER);
      }
    }

    // Get the day at the top right corner
    int day = getUpperRightJulianDay();
    // Get the day of the first day of the next/previous month
    // (according to scroll direction)
    mTempTime.setJulianDay(day);
    mTempTime.monthDay = 1;
    mTempTime.month += monthsToJump;
    long timeInMillis = mTempTime.normalize(false);
    // Since each view is 7 days, round the target day up to make sure the
    // scroll will be  at least one view.
    int scrollToDay =
        Time.getJulianDay(timeInMillis, mTempTime.gmtoff) + ((monthsToJump > 0) ? 6 : 0);

    // Since all views have the same height, scroll by pixels instead of
    // "to position".
    // Compensate for the top view offset from the top.
    View firstView = getChildAt(0);
    int firstViewHeight = firstView.getHeight();
    // Get visible part length
    firstView.getLocalVisibleRect(mFirstViewRect);
    int topViewVisiblePart = mFirstViewRect.bottom - mFirstViewRect.top;
    int viewsToFling = (scrollToDay - day) / 7 - ((monthsToJump <= 0) ? 1 : 0);
    int offset =
        (viewsToFling > 0)
            ? -(firstViewHeight - topViewVisiblePart + SimpleDayPickerFragment.LIST_TOP_OFFSET)
            : (topViewVisiblePart - SimpleDayPickerFragment.LIST_TOP_OFFSET);
    // Fling
    smoothScrollBy(viewsToFling * firstViewHeight + offset, FLING_TIME);
  }
コード例 #5
0
 public static String prettyTimestamp(Timestamp t, boolean isChat) {
   // Set time in UTC time
   Time time = new Time("UTC");
   Calendar cal = Calendar.getInstance();
   cal.setTime(t);
   time.set(
       cal.get(Calendar.SECOND),
       cal.get(Calendar.MINUTE),
       cal.get(Calendar.HOUR_OF_DAY),
       cal.get(Calendar.DAY_OF_MONTH),
       cal.get(Calendar.MONTH),
       cal.get(Calendar.YEAR));
   // Switch to device timezone
   time.switchTimezone(Time.getCurrentTimezone());
   Time startOfDay = new Time(Time.getCurrentTimezone());
   startOfDay.setToNow();
   startOfDay.hour = 0;
   startOfDay.minute = 0;
   startOfDay.second = 0;
   Time startOfYear = new Time(Time.getCurrentTimezone());
   startOfYear.setToNow();
   startOfYear.hour = 0;
   startOfYear.minute = 0;
   startOfYear.second = 0;
   startOfYear.monthDay = 0;
   startOfYear.month = 0;
   Time startOfTime = new Time(Time.getCurrentTimezone());
   startOfTime.set(0);
   if (t.equals(new Timestamp(0, 0, 0, 0, 0, 0, 0))) {
     return "";
   } else if (isChat) {
     if (time.after(startOfDay)) {
       return time.format("%H:%M");
     } else if (time.after(startOfYear)) {
       return time.format("%b %d, %H:%M");
     } else {
       return time.format("%b %d %Y, %H:%M");
     }
   } else {
     if (time.after(startOfDay)) {
       return time.format("%H:%M");
     } else if (time.after(startOfYear)) {
       return time.format("%b %d");
     } else {
       return time.format("%b %d %Y");
     }
   }
 }
コード例 #6
0
ファイル: PLN.java プロジェクト: Bresiu/rozkladpkp-android
  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);
  }
コード例 #7
0
  /** 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);
  }