List of usage examples for android.util MathUtils constrain
@UnsupportedAppUsage public static float constrain(float amount, float low, float high)
From source file:com.android.internal.widget.ViewPager.java
boolean setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity) { if (mAdapter == null || mAdapter.getCount() <= 0) { setScrollingCacheEnabled(false); return false; }//from ww w . j a v a 2 s .c o m item = MathUtils.constrain(item, 0, mAdapter.getCount() - 1); if (!always && mCurItem == item && mItems.size() != 0) { setScrollingCacheEnabled(false); return false; } final int pageLimit = mOffscreenPageLimit; if (item > (mCurItem + pageLimit) || item < (mCurItem - pageLimit)) { // We are doing a jump by more than one page. To avoid // glitches, we want to keep all current pages in the view // until the scroll ends. for (int i = 0; i < mItems.size(); i++) { mItems.get(i).scrolling = true; } } final boolean dispatchSelected = mCurItem != item; if (mFirstLayout) { // We don't have any idea how big we are yet and shouldn't have any pages either. // Just set things up and let the pending layout handle things. mCurItem = item; if (dispatchSelected && mOnPageChangeListener != null) { mOnPageChangeListener.onPageSelected(item); } if (dispatchSelected && mInternalPageChangeListener != null) { mInternalPageChangeListener.onPageSelected(item); } requestLayout(); } else { populate(item); scrollToItem(item, smoothScroll, velocity, dispatchSelected); } return true; }
From source file:com.android.internal.widget.ViewPager.java
private int getLeftEdgeForItem(int position) { final ItemInfo info = infoForPosition(position); if (info == null) { return 0; }/* w w w . j a v a 2 s.c o m*/ final int width = getPaddedWidth(); final int scaledOffset = (int) (width * MathUtils.constrain(info.offset, mFirstOffset, mLastOffset)); if (isLayoutRtl()) { final int itemWidth = (int) (width * info.widthFactor + 0.5f); return MAX_SCROLL_X - itemWidth - scaledOffset; } else { return scaledOffset; } }
From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java
/** * @return the alpha to be used to fade out the contents on Keyguard (status bar, bottom area) * during swiping up//from w w w . ja va 2 s . c o m */ private float getKeyguardContentsAlpha() { float alpha; if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) { // When on Keyguard, we hide the header as soon as the top card of the notification // stack scroller is close enough (collision distance) to the bottom of the header. alpha = getNotificationsTopY() / (mKeyguardStatusBar.getHeight() + mNotificationsHeaderCollideDistance); } else { // In SHADE_LOCKED, the top card is already really close to the header. Hide it as // soon as we start translating the stack. alpha = getNotificationsTopY() / mKeyguardStatusBar.getHeight(); } alpha = MathUtils.constrain(alpha, 0, 1); alpha = (float) Math.pow(alpha, 0.75); return alpha; }
From source file:com.android.internal.widget.ViewPager.java
/** * @param currentPage the position of the page with the first visible starting edge * @param pageOffset the fraction of the right-hand page that's visible * @param velocity the velocity of the touch event stream * @param deltaX the distance of the touch event stream * @return the position of the target page *//*from w w w . ja va 2s .co m*/ private int determineTargetPage(int currentPage, float pageOffset, int velocity, int deltaX) { int targetPage; if (Math.abs(deltaX) > mFlingDistance && Math.abs(velocity) > mMinimumVelocity) { targetPage = currentPage - (velocity < 0 ? mLeftIncr : 0); } else { final float truncator = currentPage >= mCurItem ? 0.4f : 0.6f; targetPage = (int) (currentPage - mLeftIncr * (pageOffset + truncator)); } if (mItems.size() > 0) { final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); // Only let the user target pages we have items for targetPage = MathUtils.constrain(targetPage, firstItem.position, lastItem.position); } return targetPage; }