Methods Summary |
---|
private java.util.Calendar | findAccessibilityFocus()Attempts to return the date that has accessibility focus.
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
if (child instanceof SimpleMonthView) {
final Calendar focus = ((SimpleMonthView) child).getAccessibilityFocus();
if (focus != null) {
return focus;
}
}
}
return null;
|
public long | getDate()
return mSelectedDay.getTimeInMillis();
|
private int | getDiffMonths(java.util.Calendar start, java.util.Calendar end)
final int diffYears = end.get(Calendar.YEAR) - start.get(Calendar.YEAR);
final int diffMonths = end.get(Calendar.MONTH) - start.get(Calendar.MONTH) + 12 * diffYears;
return diffMonths;
|
public int | getFirstDayOfWeek()
return mAdapter.getFirstDayOfWeek();
|
public long | getMaxDate()
return mMaxDate.getTimeInMillis();
|
public long | getMinDate()
return mMinDate.getTimeInMillis();
|
private java.lang.String | getMonthAndYearString(java.util.Calendar day)
final StringBuilder sbuf = new StringBuilder();
sbuf.append(day.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()));
sbuf.append(" ");
sbuf.append(mYearFormat.format(day.getTime()));
return sbuf.toString();
|
public int | getMostVisiblePosition()Gets the position of the view that is most prominently displayed within the list view.
final int firstPosition = getFirstVisiblePosition();
final int height = getHeight();
int maxDisplayedHeight = 0;
int mostVisibleIndex = 0;
int i=0;
int bottom = 0;
while (bottom < height) {
View child = getChildAt(i);
if (child == null) {
break;
}
bottom = child.getBottom();
int displayedHeight = Math.min(bottom, height) - Math.max(0, child.getTop());
if (displayedHeight > maxDisplayedHeight) {
mostVisibleIndex = i;
maxDisplayedHeight = displayedHeight;
}
i++;
}
return firstPosition + mostVisibleIndex;
|
private int | getPositionFromDay(long timeInMillis)
final int diffMonthMax = getDiffMonths(mMinDate, mMaxDate);
final int diffMonth = getDiffMonths(mMinDate, getTempCalendarForTime(timeInMillis));
return MathUtils.constrain(diffMonth, 0, diffMonthMax);
|
private java.util.Calendar | getTempCalendarForTime(long timeInMillis)
if (mTempCalendar == null) {
mTempCalendar = Calendar.getInstance();
}
mTempCalendar.setTimeInMillis(timeInMillis);
return mTempCalendar;
|
private boolean | goTo(long day, boolean animate, boolean setSelected, boolean forceScroll)This moves to the specified time in the view. If the time is not already
in range it will move the list so that the first of the month containing
the time is at the top of the view. If the new time is already in view
the list will not be scrolled unless forceScroll is true. This time may
optionally be highlighted as selected as well.
// Set the selected day
if (setSelected) {
mSelectedDay.setTimeInMillis(day);
}
mTempDay.setTimeInMillis(day);
final int position = getPositionFromDay(day);
View child;
int i = 0;
int top = 0;
// Find a child that's completely in the view
do {
child = getChildAt(i++);
if (child == null) {
break;
}
top = child.getTop();
} while (top < 0);
// Compute the first and last position visible
int selectedPosition;
if (child != null) {
selectedPosition = getPositionForView(child);
} else {
selectedPosition = 0;
}
if (setSelected) {
mAdapter.setSelectedDay(mSelectedDay);
}
// Check if the selected day is now outside of our visible range
// and if so scroll to the month that contains it
if (position != selectedPosition || forceScroll) {
setMonthDisplayed(mTempDay);
mPreviousScrollState = OnScrollListener.SCROLL_STATE_FLING;
if (animate) {
smoothScrollToPositionFromTop(
position, LIST_TOP_OFFSET, GOTO_SCROLL_DURATION);
return true;
} else {
postSetSelection(position);
}
} else if (setSelected) {
setMonthDisplayed(mSelectedDay);
}
return false;
|
protected void | layoutChildren()
final Calendar focusedDay = findAccessibilityFocus();
super.layoutChildren();
if (mPerformingScroll) {
mPerformingScroll = false;
} else {
restoreAccessibilityFocus(focusedDay);
}
|
protected void | onConfigurationChanged(android.content.res.Configuration newConfig)
mYearFormat = new SimpleDateFormat("yyyy", Locale.getDefault());
|
public void | onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
super.onInitializeAccessibilityEvent(event);
event.setItemCount(-1);
|
public void | onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)Necessary for accessibility, to ensure we support "scrolling" forward and backward
in the month list.
super.onInitializeAccessibilityNodeInfo(info);
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD);
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD);
|
public void | onRangeChanged()Handles changes to date range.
mAdapter.setRange(mMinDate, mMaxDate);
// Changing the min/max date changes the selection position since we
// don't really have stable IDs. Jumps immediately to the new position.
goTo(mSelectedDay.getTimeInMillis(), false, false, true);
|
public void | onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)Updates the title and selected month if the view has moved to a new
month.
SimpleMonthView child = (SimpleMonthView) view.getChildAt(0);
if (child == null) {
return;
}
mPreviousScrollState = mCurrentScrollState;
|
public void | onScrollStateChanged(AbsListView view, int scrollState)
// use a post to prevent re-entering onScrollStateChanged before it
// exits
mScrollStateChangedRunnable.doScrollStateChange(view, scrollState);
|
public boolean | performAccessibilityAction(int action, android.os.Bundle arguments)When scroll forward/backward events are received, announce the newly scrolled-to month.
if (action != AccessibilityNodeInfo.ACTION_SCROLL_FORWARD &&
action != AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
return super.performAccessibilityAction(action, arguments);
}
// Figure out what month is showing.
final int firstVisiblePosition = getFirstVisiblePosition();
final int month = firstVisiblePosition % 12;
final int year = firstVisiblePosition / 12 + mMinDate.get(Calendar.YEAR);
final Calendar day = Calendar.getInstance();
day.set(year, month, 1);
// Scroll either forward or backward one month.
if (action == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
day.add(Calendar.MONTH, 1);
if (day.get(Calendar.MONTH) == 12) {
day.set(Calendar.MONTH, 0);
day.add(Calendar.YEAR, 1);
}
} else if (action == AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
View firstVisibleView = getChildAt(0);
// If the view is fully visible, jump one month back. Otherwise, we'll just jump
// to the first day of first visible month.
if (firstVisibleView != null && firstVisibleView.getTop() >= -1) {
// There's an off-by-one somewhere, so the top of the first visible item will
// actually be -1 when it's at the exact top.
day.add(Calendar.MONTH, -1);
if (day.get(Calendar.MONTH) == -1) {
day.set(Calendar.MONTH, 11);
day.add(Calendar.YEAR, -1);
}
}
}
// Go to that month.
announceForAccessibility(getMonthAndYearString(day));
goTo(day.getTimeInMillis(), true, false, true);
mPerformingScroll = true;
return true;
|
public void | postSetSelection(int position)
clearFocus();
post(new Runnable() {
@Override
public void run() {
setSelection(position);
}
});
onScrollStateChanged(this, OnScrollListener.SCROLL_STATE_IDLE);
|
private boolean | restoreAccessibilityFocus(java.util.Calendar day)Attempts to restore accessibility focus to a given date. No-op if
{@code day} is {@code null}.
if (day == null) {
return false;
}
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
if (child instanceof SimpleMonthView) {
if (((SimpleMonthView) child).restoreAccessibilityFocus(day)) {
return true;
}
}
}
return false;
|
void | setCalendarTextAppearance(int resId)
mAdapter.setCalendarTextAppearance(resId);
|
void | setCalendarTextColor(android.content.res.ColorStateList colors)
mAdapter.setCalendarTextColor(colors);
|
public void | setDate(long timeInMillis)Sets the currently selected date to the specified timestamp. Jumps
immediately to the new date. To animate to the new date, use
{@link #setDate(long, boolean, boolean)}.
setDate(timeInMillis, false, true);
|
public void | setDate(long timeInMillis, boolean animate, boolean forceScroll)
goTo(timeInMillis, animate, true, forceScroll);
|
public void | setFirstDayOfWeek(int firstDayOfWeek)
mAdapter.setFirstDayOfWeek(firstDayOfWeek);
|
public void | setMaxDate(long timeInMillis)
mMaxDate.setTimeInMillis(timeInMillis);
onRangeChanged();
|
public void | setMinDate(long timeInMillis)
mMinDate.setTimeInMillis(timeInMillis);
onRangeChanged();
|
protected void | setMonthDisplayed(java.util.Calendar date)Sets the month displayed at the top of this view based on time. Override
to add custom events when the title is changed.
if (mCurrentMonthDisplayed != date.get(Calendar.MONTH)) {
mCurrentMonthDisplayed = date.get(Calendar.MONTH);
invalidateViews();
}
|
public void | setOnDaySelectedListener(android.widget.DayPickerView$OnDaySelectedListener listener)Sets the listener to call when the user selects a day.
mOnDaySelectedListener = listener;
|
private void | setUpListView()
// Transparent background on scroll
setCacheColorHint(0);
// No dividers
setDivider(null);
// Items are clickable
setItemsCanFocus(true);
// The thumb gets in the way, so disable it
setFastScrollEnabled(false);
setVerticalScrollBarEnabled(false);
setOnScrollListener(this);
setFadingEdgeLength(0);
// Make the scrolling behavior nicer
setFriction(ViewConfiguration.getScrollFriction());
|