Search in sources :

Example 21 with Calendar

use of android.icu.util.Calendar in project platform_frameworks_base by android.

the class DatePickerSpinnerDelegate method getMaxDate.

@Override
public Calendar getMaxDate() {
    final Calendar maxDate = Calendar.getInstance();
    maxDate.setTimeInMillis(mCalendarView.getMaxDate());
    return maxDate;
}
Also used : Calendar(android.icu.util.Calendar)

Example 22 with Calendar

use of android.icu.util.Calendar in project platform_frameworks_base by android.

the class DateTimeView method computeNextMidnight.

/**
     * @param timeZone the timezone we are in
     * @return the timepoint in millis at UTC at midnight in the current timezone
     */
private long computeNextMidnight(TimeZone timeZone) {
    Calendar c = Calendar.getInstance();
    c.setTimeZone(libcore.icu.DateUtilsBridge.icuTimeZone(timeZone));
    c.add(Calendar.DAY_OF_MONTH, 1);
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis();
}
Also used : Calendar(android.icu.util.Calendar)

Example 23 with Calendar

use of android.icu.util.Calendar in project platform_frameworks_base by android.

the class CalendarViewLegacyDelegate method setMinDate.

@Override
public void setMinDate(long minDate) {
    mTempDate.setTimeInMillis(minDate);
    if (isSameDate(mTempDate, mMinDate)) {
        return;
    }
    mMinDate.setTimeInMillis(minDate);
    // make sure the current date is not earlier than
    // the new min date since the latter is used for
    // calculating the indices in the adapter thus
    // avoiding out of bounds error
    Calendar date = mAdapter.mSelectedDate;
    if (date.before(mMinDate)) {
        mAdapter.setSelectedDay(mMinDate);
    }
    // reinitialize the adapter since its range depends on min date
    mAdapter.init();
    if (date.before(mMinDate)) {
        setDate(mTempDate.getTimeInMillis());
    } else {
        // we go to the current date to force the ListView to query its
        // adapter for the shown views since we have changed the adapter
        // range and the base from which the later calculates item indices
        // note that calling setDate will not work since the date is the same
        goTo(date, false, true, false);
    }
}
Also used : Calendar(android.icu.util.Calendar)

Example 24 with Calendar

use of android.icu.util.Calendar in project platform_frameworks_base by android.

the class TwilightService method calculateTwilightState.

/**
     * Calculates the twilight state for a specific location and time.
     *
     * @param location the location to use
     * @param timeMillis the reference time to use
     * @return the calculated {@link TwilightState}, or {@code null} if location is {@code null}
     */
private static TwilightState calculateTwilightState(Location location, long timeMillis) {
    if (location == null) {
        return null;
    }
    final CalendarAstronomer ca = new CalendarAstronomer(location.getLongitude(), location.getLatitude());
    final Calendar noon = Calendar.getInstance();
    noon.setTimeInMillis(timeMillis);
    noon.set(Calendar.HOUR_OF_DAY, 12);
    noon.set(Calendar.MINUTE, 0);
    noon.set(Calendar.SECOND, 0);
    noon.set(Calendar.MILLISECOND, 0);
    ca.setTime(noon.getTimeInMillis());
    long sunriseTimeMillis = ca.getSunRiseSet(true);
    long sunsetTimeMillis = ca.getSunRiseSet(false);
    if (sunsetTimeMillis < timeMillis) {
        noon.add(Calendar.DATE, 1);
        ca.setTime(noon.getTimeInMillis());
        sunriseTimeMillis = ca.getSunRiseSet(true);
    } else if (sunriseTimeMillis > timeMillis) {
        noon.add(Calendar.DATE, -1);
        ca.setTime(noon.getTimeInMillis());
        sunsetTimeMillis = ca.getSunRiseSet(false);
    }
    return new TwilightState(sunriseTimeMillis, sunsetTimeMillis);
}
Also used : Calendar(android.icu.util.Calendar) CalendarAstronomer(android.icu.impl.CalendarAstronomer)

Example 25 with Calendar

use of android.icu.util.Calendar in project platform_frameworks_base by android.

the class SimpleMonthView method onDayClicked.

/**
     * Called when the user clicks on a day. Handles callbacks to the
     * {@link OnDayClickListener} if one is set.
     *
     * @param day the day that was clicked
     */
private boolean onDayClicked(int day) {
    if (!isValidDayOfMonth(day) || !isDayEnabled(day)) {
        return false;
    }
    if (mOnDayClickListener != null) {
        final Calendar date = Calendar.getInstance();
        date.set(mYear, mMonth, day);
        mOnDayClickListener.onDayClick(this, date);
    }
    // This is a no-op if accessibility is turned off.
    mTouchHelper.sendEventForVirtualView(day, AccessibilityEvent.TYPE_VIEW_CLICKED);
    return true;
}
Also used : Calendar(android.icu.util.Calendar)

Aggregations

Calendar (android.icu.util.Calendar)233 Test (org.junit.Test)155 GregorianCalendar (android.icu.util.GregorianCalendar)135 Date (java.util.Date)96 JapaneseCalendar (android.icu.util.JapaneseCalendar)72 SimpleDateFormat (android.icu.text.SimpleDateFormat)69 ULocale (android.icu.util.ULocale)60 BuddhistCalendar (android.icu.util.BuddhistCalendar)53 ChineseCalendar (android.icu.util.ChineseCalendar)52 IslamicCalendar (android.icu.util.IslamicCalendar)48 TimeZone (android.icu.util.TimeZone)41 DateFormat (android.icu.text.DateFormat)37 HebrewCalendar (android.icu.util.HebrewCalendar)32 FieldPosition (java.text.FieldPosition)29 SimpleTimeZone (android.icu.util.SimpleTimeZone)26 ParsePosition (java.text.ParsePosition)23 TaiwanCalendar (android.icu.util.TaiwanCalendar)22 ParseException (java.text.ParseException)21 ChineseDateFormat (android.icu.text.ChineseDateFormat)17 IOException (java.io.IOException)16