Search in sources :

Example 6 with Calendar

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

the class CalendarViewLegacyDelegate method setMaxDate.

@Override
public void setMaxDate(long maxDate) {
    mTempDate.setTimeInMillis(maxDate);
    if (isSameDate(mTempDate, mMaxDate)) {
        return;
    }
    mMaxDate.setTimeInMillis(maxDate);
    // reinitialize the adapter since its range depends on max date
    mAdapter.init();
    Calendar date = mAdapter.mSelectedDate;
    if (date.after(mMaxDate)) {
        setDate(mMaxDate.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 7 with Calendar

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

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

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

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)

Example 9 with Calendar

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

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

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

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)

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