Search in sources :

Example 16 with Calendar

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

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

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

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)

Example 18 with Calendar

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

the class CalendarViewLegacyDelegate method onScroll.

/**
     * Updates the title and selected month if the <code>view</code> has moved to a new
     * month.
     */
private void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    WeekView child = (WeekView) view.getChildAt(0);
    if (child == null) {
        return;
    }
    // Figure out where we are
    long currScroll = view.getFirstVisiblePosition() * child.getHeight() - child.getBottom();
    // If we have moved since our last call update the direction
    if (currScroll < mPreviousScrollPosition) {
        mIsScrollingUp = true;
    } else if (currScroll > mPreviousScrollPosition) {
        mIsScrollingUp = false;
    } else {
        return;
    }
    // Use some hysteresis for checking which month to highlight. This
    // causes the month to transition when two full weeks of a month are
    // visible when scrolling up, and when the first day in a month reaches
    // the top of the screen when scrolling down.
    int offset = child.getBottom() < mWeekMinVisibleHeight ? 1 : 0;
    if (mIsScrollingUp) {
        child = (WeekView) view.getChildAt(SCROLL_HYST_WEEKS + offset);
    } else if (offset != 0) {
        child = (WeekView) view.getChildAt(offset);
    }
    if (child != null) {
        // Find out which month we're moving into
        int month;
        if (mIsScrollingUp) {
            month = child.getMonthOfFirstWeekDay();
        } else {
            month = child.getMonthOfLastWeekDay();
        }
        // And how it relates to our current highlighted month
        int monthDiff;
        if (mCurrentMonthDisplayed == 11 && month == 0) {
            monthDiff = 1;
        } else if (mCurrentMonthDisplayed == 0 && month == 11) {
            monthDiff = -1;
        } else {
            monthDiff = month - mCurrentMonthDisplayed;
        }
        // selected month
        if ((!mIsScrollingUp && monthDiff > 0) || (mIsScrollingUp && monthDiff < 0)) {
            Calendar firstDay = child.getFirstDay();
            if (mIsScrollingUp) {
                firstDay.add(Calendar.DAY_OF_MONTH, -DAYS_PER_WEEK);
            } else {
                firstDay.add(Calendar.DAY_OF_MONTH, DAYS_PER_WEEK);
            }
            setMonthDisplayed(firstDay);
        }
    }
    mPreviousScrollPosition = currScroll;
    mPreviousScrollState = mCurrentScrollState;
}
Also used : Calendar(android.icu.util.Calendar) Paint(android.graphics.Paint)

Example 19 with Calendar

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

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

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

the class DatePickerSpinnerDelegate method getMinDate.

@Override
public Calendar getMinDate() {
    final Calendar minDate = Calendar.getInstance();
    minDate.setTimeInMillis(mCalendarView.getMinDate());
    return minDate;
}
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