Search in sources :

Example 1 with Calendar

use of android.icu.util.Calendar in project android_frameworks_base by ResurrectionRemix.

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)

Example 2 with Calendar

use of android.icu.util.Calendar in project android_frameworks_base by ResurrectionRemix.

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 3 with Calendar

use of android.icu.util.Calendar in project android_frameworks_base by ResurrectionRemix.

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 4 with Calendar

use of android.icu.util.Calendar in project android_frameworks_base by ResurrectionRemix.

the class CalendarViewLegacyDelegate method setUpAdapter.

/**
     * Creates a new adapter if necessary and sets up its parameters.
     */
private void setUpAdapter() {
    if (mAdapter == null) {
        mAdapter = new WeeksAdapter(mContext);
        mAdapter.registerDataSetObserver(new DataSetObserver() {

            @Override
            public void onChanged() {
                if (mOnDateChangeListener != null) {
                    Calendar selectedDay = mAdapter.getSelectedDay();
                    mOnDateChangeListener.onSelectedDayChange(mDelegator, selectedDay.get(Calendar.YEAR), selectedDay.get(Calendar.MONTH), selectedDay.get(Calendar.DAY_OF_MONTH));
                }
            }
        });
        mListView.setAdapter(mAdapter);
    }
    // refresh the view with the new parameters
    mAdapter.notifyDataSetChanged();
}
Also used : Calendar(android.icu.util.Calendar) DataSetObserver(android.database.DataSetObserver)

Example 5 with Calendar

use of android.icu.util.Calendar in project android_frameworks_base by ResurrectionRemix.

the class CalendarViewLegacyDelegate method getCalendarForLocale.

/**
     * Gets a calendar for locale bootstrapped with the value of a given calendar.
     *
     * @param oldCalendar The old calendar.
     * @param locale The locale.
     */
private static Calendar getCalendarForLocale(Calendar oldCalendar, Locale locale) {
    if (oldCalendar == null) {
        return Calendar.getInstance(locale);
    } else {
        final long currentTimeMillis = oldCalendar.getTimeInMillis();
        Calendar newCalendar = Calendar.getInstance(locale);
        newCalendar.setTimeInMillis(currentTimeMillis);
        return newCalendar;
    }
}
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