@Override public void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) { if (!checkLayoutParams(params)) { params = generateLayoutParams(params); } final LayoutParams lp = (LayoutParams) params; if (inLayout) { lp.needsMeasure = true; addViewInLayout(child, index, params); } else { super.addView(child, index, params); } }
private void scrollToItem(int item, boolean smoothScroll, int velocity) { final ItemInfo curInfo = infoForPosition(item); int destX = 0; if (curInfo != null) { destX = (int) (getClientWidth() * Math.max(firstOffset, Math.min(curInfo.offset, lastOffset))); } if (smoothScroll) { smoothScrollTo(destX, 0, velocity); } else { completeScroll(false); scrollTo(destX, 0); pageScrolled(destX); } }
@Override public void onInvalidated() { dataSetChanged(); } }
if (currentItem != newCurrentItem) { focusDirection = currentItem < newCurrentItem ? View.FOCUS_RIGHT : View.FOCUS_LEFT; oldCurInfo = infoForPosition(currentItem); currentItem = newCurrentItem; sortChildDrawingOrder(); return; sortChildDrawingOrder(); return; if (getWindowToken() == null) { return; curItem = addNewItem(currentItem, curIndex); int itemIndex = curIndex - 1; ItemInfo ii = itemIndex >= 0 ? items.get(itemIndex) : null; final int clientWidth = getClientWidth(); final float leftWidthNeeded = clientWidth <= 0 ? 0 : 2.f - curItem.widthFactor + (float) getPaddingLeft() / (float) clientWidth; for (int pos = currentItem - 1; pos >= 0; pos--) { if (extraWidthLeft >= leftWidthNeeded && pos < startPos) { ii = itemIndex >= 0 ? items.get(itemIndex) : null; } else { ii = addNewItem(pos, itemIndex + 1); extraWidthLeft += ii.widthFactor; curIndex++;
scroller.abortAnimation(); populatePending = false; populate(); : initialMotionX - touchSlop; lastMotionY = y; setScrollState(SCROLL_STATE_DRAGGING); requestParentDisallowInterceptTouchEvent(true); performDrag(x); final int width = getClientWidth(); final int scrollX = getScrollX(); final ItemInfo ii = infoForCurrentScrollPosition(); final int currentPage = ii.position; final float pageOffset = ((float) scrollX / width) - ii.offset; final float x = MotionEventCompat.getX(ev, activePointerIndex); final int totalDelta = (int) (x - initialMotionX); final int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); activePointerId = INVALID_POINTER; endDrag(); break; scrollToItem(currentItem, true, 0); activePointerId = INVALID_POINTER;
if (getChildCount() == 0) { final int sx = getScrollX(); final int sy = getScrollY(); final int dx = x - sx; final int dy = y - sy; if (dx == 0 && dy == 0) { completeScroll(false); populate(); setScrollState(SCROLL_STATE_IDLE); return; setScrollState(SCROLL_STATE_SETTLING); final int width = getClientWidth(); final int halfWidth = width / 2; final float distanceRatio = Math.min(1f, 1.0f * Math.abs(dx) / width); final float distance = halfWidth + halfWidth * distanceInfluenceForSnapDuration(distanceRatio);
private void recomputeScrollPosition(int width, int oldWidth, int margin, int oldMargin) { if (oldWidth > 0 && !items.isEmpty()) { final int widthWithMargin = width - getPaddingLeft() - getPaddingRight() + margin; final int oldWidthWithMargin = oldWidth - getPaddingLeft() - getPaddingRight() + oldMargin; final int xpos = getScrollX(); final float pageOffset = (float) xpos / oldWidthWithMargin; final int newOffsetPixels = (int) (pageOffset * widthWithMargin); scrollTo(newOffsetPixels, getScrollY()); if (!scroller.isFinished()) { // We now return to your regularly scheduled scroll, already in progress. final int newDuration = scroller.getDuration() - scroller.timePassed(); ItemInfo targetInfo = infoForPosition(currentItem); if (targetInfo != null) { scroller.startScroll(newOffsetPixels, 0, (int) (targetInfo.offset * width), 0, newDuration); } } } else { final ItemInfo ii = infoForPosition(currentItem); final float scrollOffset = ii != null ? Math.min(ii.offset, lastOffset) : 0; final int scrollPos = (int) (scrollOffset * (width - getPaddingLeft() - getPaddingRight())); if (scrollPos != getScrollX()) { completeScroll(false); scrollTo(scrollPos, getScrollY()); } } }
@Override public void computeScroll() { if (!scroller.isFinished() && scroller.computeScrollOffset()) { int oldX = getScrollX(); int oldY = getScrollY(); int x = scroller.getCurrX(); int y = scroller.getCurrY(); if (oldX != x || oldY != y) { scrollTo(x, y); if (!pageScrolled(x)) { scroller.abortAnimation(); scrollTo(0, y); } } // Keep on drawing until the animation has finished. ViewCompat.postInvalidateOnAnimation(this); return; } // Done with scroll, clean up state. completeScroll(true); }
/** * Set scroll state. Will enable hardware layers in children if there is motion. * * @param newState new state */ private void setScrollState(int newState) { if (scrollState == newState) { return; } scrollState = newState; if (onCardChangeListener != null) { onCardChangeListener.onCardScrollStateChanged(newState); } enableLayers(newState != SCROLL_STATE_IDLE); }
@Override public void onChanged() { dataSetChanged(); }