public void postSetSelection(final int position) { clearFocus(); post(new Runnable() { @Override public void run() { setSelection(position); } }); onScrollStateChanged(this, OnScrollListener.SCROLL_STATE_IDLE); }
/** * Creates a new adapter if necessary and sets up its parameters. Override * this method to provide a custom adapter. */ protected void refreshAdapter() { if (mAdapter == null) { mAdapter = createMonthAdapter(getContext(), mController); } else { mAdapter.setSelectedDay(mSelectedDay); } // refresh the view with the new parameters setAdapter(mAdapter); }
@Override protected void layoutChildren() { final CalendarDay focusedDay = findAccessibilityFocus(); super.layoutChildren(); if (mPerformingScroll) { mPerformingScroll = false; } else { restoreAccessibilityFocus(focusedDay); } }
mPreviousScrollState = mNewState; int i = 0; View child = getChildAt(i); while (child != null && child.getBottom() <= 0) { child = getChildAt(++i); int firstPosition = getFirstVisiblePosition(); int lastPosition = getLastVisiblePosition(); boolean scroll = firstPosition != 0 && lastPosition != getCount() - 1; final int top = child.getTop(); final int bottom = child.getBottom(); final int midpoint = getHeight() / 2; if (scroll && top < LIST_TOP_OFFSET) { if (bottom > midpoint) { smoothScrollBy(top, GOTO_SCROLL_DURATION); } else { smoothScrollBy(bottom, GOTO_SCROLL_DURATION);
child = getChildAt(i++); if (child == null) { break; selectedPosition = getPositionForView(child); } else { selectedPosition = 0; setMonthDisplayed(mTempDay); mPreviousScrollState = OnScrollListener.SCROLL_STATE_FLING; if (animate) { smoothScrollToPositionFromTop( position, LIST_TOP_OFFSET, GOTO_SCROLL_DURATION); return true; } else { postSetSelection(position); setMonthDisplayed(mSelectedDay);
int firstVisiblePosition = getFirstVisiblePosition(); int month = firstVisiblePosition % 12; int year = firstVisiblePosition / 12 + mController.getMinYear(); View firstVisibleView = getChildAt(0); Utils.tryAccessibilityAnnounce(this, getMonthAndYearString(day)); goTo(day, true, false, true); mPerformingScroll = true; return true;
/** * Gets the position of the view that is most prominently displayed within the list view. */ public int getMostVisiblePosition() { 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; }
/** * Attempts to restore accessibility focus to a given date. No-op if * {@code day} is {@code null}. * * @param day The date that should receive accessibility focus * @return {@code true} if focus was restored */ private boolean restoreAccessibilityFocus(CalendarDay day) { if (day == null) { return false; } final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child instanceof MonthView) { if (((MonthView) child).restoreAccessibilityFocus(day)) { return true; } } } return false; }
mPreviousScrollState = mNewState; int i = 0; View child = getChildAt(i); while (child != null && child.getBottom() <= 0) { child = getChildAt(++i); int firstPosition = getFirstVisiblePosition(); int lastPosition = getLastVisiblePosition(); boolean scroll = firstPosition != 0 && lastPosition != getCount() - 1; final int top = child.getTop(); final int bottom = child.getBottom(); final int midpoint = getHeight() / 2; if (scroll && top < LIST_TOP_OFFSET) { if (bottom > midpoint) { smoothScrollBy(top, GOTO_SCROLL_DURATION); } else { smoothScrollBy(bottom, GOTO_SCROLL_DURATION);
child = getChildAt(i++); if (child == null) { break; selectedPosition = getPositionForView(child); } else { selectedPosition = 0; setMonthDisplayed(mTempDay); mPreviousScrollState = OnScrollListener.SCROLL_STATE_FLING; if (animate) { smoothScrollToPositionFromTop( position, LIST_TOP_OFFSET, GOTO_SCROLL_DURATION); return true; } else { postSetSelection(position); setMonthDisplayed(mSelectedDay);
int firstVisiblePosition = getFirstVisiblePosition(); int month = firstVisiblePosition % 12; int year = firstVisiblePosition / 12 + mController.getMinYear(); View firstVisibleView = getChildAt(0); Utils.tryAccessibilityAnnounce(this, getMonthAndYearString(day)); goTo(day, true, false, true); mPerformingScroll = true; return true;
/** * Gets the position of the view that is most prominently displayed within the list view. */ public int getMostVisiblePosition() { 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; }
/** * Attempts to return the date that has accessibility focus. * * @return The date that has accessibility focus, or {@code null} if no date * has focus. */ private CalendarDay findAccessibilityFocus() { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child instanceof MonthView) { final CalendarDay focus = ((MonthView) child).getAccessibilityFocus(); if (focus != null) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { // Clear focus to avoid ListView bug in Jelly Bean MR1. ((MonthView) child).clearAccessibilityFocus(); } return focus; } } } return null; }
/** * Creates a new adapter if necessary and sets up its parameters. Override * this method to provide a custom adapter. */ protected void refreshAdapter() { if (mAdapter == null) { mAdapter = createMonthAdapter(getContext(), mController); } else { mAdapter.setSelectedDay(mSelectedDay); } // refresh the view with the new parameters setAdapter(mAdapter); }
public void postSetSelection(final int position) { clearFocus(); post(new Runnable() { @Override public void run() { setSelection(position); } }); onScrollStateChanged(this, OnScrollListener.SCROLL_STATE_IDLE); }
/** * Attempts to restore accessibility focus to a given date. No-op if * {@code day} is {@code null}. * * @param day The date that should receive accessibility focus * @return {@code true} if focus was restored */ private boolean restoreAccessibilityFocus(CalendarDay day) { if (day == null) { return false; } final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child instanceof MonthView) { if (((MonthView) child).restoreAccessibilityFocus(day)) { return true; } } } return false; }
@Override protected void layoutChildren() { final CalendarDay focusedDay = findAccessibilityFocus(); super.layoutChildren(); if (mPerformingScroll) { mPerformingScroll = false; } else { restoreAccessibilityFocus(focusedDay); } }
/** * Attempts to return the date that has accessibility focus. * * @return The date that has accessibility focus, or {@code null} if no date * has focus. */ private CalendarDay findAccessibilityFocus() { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child instanceof MonthView) { final CalendarDay focus = ((MonthView) child).getAccessibilityFocus(); if (focus != null) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { // Clear focus to avoid ListView bug in Jelly Bean MR1. ((MonthView) child).clearAccessibilityFocus(); } return focus; } } } return null; }